@Before public void setUp() { FacebookPhotosInterface photosInterface = mock(FacebookPhotosInterface.class); // Set up example album Album album = new Album(); album.setId(ALBUM_ID); album.setName(ALBUM_NAME); album.setDescription(ALBUM_DESCRIPTION); ArrayList<Album> albums = new ArrayList<>(); albums.add(album); @SuppressWarnings("unchecked") Connection<Album> albumConnection = mock(Connection.class); when(photosInterface.getAlbums(Mockito.any())).thenReturn(albumConnection); when(albumConnection.getData()).thenReturn(albums); // Set up example photo Photo photo = new Photo(); photo.setId(PHOTO_ID); Photo.Image image = new Photo.Image(); image.setSource(PHOTO_SOURCE); photo.addImage(image); photo.setName(PHOTO_NAME); ArrayList<Photo> photos = new ArrayList<>(); photos.add(photo); @SuppressWarnings("unchecked") Connection<Photo> photoConnection = mock(Connection.class); when(photosInterface.getPhotos(ALBUM_ID, Optional.empty())).thenReturn(photoConnection); when(photoConnection.getData()).thenReturn(photos); facebookPhotosExporter = new FacebookPhotosExporter(new AppCredentials("key", "secret"), photosInterface); }
List<Photo> photos = photoConnection.getData(); for (Photo photo : photos) { Preconditions.checkNotNull(photo.getImages().get(0).getSource()); exportPhotos.add( new PhotoModel( String.format("%s.jpg", photo.getId()), photo.getImages().get(0).getSource(), photo.getName(), "image/jpg", photo.getId(), albumId, false));
private ExportResult<PhotosContainerResource> exportAlbums( TokensAndUrlAuthData authData, Optional<StringPaginationToken> paginationData) { Optional<String> paginationToken = stripTokenPrefix(paginationData, ALBUM_TOKEN_PREFIX); ArrayList<PhotoAlbum> exportAlbums = new ArrayList<>(); // Get albums Connection<Album> connection = getOrCreatePhotosInterface(authData).getAlbums(paginationToken); PaginationData nextPageData = null; String token = connection.getAfterCursor(); if (!Strings.isNullOrEmpty(token)) { nextPageData = new StringPaginationToken(ALBUM_TOKEN_PREFIX + token); } ContinuationData continuationData = new ContinuationData(nextPageData); List<Album> albums = connection.getData(); for (Album album : albums) { exportAlbums.add(new PhotoAlbum(album.getId(), album.getName(), album.getDescription())); continuationData.addContainerResource(new IdOnlyContainerResource(album.getId())); } return new ExportResult<>( ExportResult.ResultType.CONTINUE, new PhotosContainerResource(exportAlbums, null), continuationData); }
/** * The user's hometown name. * * @return The user's hometown name. */ public String getHometownName() { if (getHometown() != null) return getHometown().getName(); return hometownAsString; }
/** * The number of likes on this post. * * @return The number of likes on this post. */ public Long getLikesCount() { if (getLikes() != null) { return getLikes().getTotalCount(); } return likesCount; }
/** * The number of reactions on this post. * * @return The number of reactions on this post. */ public Long getReactionsCount() { if (getReactions() != null) { return getReactions().getTotalCount(); } return 0L; }
/** * The number of likes on this video. * * you have to fetch the video id with <code>?fields=likes.summary(true)</code> in order to speed up the likes count * generation, you may use <code>?fields=likes.limit(1).summary(true)</code>, so only 1 like is fetched, but the * complete summary * * @return The number of likes on this video. */ public Long getLikesCount() { if (getLikes() != null) { return getLikes().getTotalCount(); } return 0L; }
/** * The number of comments of this video. * * you have to fetch the video id with <code>?fields=comments.summary(true)</code> in order to speed up the comments * count generation, you may use <code>?fields=comments.limit(1).summary(true)</code>, so only 1 comment is fetched, * but the complete summary * * @return The number of comments of this video. */ public Long getCommentsCount() { if (getComments() != null) { return getComments().getTotalCount(); } return 0L; }
/** * Adds a comment * @param comment the comment that should be added * @return true if the comment was added, false otherwise * @deprecated work on the {@code Comments} object directly instead of using this method */ @Deprecated public boolean addComment(Comment comment) { if (getComments() != null) { return getComments().addData(comment); } return false; }
/** * Adds a comment * @param comment the comment that should be added * @return true if the comment was added, false otherwise * @deprecated work on the {@code Comments} object directly instead of using this method */ @Deprecated public boolean removeComment(Comment comment) { if (getComments() != null) { return getComments().removeData(comment); } return false; }
/** * The number of comments of this post. * * @return The number of comments of this post. */ public Long getCommentsCount() { if (comments != null) { return comments.getTotalCount(); } return 0L; }
/** * The number of shares of this post. * * @return The number of shares of this post. */ public Long getSharesCount() { if (shares != null) { return shares.getCount(); } return 0L; }
public boolean addLocale(Integer locale) { if (geoLocations != null) { return geoLocations.addLocale(locale); } return locales.add(locale); }
public boolean removeLocale(Integer locale) { if (geoLocations != null) { return geoLocations.removeLocale(locale); } return locales.remove(locale); }
public boolean addCountry(String country) { if (geoLocations != null) { return geoLocations.addCountry(country); } return countries.add(country); }
public boolean addRegion(KeyedType region) { if (geoLocations != null) { return geoLocations.addRegion(region); } return regions.add(region); }
public boolean removeCountry(String country) { if (geoLocations != null) { return geoLocations.removeCountry(country); } return countries.remove(country); }
/** * The user's hometown name. * * @return The user's hometown name. */ public String getHometownName() { if (getHometown() != null) return getHometown().getName(); return hometownAsString; }