use of com.trovebox.android.common.net.TokenResponse in project mobile-android by photo.
the class TokenUtils method getPhotoShareTokenResponse.
/**
* Performs api request to retrieve share token for the photo
*
* @param photo
* @return
* @throws ClientProtocolException
* @throws IOException
* @throws JSONException
*/
public static TokenResponse getPhotoShareTokenResponse(Photo photo) throws ClientProtocolException, IOException, JSONException {
TrackerUtils.trackBackgroundEvent("getPhotoShareToken", TAG);
long start = System.currentTimeMillis();
TokenResponse response = CommonConfigurationUtils.getApi().createTokenForPhoto(photo.getId());
TrackerUtils.trackDataLoadTiming(System.currentTimeMillis() - start, "getPhotoShareToken", TAG);
return response;
}
use of com.trovebox.android.common.net.TokenResponse in project mobile-android by photo.
the class PhotoUtils method validateShareTokenExistsAndReturn.
/**
* Validate whether the photo has retrieved share token. If not then
* retrieve the share token
*
* @param photo
* @return
* @throws ClientProtocolException
* @throws IOException
* @throws JSONException
*/
public static Photo validateShareTokenExistsAndReturn(Photo photo) throws ClientProtocolException, IOException, JSONException {
if (photo.getShareToken() != null) {
CommonUtils.debug(TAG, "Share token exists");
} else {
CommonUtils.debug(TAG, "Share token doesn't exist. Running size retrieval method.");
TokenResponse response = TokenUtils.getPhotoShareTokenResponse(photo);
photo.setShareToken(response.getToken());
}
return photo;
}
use of com.trovebox.android.common.net.TokenResponse 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();
}
Aggregations