Skip to content

Commit

Permalink
Merge pull request #17 from gettyimages/custom_headers_and_params
Browse files Browse the repository at this point in the history
Custom headers and params
  • Loading branch information
ssterli2 authored Sep 30, 2022
2 parents c2d53d1 + 222716d commit 2b11d98
Show file tree
Hide file tree
Showing 19 changed files with 1,317 additions and 1,070 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,29 @@ $ mvn install
}
```

### Search creative images with phrase, custom parameter, and customer header
```java
String apiKey = "API Key";
String apiSecret = "API Secret";
String userName = "Username";
String userPassword = "Password";

ApiClient client = ApiClient.GetApiClientWithResourceOwnerCredentials(apiKey, apiSecret, userName, userPassword);

try {
SearchImagesCreative search = client.searchimagescreative()
.withPhrase("cat")
.withCustomParameter("safe_search", "true")
.withCustomHeader("gi-country-code", "CAN");
String result = search.executeAsync();
System.out.print(result);

} catch (SdkException e) {
System.out.println("Exception occurred while searching for creative images: " + e.getLocalizedMessage());
System.exit(-1);
}
```

### Custom Request to search images with phrase, fields, and age of people

```java
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/gettyimages/api/Search/SearchImages.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ public String executeAsync() throws SdkException {
return super.executeAsync();
}

public SearchImages withCustomHeader(String key, String value) {
headers.put(key, value);
return this;
}

public SearchImages withCustomParameter(String key, String value) {
queryParams.put(key, value);
return this;
}

