Skip to content
This repository was archived by the owner on Sep 24, 2025. It is now read-only.

Commit 2b11d98

Browse files
authored
Merge pull request #17 from gettyimages/custom_headers_and_params
Custom headers and params
2 parents c2d53d1 + 222716d commit 2b11d98

19 files changed

+1317
-1070
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,29 @@ $ mvn install
9292
}
9393
```
9494

95+
### Search creative images with phrase, custom parameter, and customer header
96+
```java
97+
String apiKey = "API Key";
98+
String apiSecret = "API Secret";
99+
String userName = "Username";
100+
String userPassword = "Password";
101+
102+
ApiClient client = ApiClient.GetApiClientWithResourceOwnerCredentials(apiKey, apiSecret, userName, userPassword);
103+
104+
try {
105+
SearchImagesCreative search = client.searchimagescreative()
106+
.withPhrase("cat")
107+
.withCustomParameter("safe_search", "true")
108+
.withCustomHeader("gi-country-code", "CAN");
109+
String result = search.executeAsync();
110+
System.out.print(result);
111+
112+
} catch (SdkException e) {
113+
System.out.println("Exception occurred while searching for creative images: " + e.getLocalizedMessage());
114+
System.exit(-1);
115+
}
116+
```
117+
95118
### Custom Request to search images with phrase, fields, and age of people
96119

97120
```java

src/main/java/com/gettyimages/api/Search/SearchImages.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ public String executeAsync() throws SdkException {
2626
return super.executeAsync();
2727
}
2828

