Search in sources :

Example 6 with UploadMetaData

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();
}
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)

Example 7 with UploadMetaData

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

Example 8 with UploadMetaData

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

Example 9 with UploadMetaData

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));
        }
    }
}
Also used : UploadMetaData(com.trovebox.android.common.net.UploadMetaData) Intent(android.content.Intent) UploadsProviderAccessor(com.trovebox.android.common.provider.UploadsProviderAccessor) File(java.io.File)

Aggregations

UploadMetaData (com.trovebox.android.common.net.UploadMetaData)9 File (java.io.File)6 UploadResponse (com.trovebox.android.common.net.UploadResponse)5 JSONException (org.json.JSONException)5 IOException (java.io.IOException)4 ClientProtocolException (org.apache.http.client.ClientProtocolException)4 Photo (com.trovebox.android.common.model.Photo)3 PhotosResponse (com.trovebox.android.common.net.PhotosResponse)2 UploadsProviderAccessor (com.trovebox.android.common.provider.UploadsProviderAccessor)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Notification (android.app.Notification)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 Parcel (android.os.Parcel)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 Token (com.trovebox.android.common.model.Token)1 ProgressListener (com.trovebox.android.common.net.HttpEntityWithProgress.ProgressListener)1 PhotoResponse (com.trovebox.android.common.net.PhotoResponse)1 TokenResponse (com.trovebox.android.common.net.TokenResponse)1