/** * Add a photo to a photoset. * * @param ssPhotoset the photoset to add the photo to. * @param photo the photo to add. * @throws Exception if there are any errors, or if either parameter is null. */ public void addPhoto(SSPhotoset ssPhotoset, Photo photo) throws Exception { if (ssPhotoset == null) { throw new Exception("addPhoto: PARAMETER CANNOT BE NULL."); } if (photo == null) { throw new Exception("addPhoto: PHOTO CANNOT BE NULL."); } // RequestContext rc = FlickrHelper.getInstance().getRequestContext(); // PhotosetsInterface pi = FlickrHelper.getInstance().getPhotosetsInterface(); try { // pi.addPhoto(ssPhotoset.getId(), photo.getId()); // PhotosetsApi.getInstance().addPhoto(ssPhotoset.getId(), photo.getId()); Response response = JinxFactory.getInstance() .getPhotosetsApi() .addPhoto(ssPhotoset.getPhotosetId(), photo.getPhotoId()); if (response.getCode() == 0) { logger.info("Photo " + photo.getTitle() + " added to set " + ssPhotoset.getTitle()); } else if (response.getCode() == 3) { logger.info("Photo " + photo.getTitle() + " already in set, not added."); } } catch (JinxException fe) { logger.warn("Unexpected flickr error", fe); } catch (Exception e) { logger.error("Unexpected error.", e); } }
@Test public void parseGetPhotos() throws Exception { InputStreamReader reader = new InputStreamReader( ActivityResponseTest.class.getResourceAsStream( "/response/galleries/sample_get_photos.json")); Photos photos = new Gson().fromJson(reader, Photos.class); reader.close(); assertNotNull(photos); assertEquals("ok", photos.getStat()); assertEquals(0, photos.getCode()); assertEquals(1, (int) photos.getPage()); assertEquals(1, (int) photos.getPages()); assertEquals(500, (int) photos.getPerPage()); assertEquals(13, (int) photos.getTotal()); assertNotNull(photos.getPhotoList()); assertEquals(13, photos.getPhotoList().size()); Photo p = photos.getPhotoList().get(0); assertEquals("8413449964", p.getPhotoId()); assertEquals("85853333@N00", p.getOwner()); assertEquals("edd91a1d17", p.getSecret()); assertEquals("8473", p.getServer()); assertEquals("9", p.getFarm()); assertEquals("China Chef", p.getTitle()); assertTrue(p.isPublic()); assertFalse(p.isFriend()); assertFalse(p.isFamily()); assertTrue(p.isPrimary()); assertFalse(p.isHasComment()); }