29+
public SearchImages withCustomHeader(String key, String value) {
30+
headers.put(key, value);
31+
return this;
32+
}
33+
34+
public SearchImages withCustomParameter(String key, String value) {
35+
queryParams.put(key, value);
36+
return this;
37+
}
38+
2939
public SearchImages withAcceptLanguage(String value)
3040
{
3141
headers.put(Constants.AcceptLanguageString, value);

src/main/java/com/gettyimages/api/Search/SearchImagesCreative.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ public String executeAsync() throws SdkException {
2626
return super.executeAsync();
2727
}
2828

29+
public SearchImagesCreative withCustomHeader(String key, String value) {
30+
headers.put(key, value);
31+
return this;
32+
}
33+
34+
public SearchImagesCreative withCustomParameter(String key, String value) {
35+
queryParams.put(key, value);
36+
return this;
37+
}
38+
2939
public SearchImagesCreative withAcceptLanguage(String value)
3040
{
3141
headers.put(Constants.AcceptLanguageString, value);

src/main/java/com/gettyimages/api/Search/SearchImagesEditorial.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ public String executeAsync() throws SdkException {
2626
return super.executeAsync();
2727
}
2828

29+
public SearchImagesEditorial withCustomHeader(String key, String value) {
30+
headers.put(key, value);
31+
return this;
32+
}
33+
34+
public SearchImagesEditorial withCustomParameter(String key, String value) {
35+
queryParams.put(key, value);
36+
return this;
37+
}
38+
2939
public SearchImagesEditorial withAcceptLanguage(String value)
3040
{
3141
headers.put(Constants.AcceptLanguageString, value);

src/main/java/com/gettyimages/api/Search/SearchVideos.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ public String executeAsync() throws SdkException {
2626
return super.executeAsync();
2727
}
2828

29+
public SearchVideos withCustomHeader(String key, String value) {
30+
headers.put(key, value);
31+
return this;
32+
}
33+
34+
public SearchVideos withCustomParameter(String key, String value) {
35+
queryParams.put(key, value);
36+
return this;
37+
}
38+
2939
public SearchVideos withAcceptLanguage(String value)
3040
{
3141
headers.put(Constants.AcceptLanguageString, value);

src/main/java/com/gettyimages/api/Search/SearchVideosCreative.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ public String executeAsync() throws SdkException {
2626
return super.executeAsync();
2727
}
2828

29+
public SearchVideosCreative withCustomHeader(String key, String value) {
30+
headers.put(key, value);
31+
return this;
32+
}
33+
34+
public SearchVideosCreative withCustomParameter(String key, String value) {
35+
queryParams.put(key, value);
36+
return this;
37+
}
38+
2939
public SearchVideosCreative withAcceptLanguage(String value)
3040
{
3141
headers.put(Constants.AcceptLanguageString, value);

src/main/java/com/gettyimages/api/Search/SearchVideosEditorial.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ public String executeAsync() throws SdkException {
2626
return super.executeAsync();
2727
}
2828

29+
public SearchVideosEditorial withCustomHeader(String key, String value) {
30+
headers.put(key, value);
31+
return this;
32+
}
33+
34+
public SearchVideosEditorial withCustomParameter(String key, String value) {
35+
queryParams.put(key, value);
36+
return this;
37+
}
38+
2939
public SearchVideosEditorial withAcceptLanguage(String value)
3040
{
3141
headers.put(Constants.AcceptLanguageString, value);

src/test/java/AuthFailureTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import static org.junit.Assert.assertEquals;
1+
import static org.junit.jupiter.api.Assertions.assertEquals;
22
import static org.junit.jupiter.api.Assertions.assertThrows;
33
import static org.mockserver.integration.ClientAndServer.startClientAndServer;
44
import static org.mockserver.model.HttpRequest.request;

src/test/java/CustomRequestTest.java

Lines changed: 59 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ public static void startProxy() throws Exception {
3737
field.setAccessible(true);
3838
field.set(null, "http://127.0.0.1:1080/");
3939
mockServer = startClientAndServer(1080);
40-
}
41-
42-
@BeforeEach
43-
public void createMock(){
4440
MockServerClient client = new MockServerClient("127.0.0.1", 1080);
4541

4642
client
@@ -53,81 +49,80 @@ public void createMock(){
5349
.withBody("{ access_token: 'client_credentials_access_token', token_type: 'Bearer', expires_in: '1800' }")
5450
);
5551
client.when(
56-
request()
57-
.withMethod("GET")
58-
.withPath("/search/images")
59-
.withQueryStringParameters(
60-
new Parameter("phrase", "cat"),
61-
new Parameter("compositions", "abstract,full_frame")
62-
)
63-
)
52+
request()
53+
.withMethod("GET")
54+
.withPath("/search/images")
55+
.withQueryStringParameters(
56+
new Parameter("phrase", "cat"),
57+
new Parameter("compositions", "abstract,full_frame")
58+
)
59+
)
6460
.respond(response().withStatusCode(200).withBody("success"));
6561
client.when(
66-
request()
67-
.withMethod("POST")
68-
.withPath("/downloads/images/12345")
69-
.withQueryStringParameters(
70-
new Parameter("auto_download", "false")
71-
)
72-
)
62+
request()
63+
.withMethod("POST")
64+
.withPath("/downloads/images/12345")
65+
.withQueryStringParameters(
66+
new Parameter("auto_download", "false")
67+
)
68+
)
7369
.respond(response().withStatusCode(200).withBody("success"));
7470
client.when(
75-
request()
76-
.withMethod("POST")
77-
.withPath("/boards")
78-
.withBody(
79-
json("{" + System.lineSeparator() +
80-
" \"name\": \"new board\"," + System.lineSeparator() +
81-
" \"description\": \"new description\"" + System.lineSeparator() +
82-
"}",
83-
MatchType.STRICT
71+
request()
72+
.withMethod("POST")
73+
.withPath("/boards")
74+
.withBody(
75+
json("{" + System.lineSeparator() +
76+
" \"name\": \"new board\"," + System.lineSeparator() +
77+
" \"description\": \"new description\"" + System.lineSeparator() +
78+
"}",
79+
MatchType.STRICT
80+
)
8481
)
85-
)
86-
)
82+
)
8783
.respond(response().withStatusCode(200).withBody("success"));
8884
client.when(
89-
request()
90-
.withMethod("PUT")
91-
.withPath("/asset-changes/change-sets")
92-
.withQueryStringParameters(
93-
new Parameter("channel_id", "3")
94-
)
95-
)
85+
request()
86+
.withMethod("PUT")
87+
.withPath("/asset-changes/change-sets")
88+
.withQueryStringParameters(
89+
new Parameter("channel_id", "3")
90+
)
91+
)
9692
.respond(response().withStatusCode(200).withBody("success"));
9793
client.when(
98-
request()
99-
.withMethod("PUT")
100-
.withPath("/boards/111")
101-
.withBody(
102-
json("{" + System.lineSeparator() +
103-
" \"name\": \"new board\"," + System.lineSeparator() +
104-
" \"description\": \"new description\"" + System.lineSeparator() +
105-
"}",
106-
MatchType.STRICT
94+
request()
95+
.withMethod("PUT")
96+
.withPath("/boards/111")
97+
.withBody(
98+
json("{" + System.lineSeparator() +
99+
" \"name\": \"new board\"," + System.lineSeparator() +
100+
" \"description\": \"new description\"" + System.lineSeparator() +
101+
"}",
102+
MatchType.STRICT
103+
)
107104
)
108-
)
109-
)
105+
)
110106
.respond(response().withStatusCode(200).withBody("success"));
111107
client.when(
112-
request()
113-
.withMethod("DELETE")
114-
.withPath("/boards/333")
115-
.withQueryStringParameters(
116-
new Parameter("asset_ids", "1234,5678")
117-
)
118-
)
108+
request()
109+
.withMethod("DELETE")
110+
.withPath("/boards/333")
111+
.withQueryStringParameters(
112+
new Parameter("asset_ids", "1234,5678")
113+
)
114+
)
119115
.respond(response().withStatusCode(200).withBody("success"));
120116
client.when(
121-
request()
122-
.withMethod("GET")
123-
.withPath("/search/images")
124-
.withQueryStringParameters(
125-
new Parameter("phrase", "cat")
126-
)
127-
.withHeader("Accept-Language", "de")
128-
)
117+
request()
118+
.withMethod("GET")
119+
.withPath("/search/images")
120+
.withQueryStringParameters(
121+
new Parameter("phrase", "cat")
122+
)
123+
.withHeader("Accept-Language", "de")
124+
)
129125
.respond(response().withStatusCode(200).withBody("success"));
130-
131126
}
132127

133128
@Test

src/test/java/DownloadImagesTest.java

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ public static void startProxy() throws Exception {
2828
field.setAccessible(true);
2929
field.set(null, "http://127.0.0.1:1080/");
3030
mockServer = startClientAndServer(1080);
31-
}
32-
33-
@BeforeEach
34-
public void createMock(){
3531
MockServerClient client = new MockServerClient("127.0.0.1", 1080);
3632

3733
client
@@ -44,54 +40,54 @@ public void createMock(){
4440
.withBody("{ access_token: 'client_credentials_access_token', token_type: 'Bearer', expires_in: '1800' }")
4541
);
4642
client.when(
47-
request()
48-
.withMethod("POST")
49-
.withPath("/downloads/images/12345")
50-
.withQueryStringParameters(
51-
new Parameter("auto_download", "false")
52-
)
53-
.withHeader("Accept-Language", "de")
54-
)
43+
request()
44+
.withMethod("POST")
45+
.withPath("/downloads/images/12345")
46+
.withQueryStringParameters(
47+
new Parameter("auto_download", "false")
48+
)
49+
.withHeader("Accept-Language", "de")
50+
)
5551
.respond(response().withStatusCode(200).withBody("success"));
5652
client.when(
57-
request()
58-
.withMethod("POST")
59-
.withPath("/downloads/images/12345")
60-
.withQueryStringParameters(
61-
new Parameter("file_type", "jpg"),
62-
new Parameter("auto_download", "false")
63-
)
64-
)
53+
request()
54+
.withMethod("POST")
55+
.withPath("/downloads/images/12345")
56+
.withQueryStringParameters(
57+
new Parameter("file_type", "jpg"),
58+
new Parameter("auto_download", "false")
59+
)
60+
)
6561
.respond(response().withStatusCode(200).withBody("success"));
6662
client.when(
67-
request()
68-
.withMethod("POST")
69-
.withPath("/downloads/images/12345")
70-
.withQueryStringParameters(
71-
new Parameter("auto_download", "false"),
72-
new Parameter("height", "592")
73-
)
74-
)
63+
request()
64+
.withMethod("POST")
65+
.withPath("/downloads/images/12345")
66+
.withQueryStringParameters(
67+
new Parameter("auto_download", "false"),
68+
new Parameter("height", "592")
69+
)
70+
)
7571
.respond(response().withStatusCode(200).withBody("success"));
7672
client.when(
77-
request()
78-
.withMethod("POST")
79-
.withPath("/downloads/images/12345")
80-
.withQueryStringParameters(
81-
new Parameter("product_id", "9876"),
82-
new Parameter("auto_download", "false")
83-
)
84-
)
73+
request()
74+
.withMethod("POST")
75+
.withPath("/downloads/images/12345")
76+
.withQueryStringParameters(
77+
new Parameter("product_id", "9876"),
78+
new Parameter("auto_download", "false")
79+
)
80+
)
8581
.respond(response().withStatusCode(200).withBody("success"));
8682
client.when(
87-
request()
88-
.withMethod("POST")
89-
.withPath("/downloads/images/12345")
90-
.withQueryStringParameters(
91-
new Parameter("product_type", "easyaccess"),
92-
new Parameter("auto_download", "false")
93-
)
94-
)
83+
request()
84+
.withMethod("POST")
85+
.withPath("/downloads/images/12345")
86+
.withQueryStringParameters(
87+
new Parameter("product_type", "easyaccess"),
88+
new Parameter("auto_download", "false")
89+
)
90+
)
9591
.respond(response().withStatusCode(200).withBody("success"));
9692

9793
}

0 commit comments

Comments
 (0)