Search in sources :

Example 1 with TokenResponse

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;
}
Also used : TokenResponse(com.trovebox.android.common.net.TokenResponse)

Example 2 with TokenResponse

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;
}
Also used : TokenResponse(com.trovebox.android.common.net.TokenResponse)

Example 3 with TokenResponse

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();
}
Also used : UploadResponse(com.trovebox.android.common.net.UploadResponse) TokenResponse(com.trovebox.android.common.net.TokenResponse) UploadMetaData(com.trovebox.android.common.net.UploadMetaData) PhotosResponse(com.trovebox.android.common.net.PhotosResponse) Photo(com.trovebox.android.common.model.Photo) Token(com.trovebox.android.common.model.Token) File(java.io.File) ClientProtocolException(org.apache.http.client.ClientProtocolException) JSONException(org.json.JSONException) IOException(java.io.IOException)

Aggregations

TokenResponse (com.trovebox.android.common.net.TokenResponse)3 Photo (com.trovebox.android.common.model.Photo)1 Token (com.trovebox.android.common.model.Token)1 PhotosResponse (com.trovebox.android.common.net.PhotosResponse)1 UploadMetaData (com.trovebox.android.common.net.UploadMetaData)1 UploadResponse (com.trovebox.android.common.net.UploadResponse)1 File (java.io.File)1 IOException (java.io.IOException)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1 JSONException (org.json.JSONException)1