use of com.trovebox.android.common.net.UploadMetaData in project mobile-android by photo.
the class TroveboxApiTest method testCreateTokenForPhoto.
public void testCreateTokenForPhoto() throws Exception {
File file = createTestFileForUpload();
boolean priv = true;
UploadMetaData settings = new UploadMetaData();
String title = "Android";
String description = "Nice picture of an android";
String tags = "test";
settings.setTitle(title);
settings.setDescription(description);
settings.setTags(tags);
settings.setPrivate(priv);
try {
String hash = SHA1Utils.computeSha1ForFile(file.getAbsolutePath());
PhotosResponse photos = mApi.getPhotos(hash);
assertTrue(photos.isSuccess());
boolean created = false;
Photo photo;
if (photos.getPhotos().size() > 0) {
photo = photos.getPhotos().get(0);
} else {
UploadResponse resp = mApi.uploadPhoto(file, settings, null);
assertTrue(resp.isSuccess());
assertNotNull(resp.getPhoto());
photo = resp.getPhoto();
created = true;
}
try {
assertNotNull(photo);
assertTrue(photo.getTags().size() >= 1);
// assertEquals("test", resp.getPhoto().getTags().get(0));
assertEquals(title, photo.getTitle());
assertEquals(description, photo.getDescription());
assertEquals(priv, photo.isPrivate());
TokenResponse tokenResponse = mApi.createTokenForPhoto(photo.getId());
assertEquals(tokenResponse.getCode(), 201);
Token token = tokenResponse.getToken();
assertNotNull(token);
assertEquals(token.getType(), "photo");
assertEquals(token.getData(), photo.getId());
assertNotNull(token.getId());
assertFalse(token.getId().isEmpty());
System.out.println(token.getDateExpires());
assertNotNull(token.getDateExpires());
} finally {
if (created) {
// remove uploaded photo
mApi.deletePhoto(photo.getId());
}
}
} catch (Exception e) {
e.printStackTrace();
fail("Exception should not happen: " + e.getClass().getSimpleName() + " - " + e.getMessage());
}
file.delete();
}
use of com.trovebox.android.common.net.UploadMetaData in project mobile-android by photo.
the class TroveboxApiTest method testPhotoUploadAndDetailsEdit.
public void testPhotoUploadAndDetailsEdit() throws Exception {
File file = createTestFileForUpload();
UploadMetaData settings = new UploadMetaData();
String title = "Android";
String description = "Nice picture of an android";
String tags = "test";
boolean priv = false;
settings.setTitle(title);
settings.setDescription(description);
settings.setTags(tags);
settings.setPrivate(priv);
try {
UploadResponse resp = mApi.uploadPhoto(file, settings, null);
assertTrue(resp.isSuccess());
assertNotNull(resp.getPhoto());
try {
Photo photo = resp.getPhoto();
assertNotNull(photo);
assertTrue(photo.getTags().size() >= 1);
// assertEquals("test", resp.getPhoto().getTags().get(0));
assertEquals(title, photo.getTitle());
assertEquals(description, photo.getDescription());
assertFalse(photo.isPrivate());
title = "Android (Edited)";
description = "Nice picture of an android (Edited)";
tags = "edited";
Collection<String> tagsCollection = new ArrayList<String>();
tagsCollection.add("edited");
priv = true;
PhotoResponse photoResp = mApi.updatePhotoDetails(photo.getId(), title, description, tagsCollection, Photo.PERMISSION_PRIVATE);
photo = photoResp.getPhoto();
assertTrue(photoResp.isSuccess());
assertNotNull(photo);
assertTrue(photo.getTags().size() == 1);
assertEquals(tags, photo.getTags().get(0));
assertEquals(title, photo.getTitle());
assertEquals(description, photo.getDescription());
assertTrue(photo.isPrivate() == priv);
} finally {
// remove uploaded photo
mApi.deletePhoto(resp.getPhoto().getId());
}
} catch (Exception e) {
fail("Exception should not happen: " + e.getClass().getSimpleName() + " - " + e.getMessage());
}
file.delete();
}
use of com.trovebox.android.common.net.UploadMetaData in project mobile-android by photo.
the class UploadMetaDataTest method testUploadMetaDataParcelable.
public void testUploadMetaDataParcelable() {
UploadMetaData data = getTestData();
testUploadMetaData(data);
Parcel parcel = Parcel.obtain();
data.writeToParcel(parcel, 0);
// done writing, now reset parcel for reading
parcel.setDataPosition(0);
// finish round trip
UploadMetaData createFromParcel = UploadMetaData.CREATOR.createFromParcel(parcel);
testUploadMetaData(createFromParcel);
}
use of com.trovebox.android.common.net.UploadMetaData in project mobile-android by photo.
the class NewPhotoObserver method onEvent.
@Override
public void onEvent(int event, String fileName) {
if (event == FileObserver.CREATE && !fileName.equals(".probe")) {
File file = new File(mPath + "/" + fileName);
CommonUtils.debug(TAG, "File created [" + file.getAbsolutePath() + "]");
// fix for the issue #309
String type = getMimeType(file);
if (type != null && type.toLowerCase().startsWith("image/")) {
TrackerUtils.trackBackgroundEvent("autoupload_observer", CommonUtils.format("Processed for Mime-Type: %1$s", type));
if (!Preferences.isAutoUploadActive(mContext) || !GuiUtils.checkLoggedIn(true) || Preferences.isLimitedAccountAccessType()) {
return;
}
if (checkLimits()) {
TrackerUtils.trackLimitEvent("auto_upload_limit_check", "success");
CommonUtils.debug(TAG, "Adding new autoupload to queue for file: " + fileName);
UploadsProviderAccessor uploads = new UploadsProviderAccessor(mContext);
UploadMetaData metaData = new UploadMetaData();
metaData.setTags(Preferences.getAutoUploadTag(mContext));
uploads.addPendingAutoUpload(Uri.fromFile(file), metaData);
mContext.startService(new Intent(mContext, UploaderService.class));
} else {
TrackerUtils.trackLimitEvent("autoupload_observer", "fail");
showAutouploadIgnoredNotification(file);
}
} else {
TrackerUtils.trackBackgroundEvent("autoupload_observer", CommonUtils.format("Skipped for Mime-Type: %1$s", type == null ? "null" : type));
}
}
}
Aggregations