public FlickrPhotosExporter(AppCredentials appCredentials) { this.flickr = new Flickr(appCredentials.getKey(), appCredentials.getSecret(), new REST()); this.photosetsInterface = flickr.getPhotosetsInterface(); this.photosInterface = flickr.getPhotosInterface(); }
@VisibleForTesting FlickrPhotosExporter(Flickr flickr) { this.flickr = flickr; this.photosInterface = flickr.getPhotosInterface(); this.photosetsInterface = flickr.getPhotosetsInterface(); }
@VisibleForTesting FlickrPhotosImporter(Flickr flickr, JobStore jobstore, ImageStreamProvider imageStreamProvider) { this.flickr = flickr; this.imageStreamProvider = imageStreamProvider; this.jobStore = jobstore; this.uploader = flickr.getUploader(); this.photosetsInterface = flickr.getPhotosetsInterface(); }
@Test public void exportPhotosFromPhotoset() throws FlickrException { when(user.getId()).thenReturn("userId"); when(authInterface.checkToken(any(Token.class))).thenReturn(auth); when(flickr.getPhotosetsInterface()).thenReturn(photosetsInterface); when(flickr.getPhotosInterface()).thenReturn(photosInterface); when(flickr.getAuthInterface()).thenReturn(authInterface); PhotoList<Photo> photosList = new PhotoList<>(); for (int i = 0; i < numPhotos; i++) { photosList.add( FlickrTestUtils.initializePhoto("title" + 1, "url" + i, "description" + i, MEDIA_TYPE)); photosList.setPage(page); photosList.setPages(page + 1); when(photosetsInterface.getPhotos(anyString(), anySet(), anyInt(), anyInt(), anyInt())) .thenReturn(photosList);
@Test public void exportAlbumInitial() throws FlickrException { when(user.getId()).thenReturn("userId"); when(authInterface.checkToken(any(Token.class))).thenReturn(auth); when(flickr.getPhotosetsInterface()).thenReturn(photosetsInterface); when(flickr.getPhotosInterface()).thenReturn(photosInterface); when(flickr.getAuthInterface()).thenReturn(authInterface); Photosets photosetsList = new Photosets(); photosetsList.setPage(page); photosetsList.setPages(page + 1); photosetsList.setPhotosets(Collections.singletonList(photoset)); when(photosetsInterface.getList(anyString(), anyInt(), anyInt(), anyString())) .thenReturn(photosetsList);
when(user.getId()).thenReturn("userId"); when(authInterface.checkToken(any(Token.class))).thenReturn(auth); when(flickr.getPhotosetsInterface()).thenReturn(photosetsInterface); when(flickr.getUploader()).thenReturn(uploader); when(flickr.getAuthInterface()).thenReturn(authInterface); when(imageStreamProvider.get(FETCHABLE_URL)).thenReturn(bufferedInputStream); when(uploader.upload(any(BufferedInputStream.class), any(UploadMetaData.class))) .thenReturn(FLICKR_PHOTO_ID); Photoset photoset = FlickrTestUtils.initializePhotoset(FLICKR_ALBUM_ID, ALBUM_DESCRIPTION, FLICKR_PHOTO_ID); when(photosetsInterface.create(flickrAlbumTitle, ALBUM_DESCRIPTION, FLICKR_PHOTO_ID)) .thenReturn(photoset); verify(uploader).upload(eq(bufferedInputStream), uploadMetaDataArgumentCaptor.capture()); UploadMetaData actualUploadMetaData = uploadMetaDataArgumentCaptor.getValue(); assertThat(actualUploadMetaData.getTitle()) .isEqualTo(FlickrPhotosImporter.COPY_PREFIX + PHOTO_TITLE); assertThat(actualUploadMetaData.getDescription()).isEqualTo(PHOTO_DESCRIPTION); verify(photosetsInterface).create(flickrAlbumTitle, ALBUM_DESCRIPTION, FLICKR_PHOTO_ID);
public FlickrPhotosImporter(AppCredentials appCredentials, JobStore jobStore) { this.jobStore = jobStore; this.flickr = new Flickr(appCredentials.getKey(), appCredentials.getSecret(), new REST()); this.uploader = flickr.getUploader(); this.imageStreamProvider = new ImageStreamProvider(); this.photosetsInterface = flickr.getPhotosetsInterface(); }
RequestContext.getRequestContext().setExtras(EXTRAS); photoSetList = photosInterface.getNotInSet(PHOTO_PER_PAGE, page); RequestContext.getRequestContext().setExtras(ImmutableList.of()); } else { photoSetList = photosetsInterface.getPhotos( photoSetId, ImmutableSet.copyOf(EXTRAS), 0, PHOTO_PER_PAGE, page); boolean hasMore = photoSetList.getPage() != photoSetList.getPages() && !photoSetList.isEmpty(); photoSetList.stream().map(p -> toCommonPhoto(p, photoSetId)).collect(Collectors.toList());
/** * Construct an Uploader. * * @param apiKey * The API key */ public Uploader(String apiKey, String sharedSecret) { this(apiKey, sharedSecret, new REST(Transport.UPLOAD_API_HOST)); this.transport.setResponseClass(UploaderResponse.class); }
private void act(String suggestionId, String method) throws FlickrException { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("method", method); parameters.put("suggestion_id", suggestionId); Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret); if (response.isError()) { throw new FlickrException(response.getErrorCode(), response.getErrorMessage()); } }
public void editPhotos(String strGalleryId, String strPrimaryPhotoId, String strPhotoIds) throws FlickrException { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("method", METHOD_EDIT_PHOTOS); parameters.put("gallery_id", strGalleryId); parameters.put("primary_photo_id", strPrimaryPhotoId); parameters.put("photo_ids", strPhotoIds); Response response = transport.post(transport.getPath(), parameters, apiKey, sharedSecret); if (response.isError()) { throw new FlickrException(response.getErrorCode(), response.getErrorMessage()); } }
public static Auth getAuth(AuthData authData, Flickr flickr) throws FlickrException { checkArgument( authData instanceof TokenSecretAuthData, "authData expected to be TokenSecretAuthData not %s", authData.getClass().getCanonicalName()); TokenSecretAuthData tokenAuthData = (TokenSecretAuthData) authData; Token requestToken = new Token(tokenAuthData.getToken(), tokenAuthData.getSecret()); return flickr.getAuthInterface().checkToken(requestToken); } }
/** * Construct a new REST transport instance. */ public REST() { setTransportType(REST); setHost(API_HOST); setPath(PATH); setScheme(DEFAULT_SCHEME); setResponseClass(RESTResponse.class); }
@Override public ExportResult<PhotosContainerResource> export( UUID jobId, AuthData authData, Optional<ExportInformation> exportInformation) { Auth auth; try { auth = FlickrUtils.getAuth(authData, flickr); } catch (FlickrException e) { return new ExportResult<>(e); } RequestContext.getRequestContext().setAuth(auth); PaginationData paginationData = exportInformation.isPresent() ? exportInformation.get().getPaginationData() : null; IdOnlyContainerResource resource = exportInformation.isPresent() ? (IdOnlyContainerResource) exportInformation.get().getContainerResource() : null; if (resource != null) { return getPhotos(resource, paginationData); } else { return getAlbums(paginationData, auth); } }
/** * Get the RequestContext instance for the current Thread. * * @return The RequestContext */ public static RequestContext getRequestContext() { return threadLocal.get(); }
/** * Construct an Uploader. * * @param apiKey * The API key */ public Uploader(String apiKey, String sharedSecret) { this(apiKey, sharedSecret, new REST(Transport.UPLOAD_API_HOST)); this.transport.setResponseClass(UploaderResponse.class); }
return new ImportResult(e); RequestContext.getRequestContext().setAuth(auth);