@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PhotoModel that = (PhotoModel) o; return Objects.equal(getTitle(), that.getTitle()) && Objects.equal(getFetchableUrl(), that.getFetchableUrl()) && Objects.equal(getDescription(), that.getDescription()) && Objects.equal(getMediaType(), that.getMediaType()) && Objects.equal(getDataId(), that.getDataId()) && Objects.equal(getAlbumId(), that.getAlbumId()); } }
SmugMugImageUploadResponse uploadImage(PhotoModel photoModel, String albumUri, InputStream inputStream) throws IOException { // Set up photo InputStreamContent content = new InputStreamContent(null, inputStream); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); content.writeTo(outputStream); byte[] contentBytes = outputStream.toByteArray(); // Headers from: https://api.smugmug.com/api/v2/doc/reference/upload.html Map<String, String> headersMap = new HashMap<>(); headersMap.put("X-Smug-AlbumUri", albumUri); headersMap.put("X-Smug-ResponseType", "JSON"); headersMap.put("X-Smug-Version", "v2"); headersMap.put("Content-Type", photoModel.getMediaType()); if (!Strings.isNullOrEmpty(photoModel.getTitle())) { headersMap.put("X-Smug-Title", photoModel.getTitle()); } if (!Strings.isNullOrEmpty(photoModel.getDescription())) { headersMap.put("X-Smug-Caption", photoModel.getDescription()); } // Upload photo return postRequest( "https://upload.smugmug.com/", ImmutableMap.of(), // No content params for photo upload contentBytes, headersMap, new TypeReference<SmugMugImageUploadResponse>() { }); }
requestBuilder.header("Authorization", "Bearer " + authData.getToken()); MediaType contentType = MediaType.parse(photoModel.getMediaType());
@Test public void toCommonPhoto() { Photo photo = FlickrTestUtils.initializePhoto(PHOTO_TITLE, FETCHABLE_URL, PHOTO_DESCRIPTION, MEDIA_TYPE); PhotoModel photoModel = FlickrPhotosExporter.toCommonPhoto(photo, ALBUM_ID); assertThat(photoModel.getAlbumId()).isEqualTo(ALBUM_ID); assertThat(photoModel.getFetchableUrl()).isEqualTo(FETCHABLE_URL); assertThat(photoModel.getTitle()).isEqualTo(PHOTO_TITLE); assertThat(photoModel.getDescription()).isEqualTo(PHOTO_DESCRIPTION); assertThat(photoModel.getMediaType()).isEqualTo("image/jpeg"); }
Assert.assertEquals("testimage1.png", photo1.getTitle()); Assert.assertEquals("image1", photo1.getDataId()); Assert.assertEquals("image/png", photo1.getMediaType()); Assert.assertEquals(album.getId(), photo1.getAlbumId()); Assert.assertEquals("testimage2.png", photo2.getTitle()); Assert.assertEquals("image2", photo2.getDataId()); Assert.assertEquals("image/jpeg", photo2.getMediaType()); Assert.assertEquals(album.getId(), photo2.getAlbumId());