public SearchImages withAcceptLanguage(String value)
{
headers.put(Constants.AcceptLanguageString, value);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/gettyimages/api/Search/SearchImagesCreative.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ public String executeAsync() throws SdkException {
return super.executeAsync();
}

public SearchImagesCreative withCustomHeader(String key, String value) {
headers.put(key, value);
return this;
}

public SearchImagesCreative withCustomParameter(String key, String value) {
queryParams.put(key, value);
return this;
}

public SearchImagesCreative withAcceptLanguage(String value)
{
headers.put(Constants.AcceptLanguageString, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ public String executeAsync() throws SdkException {
return super.executeAsync();
}

public SearchImagesEditorial withCustomHeader(String key, String value) {
headers.put(key, value);
return this;
}

public SearchImagesEditorial withCustomParameter(String key, String value) {
queryParams.put(key, value);
return this;
}

public SearchImagesEditorial withAcceptLanguage(String value)
{
headers.put(Constants.AcceptLanguageString, value);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/gettyimages/api/Search/SearchVideos.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ public String executeAsync() throws SdkException {
return super.executeAsync();
}

public SearchVideos withCustomHeader(String key, String value) {
headers.put(key, value);
return this;
}

public SearchVideos withCustomParameter(String key, String value) {
queryParams.put(key, value);
return this;
}

public SearchVideos withAcceptLanguage(String value)
{
headers.put(Constants.AcceptLanguageString, value);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/gettyimages/api/Search/SearchVideosCreative.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ public String executeAsync() throws SdkException {
return super.executeAsync();
}

public SearchVideosCreative withCustomHeader(String key, String value) {
headers.put(key, value);
return this;
}

public SearchVideosCreative withCustomParameter(String key, String value) {
queryParams.put(key, value);
return this;
}

public SearchVideosCreative withAcceptLanguage(String value)
{
headers.put(Constants.AcceptLanguageString, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ public String executeAsync() throws SdkException {
return super.executeAsync();
}

public SearchVideosEditorial withCustomHeader(String key, String value) {
headers.put(key, value);
return this;
}

public SearchVideosEditorial withCustomParameter(String key, String value) {
queryParams.put(key, value);
return this;
}

public SearchVideosEditorial withAcceptLanguage(String value)
{
headers.put(Constants.AcceptLanguageString, value);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/AuthFailureTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockserver.integration.ClientAndServer.startClientAndServer;
import static org.mockserver.model.HttpRequest.request;
Expand Down
123 changes: 59 additions & 64 deletions src/test/java/CustomRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public static void startProxy() throws Exception {
field.setAccessible(true);
field.set(null, "http://127.0.0.1:1080/");
mockServer = startClientAndServer(1080);
}

@BeforeEach
public void createMock(){
MockServerClient client = new MockServerClient("127.0.0.1", 1080);

client
Expand All @@ -53,81 +49,80 @@ public void createMock(){
.withBody("{ access_token: 'client_credentials_access_token', token_type: 'Bearer', expires_in: '1800' }")
);
client.when(
request()
.withMethod("GET")
.withPath("/search/images")
.withQueryStringParameters(
new Parameter("phrase", "cat"),
new Parameter("compositions", "abstract,full_frame")
)
)
request()
.withMethod("GET")
.withPath("/search/images")
.withQueryStringParameters(
new Parameter("phrase", "cat"),
new Parameter("compositions", "abstract,full_frame")
)
)
.respond(response().withStatusCode(200).withBody("success"));
client.when(
request()
.withMethod("POST")
.withPath("/downloads/images/12345")
.withQueryStringParameters(
new Parameter("auto_download", "false")
)
)
request()
.withMethod("POST")
.withPath("/downloads/images/12345")
.withQueryStringParameters(
new Parameter("auto_download", "false")
)
)
.respond(response().withStatusCode(200).withBody("success"));
client.when(
request()
.withMethod("POST")
.withPath("/boards")
.withBody(
json("{" + System.lineSeparator() +
" \"name\": \"new board\"," + System.lineSeparator() +
" \"description\": \"new description\"" + System.lineSeparator() +
"}",
MatchType.STRICT
request()
.withMethod("POST")
.withPath("/boards")
.withBody(
json("{" + System.lineSeparator() +
" \"name\": \"new board\"," + System.lineSeparator() +
" \"description\": \"new description\"" + System.lineSeparator() +
"}",
MatchType.STRICT
)
)
)
)
)
.respond(response().withStatusCode(200).withBody("success"));
client.when(
request()
.withMethod("PUT")
.withPath("/asset-changes/change-sets")
.withQueryStringParameters(
new Parameter("channel_id", "3")
)
)
request()
.withMethod("PUT")
.withPath("/asset-changes/change-sets")
.withQueryStringParameters(
new Parameter("channel_id", "3")
)
)
.respond(response().withStatusCode(200).withBody("success"));
client.when(
request()
.withMethod("PUT")
.withPath("/boards/111")
.withBody(
json("{" + System.lineSeparator() +
" \"name\": \"new board\"," + System.lineSeparator() +
" \"description\": \"new description\"" + System.lineSeparator() +
"}",
MatchType.STRICT
request()
.withMethod("PUT")
.withPath("/boards/111")
.withBody(
json("{" + System.lineSeparator() +
" \"name\": \"new board\"," + System.lineSeparator() +
" \"description\": \"new description\"" + System.lineSeparator() +
"}",
MatchType.STRICT
)
)
)
)
)
.respond(response().withStatusCode(200).withBody("success"));
client.when(
request()
.withMethod("DELETE")
.withPath("/boards/333")
.withQueryStringParameters(
new Parameter("asset_ids", "1234,5678")
)
)
request()
.withMethod("DELETE")
.withPath("/boards/333")
.withQueryStringParameters(
new Parameter("asset_ids", "1234,5678")
)
)
.respond(response().withStatusCode(200).withBody("success"));
client.when(
request()
.withMethod("GET")
.withPath("/search/images")
.withQueryStringParameters(
new Parameter("phrase", "cat")
)
.withHeader("Accept-Language", "de")
)
request()
.withMethod("GET")
.withPath("/search/images")
.withQueryStringParameters(
new Parameter("phrase", "cat")
)
.withHeader("Accept-Language", "de")
)
.respond(response().withStatusCode(200).withBody("success"));

}

@Test
Expand Down
84 changes: 40 additions & 44 deletions src/test/java/DownloadImagesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ public static void startProxy() throws Exception {
field.setAccessible(true);
field.set(null, "http://127.0.0.1:1080/");
mockServer = startClientAndServer(1080);
}

@BeforeEach
public void createMock(){
MockServerClient client = new MockServerClient("127.0.0.1", 1080);

client
Expand All @@ -44,54 +40,54 @@ public void createMock(){
.withBody("{ access_token: 'client_credentials_access_token', token_type: 'Bearer', expires_in: '1800' }")
);
client.when(
request()
.withMethod("POST")
.withPath("/downloads/images/12345")
.withQueryStringParameters(
new Parameter("auto_download", "false")
)
.withHeader("Accept-Language", "de")
)
request()
.withMethod("POST")
.withPath("/downloads/images/12345")
.withQueryStringParameters(
new Parameter("auto_download", "false")
)
.withHeader("Accept-Language", "de")
)
.respond(response().withStatusCode(200).withBody("success"));
client.when(
request()
.withMethod("POST")
.withPath("/downloads/images/12345")
.withQueryStringParameters(
new Parameter("file_type", "jpg"),
new Parameter("auto_download", "false")
)
)
request()
.withMethod("POST")
.withPath("/downloads/images/12345")
.withQueryStringParameters(
new Parameter("file_type", "jpg"),
new Parameter("auto_download", "false")
)
)
.respond(response().withStatusCode(200).withBody("success"));
client.when(
request()
.withMethod("POST")
.withPath("/downloads/images/12345")
.withQueryStringParameters(
new Parameter("auto_download", "false"),
new Parameter("height", "592")
)
)
request()
.withMethod("POST")
.withPath("/downloads/images/12345")
.withQueryStringParameters(
new Parameter("auto_download", "false"),
new Parameter("height", "592")
)
)
.respond(response().withStatusCode(200).withBody("success"));
client.when(
request()
.withMethod("POST")
.withPath("/downloads/images/12345")
.withQueryStringParameters(
new Parameter("product_id", "9876"),
new Parameter("auto_download", "false")
)
)
request()
.withMethod("POST")
.withPath("/downloads/images/12345")
.withQueryStringParameters(
new Parameter("product_id", "9876"),
new Parameter("auto_download", "false")
)
)
.respond(response().withStatusCode(200).withBody("success"));
client.when(
request()
.withMethod("POST")
.withPath("/downloads/images/12345")
.withQueryStringParameters(
new Parameter("product_type", "easyaccess"),
new Parameter("auto_download", "false")
)
)
request()
.withMethod("POST")
.withPath("/downloads/images/12345")
.withQueryStringParameters(
new Parameter("product_type", "easyaccess"),
new Parameter("auto_download", "false")
)
)
.respond(response().withStatusCode(200).withBody("success"));

}
Expand Down
Loading

0 comments on commit 2b11d98

Please sign in to comment.