Skip to content

Commit

Permalink
Merge pull request #27 from tinify/post-bug
Browse files Browse the repository at this point in the history
Small fix on requests
  • Loading branch information
ddmicu authored Mar 15, 2023
2 parents 6d361c2 + 6ae3e57 commit cb11b24
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.8.3
* Fix for requests with empty body

## 1.8.2
* Fixed Import-Package manifest for OSGI deployments

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.tinify</groupId>
<artifactId>tinify</artifactId>
<version>1.8.2</version>
<version>1.8.3</version>
<name>Tinify</name>
<description>Java client for the Tinify API. Tinify compresses your images intelligently. Read more at https://tinify.com.</description>
<url>https://tinify.com</url>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tinify/Source.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public final ResultMeta store(final Options options) {

public final Result result() throws IOException {
Client.Response response;
if (commands == null) {
if (commands == null || commands.isEmpty()) {
response = Tinify.client().request(Client.Method.GET, url);
} else {
response = Tinify.client().request(Client.Method.POST, url, commands);
Expand Down
42 changes: 41 additions & 1 deletion src/test/java/com/tinify/SourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,44 @@ public void withValidApiKeyToFileShouldStoreImageData() throws Exception, IOExce
assertThat(Files.readAllBytes(tempFile),
is(equalTo("compressed file".getBytes())));
}
}


/*
* The following tests should probably be done with parametrized tests
*/
@Test
public void withOptionsNotEmptyResultDoesAPOST() throws Exception, IOException, InterruptedException {
Tinify.setKey("valid");

server.enqueue(new MockResponse()
.setResponseCode(200)
.setBody("compressed file"));
Result result = new Source("https://api.tinify.com/some/location", new Options().with("I am not", "empty")).result();
RecordedRequest outputRequest = server.takeRequest(1, TimeUnit.SECONDS);
assertEquals("POST", outputRequest.getMethod());
}

@Test
public void withOptionsNULLResultDoesAGET() throws Exception, IOException, InterruptedException {
Tinify.setKey("valid");

server.enqueue(new MockResponse()
.setResponseCode(200)
.setBody("compressed file"));
Result result = new Source("https://api.tinify.com/some/location", null).result();
RecordedRequest outputRequest = server.takeRequest(1, TimeUnit.SECONDS);
assertEquals("GET", outputRequest.getMethod());
}

@Test
public void withOptionsEmptyResultDoesAGET() throws Exception, IOException, InterruptedException {
Tinify.setKey("valid");

server.enqueue(new MockResponse()
.setResponseCode(200)
.setBody("compressed file"));
Result result = new Source("https://api.tinify.com/some/location", new Options()).result();
RecordedRequest outputRequest = server.takeRequest(1, TimeUnit.SECONDS);
assertEquals("GET", outputRequest.getMethod());
}
}

0 comments on commit cb11b24

Please sign in to comment.