-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
BingCustomImageSearchManager.java
92 lines (84 loc) · 3.69 KB
/
BingCustomImageSearchManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
package com.microsoft.azure.cognitiveservices.search.customimagesearch;
import com.microsoft.azure.cognitiveservices.search.customimagesearch.implementation.BingCustomImageSearchAPIImpl;
import com.microsoft.rest.RestClient;
import com.microsoft.rest.credentials.ServiceClientCredentials;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;
/**
* Entry point to Azure Cognitive Services Bing Custom Image Search manager.
*/
public class BingCustomImageSearchManager {
/**
* Initializes an instance of Bing Custom Image Search API client.
*
* @param subscriptionKey the Bing Search API key
* @return the Bing Custom Search API client
*/
public static BingCustomImageSearchAPI authenticate(String subscriptionKey) {
return authenticate("https://api.cognitive.microsoft.com/bingcustomsearch/v7.0/", subscriptionKey);
}
/**
* Initializes an instance of Bing Custom Image Search API client.
*
* @param baseUrl the base URL of the service
* @param subscriptionKey the Bing Search API key
* @return the Bing Custom Search API client
*/
public static BingCustomImageSearchAPI authenticate(String baseUrl, final String subscriptionKey) {
ServiceClientCredentials serviceClientCredentials = new ServiceClientCredentials() {
@Override
public void applyCredentialsFilter(OkHttpClient.Builder builder) {
builder.addNetworkInterceptor(
new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = null;
Request original = chain.request();
// Request customization: add request headers
Request.Builder requestBuilder = original.newBuilder()
.addHeader("Ocp-Apim-Subscription-Key", subscriptionKey);
request = requestBuilder.build();
return chain.proceed(request);
}
});
}
};
return authenticate(baseUrl, serviceClientCredentials);
}
/**
* Initializes an instance of Bing Custom Image Search API client.
*
* @param credentials the management credentials for Azure
* @return the Bing Custom Image Search API client
*/
public static BingCustomImageSearchAPI authenticate(ServiceClientCredentials credentials) {
return authenticate("https://api.cognitive.microsoft.com/bingcustomsearch/v7.0/", credentials);
}
/**
* Initializes an instance of Bing Custom Image Search API client.
*
* @param baseUrl the base URL of the service
* @param credentials the management credentials for Azure
* @return the Bing Custom Image Search API client
*/
public static BingCustomImageSearchAPI authenticate(String baseUrl, ServiceClientCredentials credentials) {
return new BingCustomImageSearchAPIImpl(baseUrl, credentials);
}
/**
* Initializes an instance of Bing Custom Image Search API client.
*
* @param restClient the REST client to connect to Azure.
* @return the Bing Custom Image Search API client
*/
public static BingCustomImageSearchAPI authenticate(RestClient restClient) {
return new BingCustomImageSearchAPIImpl(restClient);
}
}