Search in sources :

Example 1 with SmugMugAlbumInfoResponse

use of org.dataportabilityproject.serviceProviders.smugmug.model.SmugMugAlbumInfoResponse in project data-transfer-project by google.

the class SmugMugPhotoService method getImages.

private PhotosModelWrapper getImages(IdOnlyResource resource, Optional<PaginationInformation> paginationInformation) throws IOException {
    List<PhotoModel> photos = new ArrayList<>();
    String url;
    if (paginationInformation.isPresent()) {
        url = ((StringPaginationToken) paginationInformation.get()).getId();
    } else {
        String id = resource.getId();
        url = "/api/v2/album/" + id + "!images";
    }
    StringPaginationToken pageToken = null;
    SmugMugResponse<SmugMugAlbumInfoResponse> albumInfoResponse = makeAlbumInfoRequest(url);
    if (albumInfoResponse.getResponse().getImages() != null) {
        for (SmugMugAlbumImage image : albumInfoResponse.getResponse().getImages()) {
            String title = image.getTitle();
            if (Strings.isNullOrEmpty(title)) {
                title = image.getFileName();
            }
            try {
                photos.add(new PhotoModel(title, this.authConsumer.sign(image.getArchivedUri()), image.getCaption(), image.getFormat(), resource.getId()));
            } catch (OAuthException e) {
                throw new IOException("Couldn't sign: " + image.getArchivedUri(), e);
            }
        }
        if (albumInfoResponse.getResponse().getPageInfo().getNextPage() != null) {
            pageToken = new StringPaginationToken(albumInfoResponse.getResponse().getPageInfo().getNextPage());
        }
    }
    return new PhotosModelWrapper(null, photos, new ContinuationInformation(null, pageToken));
}
Also used : ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) PhotoModel(org.dataportabilityproject.dataModels.photos.PhotoModel) SmugMugAlbumImage(org.dataportabilityproject.serviceProviders.smugmug.model.SmugMugAlbumImage) OAuthException(oauth.signpost.exception.OAuthException) ArrayList(java.util.ArrayList) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) IOException(java.io.IOException) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken) SmugMugAlbumInfoResponse(org.dataportabilityproject.serviceProviders.smugmug.model.SmugMugAlbumInfoResponse)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 OAuthException (oauth.signpost.exception.OAuthException)1 ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)1 PhotoModel (org.dataportabilityproject.dataModels.photos.PhotoModel)1 PhotosModelWrapper (org.dataportabilityproject.dataModels.photos.PhotosModelWrapper)1 SmugMugAlbumImage (org.dataportabilityproject.serviceProviders.smugmug.model.SmugMugAlbumImage)1 SmugMugAlbumInfoResponse (org.dataportabilityproject.serviceProviders.smugmug.model.SmugMugAlbumInfoResponse)1 StringPaginationToken (org.dataportabilityproject.shared.StringPaginationToken)1