1 package imagesearch 2 3 // Copyright (c) Microsoft Corporation. All rights reserved. 4 // Licensed under the MIT License. See License.txt in the project root for license information. 5 // 6 // Code generated by Microsoft (R) AutoRest Code Generator. 7 // Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9 import ( 10 "context" 11 "github.com/Azure/go-autorest/autorest" 12 "github.com/Azure/go-autorest/autorest/azure" 13 "github.com/Azure/go-autorest/tracing" 14 "net/http" 15 ) 16 17 // ImagesClient is the the Image Search API lets you send a search query to Bing and get back a list of relevant 18 // images. This section provides technical details about the query parameters and headers that you use to request 19 // images and the JSON response objects that contain them. For examples that show how to make requests, see [Searching 20 // the Web for Images](https://docs.microsoft.com/azure/cognitive-services/bing-image-search/search-the-web). 21 type ImagesClient struct { 22 BaseClient 23 } 24 25 // NewImagesClient creates an instance of the ImagesClient client. 26 func NewImagesClient() ImagesClient { 27 return ImagesClient{New()} 28 } 29 30 // Details sends the details request. 31 // Parameters: 32 // query - the user's search query term. The term cannot be empty. The term may contain [Bing Advanced 33 // Operators](http://msdn.microsoft.com/library/ff795620.aspx). For example, to limit images to a specific 34 // domain, use the [site:](http://msdn.microsoft.com/library/ff795613.aspx) operator. To help improve relevance 35 // of an insights query (see 36 // [insightsToken](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#insightstoken)), 37 // you should always include the user's query term. Use this parameter only with the Image Search API.Do not 38 // specify this parameter when calling the Trending Images API. 39 // acceptLanguage - a comma-delimited list of one or more languages to use for user interface strings. The list 40 // is in decreasing order of preference. For additional information, including expected format, see 41 // [RFC2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). This header and the 42 // [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang) 43 // query parameter are mutually exclusive; do not specify both. If you set this header, you must also specify 44 // the [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) query 45 // parameter. To determine the market to return results for, Bing uses the first supported language it finds 46 // from the list and combines it with the cc parameter value. If the list does not include a supported 47 // language, Bing finds the closest language and market that supports the request or it uses an aggregated or 48 // default market for the results. To determine the market that Bing used, see the BingAPIs-Market header. Use 49 // this header and the cc query parameter only if you specify multiple languages. Otherwise, use the 50 // [mkt](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#mkt) and 51 // [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang) 52 // query parameters. A user interface string is a string that's used as a label in a user interface. There are 53 // few user interface strings in the JSON response objects. Any links to Bing.com properties in the response 54 // objects apply the specified language. 55 // contentType - optional request header. If you set the 56 // [modules](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#modulesrequested) 57 // query parameter to RecognizedEntities, you may specify the binary of an image in the body of a POST request. 58 // If you specify the image in the body of a POST request, you must specify this header and set its value to 59 // multipart/form-data. The maximum image size is 1 MB. 60 // userAgent - the user agent originating the request. Bing uses the user agent to provide mobile users with an 61 // optimized experience. Although optional, you are encouraged to always specify this header. The user-agent 62 // should be the same string that any commonly used browser sends. For information about user agents, see [RFC 63 // 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). The following are examples of user-agent 64 // strings. Windows Phone: Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; 65 // ARM; Touch; NOKIA; Lumia 822). Android: Mozilla / 5.0 (Linux; U; Android 2.3.5; en - us; SCH - I500 Build / 66 // GINGERBREAD) AppleWebKit / 533.1 (KHTML; like Gecko) Version / 4.0 Mobile Safari / 533.1. iPhone: Mozilla / 67 // 5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit / 536.26 (KHTML; like Gecko) Mobile / 10B142 68 // iPhone4; 1 BingWeb / 3.03.1428.20120423. PC: Mozilla / 5.0 (Windows NT 6.3; WOW64; Trident / 7.0; Touch; 69 // rv:11.0) like Gecko. iPad: Mozilla / 5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit / 537.51.1 (KHTML, 70 // like Gecko) Version / 7.0 Mobile / 11A465 Safari / 9537.53 71 // clientID - bing uses this header to provide users with consistent behavior across Bing API calls. Bing often 72 // flights new features and improvements, and it uses the client ID as a key for assigning traffic on different 73 // flights. If you do not use the same client ID for a user across multiple requests, then Bing may assign the 74 // user to multiple conflicting flights. Being assigned to multiple conflicting flights can lead to an 75 // inconsistent user experience. For example, if the second request has a different flight assignment than the 76 // first, the experience may be unexpected. Also, Bing can use the client ID to tailor web results to that 77 // client ID’s search history, providing a richer experience for the user. Bing also uses this header to help 78 // improve result rankings by analyzing the activity generated by a client ID. The relevance improvements help 79 // with better quality of results delivered by Bing APIs and in turn enables higher click-through rates for the 80 // API consumer. IMPORTANT: Although optional, you should consider this header required. Persisting the client 81 // ID across multiple requests for the same end user and device combination enables 1) the API consumer to 82 // receive a consistent user experience, and 2) higher click-through rates via better quality of results from 83 // the Bing APIs. Each user that uses your application on the device must have a unique, Bing generated client 84 // ID. If you do not include this header in the request, Bing generates an ID and returns it in the 85 // X-MSEdge-ClientID response header. The only time that you should NOT include this header in a request is the 86 // first time the user uses your app on that device. Use the client ID for each Bing API request that your app 87 // makes for this user on the device. Persist the client ID. To persist the ID in a browser app, use a 88 // persistent HTTP cookie to ensure the ID is used across all sessions. Do not use a session cookie. For other 89 // apps such as mobile apps, use the device's persistent storage to persist the ID. The next time the user uses 90 // your app on that device, get the client ID that you persisted. Bing responses may or may not include this 91 // header. If the response includes this header, capture the client ID and use it for all subsequent Bing 92 // requests for the user on that device. If you include the X-MSEdge-ClientID, you must not include cookies in 93 // the request. 94 // clientIP - the IPv4 or IPv6 address of the client device. The IP address is used to discover the user's 95 // location. Bing uses the location information to determine safe search behavior. Although optional, you are 96 // encouraged to always specify this header and the X-Search-Location header. Do not obfuscate the address (for 97 // example, by changing the last octet to 0). Obfuscating the address results in the location not being 98 // anywhere near the device's actual location, which may result in Bing serving erroneous results. 99 // location - a semicolon-delimited list of key/value pairs that describe the client's geographical location. 100 // Bing uses the location information to determine safe search behavior and to return relevant local content. 101 // Specify the key/value pair as <key>:<value>. The following are the keys that you use to specify the user's 102 // location. lat (required): The latitude of the client's location, in degrees. The latitude must be greater 103 // than or equal to -90.0 and less than or equal to +90.0. Negative values indicate southern latitudes and 104 // positive values indicate northern latitudes. long (required): The longitude of the client's location, in 105 // degrees. The longitude must be greater than or equal to -180.0 and less than or equal to +180.0. Negative 106 // values indicate western longitudes and positive values indicate eastern longitudes. re (required): The 107 // radius, in meters, which specifies the horizontal accuracy of the coordinates. Pass the value returned by 108 // the device's location service. Typical values might be 22m for GPS/Wi-Fi, 380m for cell tower triangulation, 109 // and 18,000m for reverse IP lookup. ts (optional): The UTC UNIX timestamp of when the client was at the 110 // location. (The UNIX timestamp is the number of seconds since January 1, 1970.) head (optional): The client's 111 // relative heading or direction of travel. Specify the direction of travel as degrees from 0 through 360, 112 // counting clockwise relative to true north. Specify this key only if the sp key is nonzero. sp (optional): 113 // The horizontal velocity (speed), in meters per second, that the client device is traveling. alt (optional): 114 // The altitude of the client device, in meters. are (optional): The radius, in meters, that specifies the 115 // vertical accuracy of the coordinates. Specify this key only if you specify the alt key. Although many of the 116 // keys are optional, the more information that you provide, the more accurate the location results are. 117 // Although optional, you are encouraged to always specify the user's geographical location. Providing the 118 // location is especially important if the client's IP address does not accurately reflect the user's physical 119 // location (for example, if the client uses VPN). For optimal results, you should include this header and the 120 // X-MSEdge-ClientIP header, but at a minimum, you should include this header. 121 // cropBottom - the bottom coordinate of the region to crop. The coordinate is a fractional value of the 122 // original image's height and is measured from the top, left corner of the image. Specify the coordinate as a 123 // value from 0.0 through 1.0. Use this parameter only with the Insights API. Do not specify this parameter 124 // when calling the Images, Trending Images, or Web Search APIs. 125 // cropLeft - the left coordinate of the region to crop. The coordinate is a fractional value of the original 126 // image's height and is measured from the top, left corner of the image. Specify the coordinate as a value 127 // from 0.0 through 1.0. Use this parameter only with the Insights API. Do not specify this parameter when 128 // calling the Images, Trending Images, or Web Search APIs. 129 // cropRight - the right coordinate of the region to crop. The coordinate is a fractional value of the original 130 // image's height and is measured from the top, left corner of the image. Specify the coordinate as a value 131 // from 0.0 through 1.0. Use this parameter only with the Insights API. Do not specify this parameter when 132 // calling the Images, Trending Images, or Web Search APIs. 133 // cropTop - the top coordinate of the region to crop. The coordinate is a fractional value of the original 134 // image's height and is measured from the top, left corner of the image. Specify the coordinate as a value 135 // from 0.0 through 1.0. Use this parameter only with the Insights API. Do not specify this parameter when 136 // calling the Images, Trending Images, or Web Search APIs. 137 // cropType - the crop type to use when cropping the image based on the coordinates specified in the cal, cat, 138 // car, and cab parameters. The following are the possible values. 0: Rectangular (default). Use this parameter 139 // only with the Insights API. Do not specify this parameter when calling the Images, Trending Images, or Web 140 // Search APIs. 141 // countryCode - a 2-character country code of the country where the results come from. For a list of possible 142 // values, see [Market 143 // Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes). 144 // If you set this parameter, you must also specify the 145 // [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#acceptlanguage) 146 // header. Bing uses the first supported language it finds from the languages list, and combine that language 147 // with the country code that you specify to determine the market to return results for. If the languages list 148 // does not include a supported language, Bing finds the closest language and market that supports the request, 149 // or it may use an aggregated or default market for the results instead of a specified one. You should use 150 // this query parameter and the Accept-Language query parameter only if you specify multiple languages; 151 // otherwise, you should use the mkt and setLang query parameters. This parameter and the 152 // [mkt](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#mkt) query 153 // parameter are mutually exclusive—do not specify both. 154 // ID - an ID that uniquely identifies an image. Use this parameter to ensure that the specified image is the 155 // first image in the list of images that Bing returns. The 156 // [Image](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#image) 157 // object's imageId field contains the ID that you set this parameter to. 158 // imageURL - the URL of an image that you want to get insights of. Use this parameter as an alternative to 159 // using the insightsToken parameter to specify the image. You may also specify the image by placing the binary 160 // of the image in the body of a POST request. If you use the binary option, see the 161 // [Content-Type](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#contenttype) 162 // header. The maximum supported image size is 1 MB. Use this parameter only with the Insights API. Do not 163 // specify this parameter when calling the Images, Trending Images, or Web Search APIs. 164 // insightsToken - an image token. The 165 // [Image](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#image) 166 // object's 167 // [imageInsightsToken](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#image-imageinsightstoken) 168 // contains the token. Specify this parameter to get additional information about an image, such as a caption 169 // or shopping source. For a list of the additional information about an image that you can get, see the 170 // [modules](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#modulesrequested) 171 // query parameter. Use this parameter only with the Insights API. Do not specify this parameter when calling 172 // the Images, Trending Images, or Web Search APIs. 173 // modules - a comma-delimited list of insights to request. The following are the possible case-insensitive 174 // values. All: Return all insights, if available, except RecognizedEntities. BRQ: Best representative query. 175 // The query term that best describes the image. Caption: A caption that provides information about the image. 176 // If the caption contains entities, the response may include links to images of those entities. Collections: A 177 // list of related images. Recipes: A list of recipes for cooking the food shown in the images. PagesIncluding: 178 // A list of webpages that include the image. RecognizedEntities: A list of entities (people) that were 179 // recognized in the image. NOTE: You may not specify this module with any other module. If you specify it with 180 // other modules, the response doesn't include recognized entities. RelatedSearches: A list of related searches 181 // made by others. ShoppingSources: A list of merchants where you can buy related offerings. SimilarImages: A 182 // list of images that are visually similar to the original image. SimilarProducts: A list of images that 183 // contain a product that is similar to a product found in the original image. Tags: Provides characteristics 184 // of the type of content found in the image. For example, if the image is of a person, the tags might indicate 185 // the person's gender and type of clothes they're wearing. If you specify a module and there is no data for 186 // the module, the response object doesn't include the related field. For example, if you specify Caption and 187 // it does not exist, the response doesn't include the imageCaption field. To include related searches, the 188 // request must include the original query string. Although the original query string is not required for 189 // similar images or products, you should always include it because it can help improve relevance and the 190 // results. Use this parameter only with the Insights API. Do not specify this parameter when calling the 191 // Images, Trending Images, or Web Search APIs. 192 // market - the market where the results come from. Typically, mkt is the country where the user is making the 193 // request from. However, it could be a different country if the user is not located in a country where Bing 194 // delivers results. The market must be in the form <language code>-<country code>. For example, en-US. The 195 // string is case insensitive. For a list of possible market values, see [Market 196 // Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes). 197 // NOTE: If known, you are encouraged to always specify the market. Specifying the market helps Bing route the 198 // request and return an appropriate and optimal response. If you specify a market that is not listed in 199 // [Market 200 // Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes), 201 // Bing uses a best fit market code based on an internal mapping that is subject to change. This parameter and 202 // the [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) query 203 // parameter are mutually exclusive—do not specify both. 204 // safeSearch - filter images for adult content. The following are the possible filter values. Off: May return 205 // images with adult content. If the request is through the Image Search API, the response includes thumbnail 206 // images that are clear (non-fuzzy). However, if the request is through the Web Search API, the response 207 // includes thumbnail images that are pixelated (fuzzy). Moderate: If the request is through the Image Search 208 // API, the response doesn't include images with adult content. If the request is through the Web Search API, 209 // the response may include images with adult content (the thumbnail images are pixelated (fuzzy)). Strict: Do 210 // not return images with adult content. The default is Moderate. If the request comes from a market that 211 // Bing's adult policy requires that safeSearch is set to Strict, Bing ignores the safeSearch value and uses 212 // Strict. If you use the site: query operator, there is the chance that the response may contain adult content 213 // regardless of what the safeSearch query parameter is set to. Use site: only if you are aware of the content 214 // on the site and your scenario supports the possibility of adult content. 215 // setLang - the language to use for user interface strings. Specify the language using the ISO 639-1 2-letter 216 // language code. For example, the language code for English is EN. The default is EN (English). Although 217 // optional, you should always specify the language. Typically, you set setLang to the same language specified 218 // by mkt unless the user wants the user interface strings displayed in a different language. This parameter 219 // and the 220 // [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#acceptlanguage) 221 // header are mutually exclusive; do not specify both. A user interface string is a string that's used as a 222 // label in a user interface. There are few user interface strings in the JSON response objects. Also, any 223 // links to Bing.com properties in the response objects apply the specified language. 224 func (client ImagesClient) Details(ctx context.Context, query string, acceptLanguage string, contentType string, userAgent string, clientID string, clientIP string, location string, cropBottom *float64, cropLeft *float64, cropRight *float64, cropTop *float64, cropType ImageCropType, countryCode string, ID string, imageURL string, insightsToken string, modules []ImageInsightModule, market string, safeSearch SafeSearch, setLang string) (result ImageInsights, err error) { 225 if tracing.IsEnabled() { 226 ctx = tracing.StartSpan(ctx, fqdn+"/ImagesClient.Details") 227 defer func() { 228 sc := -1 229 if result.Response.Response != nil { 230 sc = result.Response.Response.StatusCode 231 } 232 tracing.EndSpan(ctx, sc, err) 233 }() 234 } 235 req, err := client.DetailsPreparer(ctx, query, acceptLanguage, contentType, userAgent, clientID, clientIP, location, cropBottom, cropLeft, cropRight, cropTop, cropType, countryCode, ID, imageURL, insightsToken, modules, market, safeSearch, setLang) 236 if err != nil { 237 err = autorest.NewErrorWithError(err, "imagesearch.ImagesClient", "Details", nil, "Failure preparing request") 238 return 239 } 240 241 resp, err := client.DetailsSender(req) 242 if err != nil { 243 result.Response = autorest.Response{Response: resp} 244 err = autorest.NewErrorWithError(err, "imagesearch.ImagesClient", "Details", resp, "Failure sending request") 245 return 246 } 247 248 result, err = client.DetailsResponder(resp) 249 if err != nil { 250 err = autorest.NewErrorWithError(err, "imagesearch.ImagesClient", "Details", resp, "Failure responding to request") 251 return 252 } 253 254 return 255 } 256 257 // DetailsPreparer prepares the Details request. 258 func (client ImagesClient) DetailsPreparer(ctx context.Context, query string, acceptLanguage string, contentType string, userAgent string, clientID string, clientIP string, location string, cropBottom *float64, cropLeft *float64, cropRight *float64, cropTop *float64, cropType ImageCropType, countryCode string, ID string, imageURL string, insightsToken string, modules []ImageInsightModule, market string, safeSearch SafeSearch, setLang string) (*http.Request, error) { 259 urlParameters := map[string]interface{}{ 260 "Endpoint": client.Endpoint, 261 } 262 263 queryParameters := map[string]interface{}{ 264 "q": autorest.Encode("query", query), 265 } 266 if cropBottom != nil { 267 queryParameters["cab"] = autorest.Encode("query", *cropBottom) 268 } 269 if cropLeft != nil { 270 queryParameters["cal"] = autorest.Encode("query", *cropLeft) 271 } 272 if cropRight != nil { 273 queryParameters["car"] = autorest.Encode("query", *cropRight) 274 } 275 if cropTop != nil { 276 queryParameters["cat"] = autorest.Encode("query", *cropTop) 277 } 278 if len(string(cropType)) > 0 { 279 queryParameters["ct"] = autorest.Encode("query", cropType) 280 } 281 if len(countryCode) > 0 { 282 queryParameters["cc"] = autorest.Encode("query", countryCode) 283 } 284 if len(ID) > 0 { 285 queryParameters["id"] = autorest.Encode("query", ID) 286 } 287 if len(imageURL) > 0 { 288 queryParameters["imgUrl"] = autorest.Encode("query", imageURL) 289 } 290 if len(insightsToken) > 0 { 291 queryParameters["insightsToken"] = autorest.Encode("query", insightsToken) 292 } 293 if modules != nil && len(modules) > 0 { 294 queryParameters["modules"] = autorest.Encode("query", modules, ",") 295 } 296 if len(market) > 0 { 297 queryParameters["mkt"] = autorest.Encode("query", market) 298 } 299 if len(string(safeSearch)) > 0 { 300 queryParameters["safeSearch"] = autorest.Encode("query", safeSearch) 301 } 302 if len(setLang) > 0 { 303 queryParameters["setLang"] = autorest.Encode("query", setLang) 304 } 305 306 preparer := autorest.CreatePreparer( 307 autorest.AsGet(), 308 autorest.WithCustomBaseURL("{Endpoint}/bing/v7.0", urlParameters), 309 autorest.WithPath("/images/details"), 310 autorest.WithQueryParameters(queryParameters), 311 autorest.WithHeader("X-BingApis-SDK", "true")) 312 if len(acceptLanguage) > 0 { 313 preparer = autorest.DecoratePreparer(preparer, 314 autorest.WithHeader("Accept-Language", autorest.String(acceptLanguage))) 315 } 316 if len(contentType) > 0 { 317 preparer = autorest.DecoratePreparer(preparer, 318 autorest.WithHeader("Content-Type", autorest.String(contentType))) 319 } 320 if len(userAgent) > 0 { 321 preparer = autorest.DecoratePreparer(preparer, 322 autorest.WithHeader("User-Agent", autorest.String(userAgent))) 323 } 324 if len(clientID) > 0 { 325 preparer = autorest.DecoratePreparer(preparer, 326 autorest.WithHeader("X-MSEdge-ClientID", autorest.String(clientID))) 327 } 328 if len(clientIP) > 0 { 329 preparer = autorest.DecoratePreparer(preparer, 330 autorest.WithHeader("X-MSEdge-ClientIP", autorest.String(clientIP))) 331 } 332 if len(location) > 0 { 333 preparer = autorest.DecoratePreparer(preparer, 334 autorest.WithHeader("X-Search-Location", autorest.String(location))) 335 } 336 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 337 } 338 339 // DetailsSender sends the Details request. The method will close the 340 // http.Response Body if it receives an error. 341 func (client ImagesClient) DetailsSender(req *http.Request) (*http.Response, error) { 342 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 343 } 344 345 // DetailsResponder handles the response to the Details request. The method always 346 // closes the http.Response Body. 347 func (client ImagesClient) DetailsResponder(resp *http.Response) (result ImageInsights, err error) { 348 err = autorest.Respond( 349 resp, 350 azure.WithErrorUnlessStatusCode(http.StatusOK), 351 autorest.ByUnmarshallingJSON(&result), 352 autorest.ByClosing()) 353 result.Response = autorest.Response{Response: resp} 354 return 355 } 356 357 // Search sends the search request. 358 // Parameters: 359 // query - the user's search query term. The term cannot be empty. The term may contain [Bing Advanced 360 // Operators](http://msdn.microsoft.com/library/ff795620.aspx). For example, to limit images to a specific 361 // domain, use the [site:](http://msdn.microsoft.com/library/ff795613.aspx) operator. To help improve relevance 362 // of an insights query (see 363 // [insightsToken](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#insightstoken)), 364 // you should always include the user's query term. Use this parameter only with the Image Search API.Do not 365 // specify this parameter when calling the Trending Images API. 366 // acceptLanguage - a comma-delimited list of one or more languages to use for user interface strings. The list 367 // is in decreasing order of preference. For additional information, including expected format, see 368 // [RFC2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). This header and the 369 // [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang) 370 // query parameter are mutually exclusive; do not specify both. If you set this header, you must also specify 371 // the [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) query 372 // parameter. To determine the market to return results for, Bing uses the first supported language it finds 373 // from the list and combines it with the cc parameter value. If the list does not include a supported 374 // language, Bing finds the closest language and market that supports the request or it uses an aggregated or 375 // default market for the results. To determine the market that Bing used, see the BingAPIs-Market header. Use 376 // this header and the cc query parameter only if you specify multiple languages. Otherwise, use the 377 // [mkt](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#mkt) and 378 // [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang) 379 // query parameters. A user interface string is a string that's used as a label in a user interface. There are 380 // few user interface strings in the JSON response objects. Any links to Bing.com properties in the response 381 // objects apply the specified language. 382 // userAgent - the user agent originating the request. Bing uses the user agent to provide mobile users with an 383 // optimized experience. Although optional, you are encouraged to always specify this header. The user-agent 384 // should be the same string that any commonly used browser sends. For information about user agents, see [RFC 385 // 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). The following are examples of user-agent 386 // strings. Windows Phone: Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; 387 // ARM; Touch; NOKIA; Lumia 822). Android: Mozilla / 5.0 (Linux; U; Android 2.3.5; en - us; SCH - I500 Build / 388 // GINGERBREAD) AppleWebKit / 533.1 (KHTML; like Gecko) Version / 4.0 Mobile Safari / 533.1. iPhone: Mozilla / 389 // 5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit / 536.26 (KHTML; like Gecko) Mobile / 10B142 390 // iPhone4; 1 BingWeb / 3.03.1428.20120423. PC: Mozilla / 5.0 (Windows NT 6.3; WOW64; Trident / 7.0; Touch; 391 // rv:11.0) like Gecko. iPad: Mozilla / 5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit / 537.51.1 (KHTML, 392 // like Gecko) Version / 7.0 Mobile / 11A465 Safari / 9537.53 393 // clientID - bing uses this header to provide users with consistent behavior across Bing API calls. Bing often 394 // flights new features and improvements, and it uses the client ID as a key for assigning traffic on different 395 // flights. If you do not use the same client ID for a user across multiple requests, then Bing may assign the 396 // user to multiple conflicting flights. Being assigned to multiple conflicting flights can lead to an 397 // inconsistent user experience. For example, if the second request has a different flight assignment than the 398 // first, the experience may be unexpected. Also, Bing can use the client ID to tailor web results to that 399 // client ID’s search history, providing a richer experience for the user. Bing also uses this header to help 400 // improve result rankings by analyzing the activity generated by a client ID. The relevance improvements help 401 // with better quality of results delivered by Bing APIs and in turn enables higher click-through rates for the 402 // API consumer. IMPORTANT: Although optional, you should consider this header required. Persisting the client 403 // ID across multiple requests for the same end user and device combination enables 1) the API consumer to 404 // receive a consistent user experience, and 2) higher click-through rates via better quality of results from 405 // the Bing APIs. Each user that uses your application on the device must have a unique, Bing generated client 406 // ID. If you do not include this header in the request, Bing generates an ID and returns it in the 407 // X-MSEdge-ClientID response header. The only time that you should NOT include this header in a request is the 408 // first time the user uses your app on that device. Use the client ID for each Bing API request that your app 409 // makes for this user on the device. Persist the client ID. To persist the ID in a browser app, use a 410 // persistent HTTP cookie to ensure the ID is used across all sessions. Do not use a session cookie. For other 411 // apps such as mobile apps, use the device's persistent storage to persist the ID. The next time the user uses 412 // your app on that device, get the client ID that you persisted. Bing responses may or may not include this 413 // header. If the response includes this header, capture the client ID and use it for all subsequent Bing 414 // requests for the user on that device. If you include the X-MSEdge-ClientID, you must not include cookies in 415 // the request. 416 // clientIP - the IPv4 or IPv6 address of the client device. The IP address is used to discover the user's 417 // location. Bing uses the location information to determine safe search behavior. Although optional, you are 418 // encouraged to always specify this header and the X-Search-Location header. Do not obfuscate the address (for 419 // example, by changing the last octet to 0). Obfuscating the address results in the location not being 420 // anywhere near the device's actual location, which may result in Bing serving erroneous results. 421 // location - a semicolon-delimited list of key/value pairs that describe the client's geographical location. 422 // Bing uses the location information to determine safe search behavior and to return relevant local content. 423 // Specify the key/value pair as <key>:<value>. The following are the keys that you use to specify the user's 424 // location. lat (required): The latitude of the client's location, in degrees. The latitude must be greater 425 // than or equal to -90.0 and less than or equal to +90.0. Negative values indicate southern latitudes and 426 // positive values indicate northern latitudes. long (required): The longitude of the client's location, in 427 // degrees. The longitude must be greater than or equal to -180.0 and less than or equal to +180.0. Negative 428 // values indicate western longitudes and positive values indicate eastern longitudes. re (required): The 429 // radius, in meters, which specifies the horizontal accuracy of the coordinates. Pass the value returned by 430 // the device's location service. Typical values might be 22m for GPS/Wi-Fi, 380m for cell tower triangulation, 431 // and 18,000m for reverse IP lookup. ts (optional): The UTC UNIX timestamp of when the client was at the 432 // location. (The UNIX timestamp is the number of seconds since January 1, 1970.) head (optional): The client's 433 // relative heading or direction of travel. Specify the direction of travel as degrees from 0 through 360, 434 // counting clockwise relative to true north. Specify this key only if the sp key is nonzero. sp (optional): 435 // The horizontal velocity (speed), in meters per second, that the client device is traveling. alt (optional): 436 // The altitude of the client device, in meters. are (optional): The radius, in meters, that specifies the 437 // vertical accuracy of the coordinates. Specify this key only if you specify the alt key. Although many of the 438 // keys are optional, the more information that you provide, the more accurate the location results are. 439 // Although optional, you are encouraged to always specify the user's geographical location. Providing the 440 // location is especially important if the client's IP address does not accurately reflect the user's physical 441 // location (for example, if the client uses VPN). For optimal results, you should include this header and the 442 // X-MSEdge-ClientIP header, but at a minimum, you should include this header. 443 // aspect - filter images by the following aspect ratios. All: Do not filter by aspect.Specifying this value is 444 // the same as not specifying the aspect parameter. Square: Return images with standard aspect ratio. Wide: 445 // Return images with wide screen aspect ratio. Tall: Return images with tall aspect ratio. 446 // colorParameter - filter images by the following color options. ColorOnly: Return color images. Monochrome: 447 // Return black and white images. Return images with one of the following dominant colors: Black, Blue, Brown, 448 // Gray, Green, Orange, Pink, Purple, Red, Teal, White, Yellow 449 // countryCode - a 2-character country code of the country where the results come from. For a list of possible 450 // values, see [Market 451 // Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes). 452 // If you set this parameter, you must also specify the 453 // [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#acceptlanguage) 454 // header. Bing uses the first supported language it finds from the languages list, and combine that language 455 // with the country code that you specify to determine the market to return results for. If the languages list 456 // does not include a supported language, Bing finds the closest language and market that supports the request, 457 // or it may use an aggregated or default market for the results instead of a specified one. You should use 458 // this query parameter and the Accept-Language query parameter only if you specify multiple languages; 459 // otherwise, you should use the mkt and setLang query parameters. This parameter and the 460 // [mkt](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#mkt) query 461 // parameter are mutually exclusive—do not specify both. 462 // count - the number of images to return in the response. The actual number delivered may be less than 463 // requested. The default is 35. The maximum value is 150. You use this parameter along with the offset 464 // parameter to page results.For example, if your user interface displays 20 images per page, set count to 20 465 // and offset to 0 to get the first page of results.For each subsequent page, increment offset by 20 (for 466 // example, 0, 20, 40). Use this parameter only with the Image Search API.Do not specify this parameter when 467 // calling the Insights, Trending Images, or Web Search APIs. 468 // freshness - filter images by the following discovery options. Day: Return images discovered by Bing within 469 // the last 24 hours. Week: Return images discovered by Bing within the last 7 days. Month: Return images 470 // discovered by Bing within the last 30 days. 471 // height - filter images that have the specified height, in pixels. You may use this filter with the size 472 // filter to return small images that have a height of 150 pixels. 473 // ID - an ID that uniquely identifies an image. Use this parameter to ensure that the specified image is the 474 // first image in the list of images that Bing returns. The 475 // [Image](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#image) 476 // object's imageId field contains the ID that you set this parameter to. 477 // imageContent - filter images by the following content types. Face: Return images that show only a person's 478 // face. Portrait: Return images that show only a person's head and shoulders. 479 // imageType - filter images by the following image types. AnimatedGif: Return only animated GIFs. Clipart: 480 // Return only clip art images. Line: Return only line drawings. Photo: Return only photographs(excluding line 481 // drawings, animated Gifs, and clip art). Shopping: Return only images that contain items where Bing knows of 482 // a merchant that is selling the items. This option is valid in the en - US market only.Transparent: Return 483 // only images with a transparent background. 484 // license - filter images by the following license types. All: Do not filter by license type.Specifying this 485 // value is the same as not specifying the license parameter. Any: Return images that are under any license 486 // type. The response doesn't include images that do not specify a license or the license is unknown. Public: 487 // Return images where the creator has waived their exclusive rights, to the fullest extent allowed by law. 488 // Share: Return images that may be shared with others. Changing or editing the image might not be allowed. 489 // Also, modifying, sharing, and using the image for commercial purposes might not be allowed. Typically, this 490 // option returns the most images. ShareCommercially: Return images that may be shared with others for personal 491 // or commercial purposes. Changing or editing the image might not be allowed. Modify: Return images that may 492 // be modified, shared, and used. Changing or editing the image might not be allowed. Modifying, sharing, and 493 // using the image for commercial purposes might not be allowed. ModifyCommercially: Return images that may be 494 // modified, shared, and used for personal or commercial purposes. Typically, this option returns the fewest 495 // images. For more information about these license types, see [Filter Images By License 496 // Type](http://go.microsoft.com/fwlink/?LinkId=309768). 497 // market - the market where the results come from. Typically, mkt is the country where the user is making the 498 // request from. However, it could be a different country if the user is not located in a country where Bing 499 // delivers results. The market must be in the form <language code>-<country code>. For example, en-US. The 500 // string is case insensitive. For a list of possible market values, see [Market 501 // Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes). 502 // NOTE: If known, you are encouraged to always specify the market. Specifying the market helps Bing route the 503 // request and return an appropriate and optimal response. If you specify a market that is not listed in 504 // [Market 505 // Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes), 506 // Bing uses a best fit market code based on an internal mapping that is subject to change. This parameter and 507 // the [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) query 508 // parameter are mutually exclusive—do not specify both. 509 // maxFileSize - filter images that are less than or equal to the specified file size. The maximum file size 510 // that you may specify is 520,192 bytes. If you specify a larger value, the API uses 520,192. It is possible 511 // that the response may include images that are slightly larger than the specified maximum. You may specify 512 // this filter and minFileSize to filter images within a range of file sizes. 513 // maxHeight - filter images that have a height that is less than or equal to the specified height. Specify the 514 // height in pixels. You may specify this filter and minHeight to filter images within a range of heights. This 515 // filter and the height filter are mutually exclusive. 516 // maxWidth - filter images that have a width that is less than or equal to the specified width. Specify the 517 // width in pixels. You may specify this filter and maxWidth to filter images within a range of widths. This 518 // filter and the width filter are mutually exclusive. 519 // minFileSize - filter images that are greater than or equal to the specified file size. The maximum file size 520 // that you may specify is 520,192 bytes. If you specify a larger value, the API uses 520,192. It is possible 521 // that the response may include images that are slightly smaller than the specified minimum. You may specify 522 // this filter and maxFileSize to filter images within a range of file sizes. 523 // minHeight - filter images that have a height that is greater than or equal to the specified height. Specify 524 // the height in pixels. You may specify this filter and maxHeight to filter images within a range of heights. 525 // This filter and the height filter are mutually exclusive. 526 // minWidth - filter images that have a width that is greater than or equal to the specified width. Specify the 527 // width in pixels. You may specify this filter and maxWidth to filter images within a range of widths. This 528 // filter and the width filter are mutually exclusive. 529 // offset - the zero-based offset that indicates the number of images to skip before returning images. The 530 // default is 0. The offset should be less than 531 // ([totalEstimatedMatches](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#totalestimatedmatches) 532 // - count). Use this parameter along with the count parameter to page results. For example, if your user 533 // interface displays 20 images per page, set count to 20 and offset to 0 to get the first page of results. For 534 // each subsequent page, increment offset by 20 (for example, 0, 20, 40). It is possible for multiple pages to 535 // include some overlap in results. To prevent duplicates, see 536 // [nextOffset](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#nextoffset). 537 // Use this parameter only with the Image API. Do not specify this parameter when calling the Trending Images 538 // API or the Web Search API. 539 // safeSearch - filter images for adult content. The following are the possible filter values. Off: May return 540 // images with adult content. If the request is through the Image Search API, the response includes thumbnail 541 // images that are clear (non-fuzzy). However, if the request is through the Web Search API, the response 542 // includes thumbnail images that are pixelated (fuzzy). Moderate: If the request is through the Image Search 543 // API, the response doesn't include images with adult content. If the request is through the Web Search API, 544 // the response may include images with adult content (the thumbnail images are pixelated (fuzzy)). Strict: Do 545 // not return images with adult content. The default is Moderate. If the request comes from a market that 546 // Bing's adult policy requires that safeSearch is set to Strict, Bing ignores the safeSearch value and uses 547 // Strict. If you use the site: query operator, there is the chance that the response may contain adult content 548 // regardless of what the safeSearch query parameter is set to. Use site: only if you are aware of the content 549 // on the site and your scenario supports the possibility of adult content. 550 // size - filter images by the following sizes. All: Do not filter by size. Specifying this value is the same 551 // as not specifying the size parameter. Small: Return images that are less than 200x200 pixels. Medium: Return 552 // images that are greater than or equal to 200x200 pixels but less than 500x500 pixels. Large: Return images 553 // that are 500x500 pixels or larger. Wallpaper: Return wallpaper images. You may use this parameter along with 554 // the height or width parameters. For example, you may use height and size to request small images that are 555 // 150 pixels tall. 556 // setLang - the language to use for user interface strings. Specify the language using the ISO 639-1 2-letter 557 // language code. For example, the language code for English is EN. The default is EN (English). Although 558 // optional, you should always specify the language. Typically, you set setLang to the same language specified 559 // by mkt unless the user wants the user interface strings displayed in a different language. This parameter 560 // and the 561 // [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#acceptlanguage) 562 // header are mutually exclusive; do not specify both. A user interface string is a string that's used as a 563 // label in a user interface. There are few user interface strings in the JSON response objects. Also, any 564 // links to Bing.com properties in the response objects apply the specified language. 565 // width - filter images that have the specified width, in pixels. You may use this filter with the size filter 566 // to return small images that have a width of 150 pixels. 567 func (client ImagesClient) Search(ctx context.Context, query string, acceptLanguage string, userAgent string, clientID string, clientIP string, location string, aspect ImageAspect, colorParameter ImageColor, countryCode string, count *int32, freshness Freshness, height *int32, ID string, imageContent ImageContent, imageType ImageType, license ImageLicense, market string, maxFileSize *int64, maxHeight *int64, maxWidth *int64, minFileSize *int64, minHeight *int64, minWidth *int64, offset *int64, safeSearch SafeSearch, size ImageSize, setLang string, width *int32) (result Images, err error) { 568 if tracing.IsEnabled() { 569 ctx = tracing.StartSpan(ctx, fqdn+"/ImagesClient.Search") 570 defer func() { 571 sc := -1 572 if result.Response.Response != nil { 573 sc = result.Response.Response.StatusCode 574 } 575 tracing.EndSpan(ctx, sc, err) 576 }() 577 } 578 req, err := client.SearchPreparer(ctx, query, acceptLanguage, userAgent, clientID, clientIP, location, aspect, colorParameter, countryCode, count, freshness, height, ID, imageContent, imageType, license, market, maxFileSize, maxHeight, maxWidth, minFileSize, minHeight, minWidth, offset, safeSearch, size, setLang, width) 579 if err != nil { 580 err = autorest.NewErrorWithError(err, "imagesearch.ImagesClient", "Search", nil, "Failure preparing request") 581 return 582 } 583 584 resp, err := client.SearchSender(req) 585 if err != nil { 586 result.Response = autorest.Response{Response: resp} 587 err = autorest.NewErrorWithError(err, "imagesearch.ImagesClient", "Search", resp, "Failure sending request") 588 return 589 } 590 591 result, err = client.SearchResponder(resp) 592 if err != nil { 593 err = autorest.NewErrorWithError(err, "imagesearch.ImagesClient", "Search", resp, "Failure responding to request") 594 return 595 } 596 597 return 598 } 599 600 // SearchPreparer prepares the Search request. 601 func (client ImagesClient) SearchPreparer(ctx context.Context, query string, acceptLanguage string, userAgent string, clientID string, clientIP string, location string, aspect ImageAspect, colorParameter ImageColor, countryCode string, count *int32, freshness Freshness, height *int32, ID string, imageContent ImageContent, imageType ImageType, license ImageLicense, market string, maxFileSize *int64, maxHeight *int64, maxWidth *int64, minFileSize *int64, minHeight *int64, minWidth *int64, offset *int64, safeSearch SafeSearch, size ImageSize, setLang string, width *int32) (*http.Request, error) { 602 urlParameters := map[string]interface{}{ 603 "Endpoint": client.Endpoint, 604 } 605 606 queryParameters := map[string]interface{}{ 607 "q": autorest.Encode("query", query), 608 } 609 if len(string(aspect)) > 0 { 610 queryParameters["aspect"] = autorest.Encode("query", aspect) 611 } 612 if len(string(colorParameter)) > 0 { 613 queryParameters["color"] = autorest.Encode("query", colorParameter) 614 } 615 if len(countryCode) > 0 { 616 queryParameters["cc"] = autorest.Encode("query", countryCode) 617 } 618 if count != nil { 619 queryParameters["count"] = autorest.Encode("query", *count) 620 } 621 if len(string(freshness)) > 0 { 622 queryParameters["freshness"] = autorest.Encode("query", freshness) 623 } 624 if height != nil { 625 queryParameters["height"] = autorest.Encode("query", *height) 626 } 627 if len(ID) > 0 { 628 queryParameters["id"] = autorest.Encode("query", ID) 629 } 630 if len(string(imageContent)) > 0 { 631 queryParameters["imageContent"] = autorest.Encode("query", imageContent) 632 } 633 if len(string(imageType)) > 0 { 634 queryParameters["imageType"] = autorest.Encode("query", imageType) 635 } 636 if len(string(license)) > 0 { 637 queryParameters["license"] = autorest.Encode("query", license) 638 } 639 if len(market) > 0 { 640 queryParameters["mkt"] = autorest.Encode("query", market) 641 } 642 if maxFileSize != nil { 643 queryParameters["maxFileSize"] = autorest.Encode("query", *maxFileSize) 644 } 645 if maxHeight != nil { 646 queryParameters["maxHeight"] = autorest.Encode("query", *maxHeight) 647 } 648 if maxWidth != nil { 649 queryParameters["maxWidth"] = autorest.Encode("query", *maxWidth) 650 } 651 if minFileSize != nil { 652 queryParameters["minFileSize"] = autorest.Encode("query", *minFileSize) 653 } 654 if minHeight != nil { 655 queryParameters["minHeight"] = autorest.Encode("query", *minHeight) 656 } 657 if minWidth != nil { 658 queryParameters["minWidth"] = autorest.Encode("query", *minWidth) 659 } 660 if offset != nil { 661 queryParameters["offset"] = autorest.Encode("query", *offset) 662 } 663 if len(string(safeSearch)) > 0 { 664 queryParameters["safeSearch"] = autorest.Encode("query", safeSearch) 665 } 666 if len(string(size)) > 0 { 667 queryParameters["size"] = autorest.Encode("query", size) 668 } 669 if len(setLang) > 0 { 670 queryParameters["setLang"] = autorest.Encode("query", setLang) 671 } 672 if width != nil { 673 queryParameters["width"] = autorest.Encode("query", *width) 674 } 675 676 preparer := autorest.CreatePreparer( 677 autorest.AsGet(), 678 autorest.WithCustomBaseURL("{Endpoint}/bing/v7.0", urlParameters), 679 autorest.WithPath("/images/search"), 680 autorest.WithQueryParameters(queryParameters), 681 autorest.WithHeader("X-BingApis-SDK", "true")) 682 if len(acceptLanguage) > 0 { 683 preparer = autorest.DecoratePreparer(preparer, 684 autorest.WithHeader("Accept-Language", autorest.String(acceptLanguage))) 685 } 686 if len(userAgent) > 0 { 687 preparer = autorest.DecoratePreparer(preparer, 688 autorest.WithHeader("User-Agent", autorest.String(userAgent))) 689 } 690 if len(clientID) > 0 { 691 preparer = autorest.DecoratePreparer(preparer, 692 autorest.WithHeader("X-MSEdge-ClientID", autorest.String(clientID))) 693 } 694 if len(clientIP) > 0 { 695 preparer = autorest.DecoratePreparer(preparer, 696 autorest.WithHeader("X-MSEdge-ClientIP", autorest.String(clientIP))) 697 } 698 if len(location) > 0 { 699 preparer = autorest.DecoratePreparer(preparer, 700 autorest.WithHeader("X-Search-Location", autorest.String(location))) 701 } 702 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 703 } 704 705 // SearchSender sends the Search request. The method will close the 706 // http.Response Body if it receives an error. 707 func (client ImagesClient) SearchSender(req *http.Request) (*http.Response, error) { 708 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 709 } 710 711 // SearchResponder handles the response to the Search request. The method always 712 // closes the http.Response Body. 713 func (client ImagesClient) SearchResponder(resp *http.Response) (result Images, err error) { 714 err = autorest.Respond( 715 resp, 716 azure.WithErrorUnlessStatusCode(http.StatusOK), 717 autorest.ByUnmarshallingJSON(&result), 718 autorest.ByClosing()) 719 result.Response = autorest.Response{Response: resp} 720 return 721 } 722 723 // Trending sends the trending request. 724 // Parameters: 725 // acceptLanguage - a comma-delimited list of one or more languages to use for user interface strings. The list 726 // is in decreasing order of preference. For additional information, including expected format, see 727 // [RFC2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). This header and the 728 // [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang) 729 // query parameter are mutually exclusive; do not specify both. If you set this header, you must also specify 730 // the [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) query 731 // parameter. To determine the market to return results for, Bing uses the first supported language it finds 732 // from the list and combines it with the cc parameter value. If the list does not include a supported 733 // language, Bing finds the closest language and market that supports the request or it uses an aggregated or 734 // default market for the results. To determine the market that Bing used, see the BingAPIs-Market header. Use 735 // this header and the cc query parameter only if you specify multiple languages. Otherwise, use the 736 // [mkt](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#mkt) and 737 // [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang) 738 // query parameters. A user interface string is a string that's used as a label in a user interface. There are 739 // few user interface strings in the JSON response objects. Any links to Bing.com properties in the response 740 // objects apply the specified language. 741 // userAgent - the user agent originating the request. Bing uses the user agent to provide mobile users with an 742 // optimized experience. Although optional, you are encouraged to always specify this header. The user-agent 743 // should be the same string that any commonly used browser sends. For information about user agents, see [RFC 744 // 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). The following are examples of user-agent 745 // strings. Windows Phone: Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; 746 // ARM; Touch; NOKIA; Lumia 822). Android: Mozilla / 5.0 (Linux; U; Android 2.3.5; en - us; SCH - I500 Build / 747 // GINGERBREAD) AppleWebKit / 533.1 (KHTML; like Gecko) Version / 4.0 Mobile Safari / 533.1. iPhone: Mozilla / 748 // 5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit / 536.26 (KHTML; like Gecko) Mobile / 10B142 749 // iPhone4; 1 BingWeb / 3.03.1428.20120423. PC: Mozilla / 5.0 (Windows NT 6.3; WOW64; Trident / 7.0; Touch; 750 // rv:11.0) like Gecko. iPad: Mozilla / 5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit / 537.51.1 (KHTML, 751 // like Gecko) Version / 7.0 Mobile / 11A465 Safari / 9537.53 752 // clientID - bing uses this header to provide users with consistent behavior across Bing API calls. Bing often 753 // flights new features and improvements, and it uses the client ID as a key for assigning traffic on different 754 // flights. If you do not use the same client ID for a user across multiple requests, then Bing may assign the 755 // user to multiple conflicting flights. Being assigned to multiple conflicting flights can lead to an 756 // inconsistent user experience. For example, if the second request has a different flight assignment than the 757 // first, the experience may be unexpected. Also, Bing can use the client ID to tailor web results to that 758 // client ID’s search history, providing a richer experience for the user. Bing also uses this header to help 759 // improve result rankings by analyzing the activity generated by a client ID. The relevance improvements help 760 // with better quality of results delivered by Bing APIs and in turn enables higher click-through rates for the 761 // API consumer. IMPORTANT: Although optional, you should consider this header required. Persisting the client 762 // ID across multiple requests for the same end user and device combination enables 1) the API consumer to 763 // receive a consistent user experience, and 2) higher click-through rates via better quality of results from 764 // the Bing APIs. Each user that uses your application on the device must have a unique, Bing generated client 765 // ID. If you do not include this header in the request, Bing generates an ID and returns it in the 766 // X-MSEdge-ClientID response header. The only time that you should NOT include this header in a request is the 767 // first time the user uses your app on that device. Use the client ID for each Bing API request that your app 768 // makes for this user on the device. Persist the client ID. To persist the ID in a browser app, use a 769 // persistent HTTP cookie to ensure the ID is used across all sessions. Do not use a session cookie. For other 770 // apps such as mobile apps, use the device's persistent storage to persist the ID. The next time the user uses 771 // your app on that device, get the client ID that you persisted. Bing responses may or may not include this 772 // header. If the response includes this header, capture the client ID and use it for all subsequent Bing 773 // requests for the user on that device. If you include the X-MSEdge-ClientID, you must not include cookies in 774 // the request. 775 // clientIP - the IPv4 or IPv6 address of the client device. The IP address is used to discover the user's 776 // location. Bing uses the location information to determine safe search behavior. Although optional, you are 777 // encouraged to always specify this header and the X-Search-Location header. Do not obfuscate the address (for 778 // example, by changing the last octet to 0). Obfuscating the address results in the location not being 779 // anywhere near the device's actual location, which may result in Bing serving erroneous results. 780 // location - a semicolon-delimited list of key/value pairs that describe the client's geographical location. 781 // Bing uses the location information to determine safe search behavior and to return relevant local content. 782 // Specify the key/value pair as <key>:<value>. The following are the keys that you use to specify the user's 783 // location. lat (required): The latitude of the client's location, in degrees. The latitude must be greater 784 // than or equal to -90.0 and less than or equal to +90.0. Negative values indicate southern latitudes and 785 // positive values indicate northern latitudes. long (required): The longitude of the client's location, in 786 // degrees. The longitude must be greater than or equal to -180.0 and less than or equal to +180.0. Negative 787 // values indicate western longitudes and positive values indicate eastern longitudes. re (required): The 788 // radius, in meters, which specifies the horizontal accuracy of the coordinates. Pass the value returned by 789 // the device's location service. Typical values might be 22m for GPS/Wi-Fi, 380m for cell tower triangulation, 790 // and 18,000m for reverse IP lookup. ts (optional): The UTC UNIX timestamp of when the client was at the 791 // location. (The UNIX timestamp is the number of seconds since January 1, 1970.) head (optional): The client's 792 // relative heading or direction of travel. Specify the direction of travel as degrees from 0 through 360, 793 // counting clockwise relative to true north. Specify this key only if the sp key is nonzero. sp (optional): 794 // The horizontal velocity (speed), in meters per second, that the client device is traveling. alt (optional): 795 // The altitude of the client device, in meters. are (optional): The radius, in meters, that specifies the 796 // vertical accuracy of the coordinates. Specify this key only if you specify the alt key. Although many of the 797 // keys are optional, the more information that you provide, the more accurate the location results are. 798 // Although optional, you are encouraged to always specify the user's geographical location. Providing the 799 // location is especially important if the client's IP address does not accurately reflect the user's physical 800 // location (for example, if the client uses VPN). For optimal results, you should include this header and the 801 // X-MSEdge-ClientIP header, but at a minimum, you should include this header. 802 // countryCode - a 2-character country code of the country where the results come from. This API supports only 803 // the United States, Canada, Australia, and China markets. If you specify this query parameter, it must be set 804 // to us, ca, au, or cn. If you set this parameter, you must also specify the Accept-Language header. Bing uses 805 // the first supported language it finds from the languages list, and combine that language with the country 806 // code that you specify to determine the market to return results for. If the languages list does not include 807 // a supported language, Bing finds the closest language and market that supports the request, or it may use an 808 // aggregated or default market for the results instead of a specified one. You should use this query parameter 809 // and the Accept-Language query parameter only if you specify multiple languages; otherwise, you should use 810 // the mkt and setLang query parameters. This parameter and the mkt query parameter are mutually exclusive—do 811 // not specify both. 812 // market - the market where the results come from. Typically, mkt is the country where the user is making the 813 // request from. However, it could be a different country if the user is not located in a country where Bing 814 // delivers results. The market must be in the form <language code>-<country code>. For example, en-US. The 815 // string is case insensitive. For a list of possible market values, see [Market 816 // Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes). 817 // NOTE: If known, you are encouraged to always specify the market. Specifying the market helps Bing route the 818 // request and return an appropriate and optimal response. If you specify a market that is not listed in 819 // [Market 820 // Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes), 821 // Bing uses a best fit market code based on an internal mapping that is subject to change. This parameter and 822 // the [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) query 823 // parameter are mutually exclusive—do not specify both. 824 // safeSearch - filter images for adult content. The following are the possible filter values. Off: May return 825 // images with adult content. If the request is through the Image Search API, the response includes thumbnail 826 // images that are clear (non-fuzzy). However, if the request is through the Web Search API, the response 827 // includes thumbnail images that are pixelated (fuzzy). Moderate: If the request is through the Image Search 828 // API, the response doesn't include images with adult content. If the request is through the Web Search API, 829 // the response may include images with adult content (the thumbnail images are pixelated (fuzzy)). Strict: Do 830 // not return images with adult content. The default is Moderate. If the request comes from a market that 831 // Bing's adult policy requires that safeSearch is set to Strict, Bing ignores the safeSearch value and uses 832 // Strict. If you use the site: query operator, there is the chance that the response may contain adult content 833 // regardless of what the safeSearch query parameter is set to. Use site: only if you are aware of the content 834 // on the site and your scenario supports the possibility of adult content. 835 // setLang - the language to use for user interface strings. Specify the language using the ISO 639-1 2-letter 836 // language code. For example, the language code for English is EN. The default is EN (English). Although 837 // optional, you should always specify the language. Typically, you set setLang to the same language specified 838 // by mkt unless the user wants the user interface strings displayed in a different language. This parameter 839 // and the 840 // [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#acceptlanguage) 841 // header are mutually exclusive; do not specify both. A user interface string is a string that's used as a 842 // label in a user interface. There are few user interface strings in the JSON response objects. Also, any 843 // links to Bing.com properties in the response objects apply the specified language. 844 func (client ImagesClient) Trending(ctx context.Context, acceptLanguage string, userAgent string, clientID string, clientIP string, location string, countryCode string, market string, safeSearch SafeSearch, setLang string) (result TrendingImages, err error) { 845 if tracing.IsEnabled() { 846 ctx = tracing.StartSpan(ctx, fqdn+"/ImagesClient.Trending") 847 defer func() { 848 sc := -1 849 if result.Response.Response != nil { 850 sc = result.Response.Response.StatusCode 851 } 852 tracing.EndSpan(ctx, sc, err) 853 }() 854 } 855 req, err := client.TrendingPreparer(ctx, acceptLanguage, userAgent, clientID, clientIP, location, countryCode, market, safeSearch, setLang) 856 if err != nil { 857 err = autorest.NewErrorWithError(err, "imagesearch.ImagesClient", "Trending", nil, "Failure preparing request") 858 return 859 } 860 861 resp, err := client.TrendingSender(req) 862 if err != nil { 863 result.Response = autorest.Response{Response: resp} 864 err = autorest.NewErrorWithError(err, "imagesearch.ImagesClient", "Trending", resp, "Failure sending request") 865 return 866 } 867 868 result, err = client.TrendingResponder(resp) 869 if err != nil { 870 err = autorest.NewErrorWithError(err, "imagesearch.ImagesClient", "Trending", resp, "Failure responding to request") 871 return 872 } 873 874 return 875 } 876 877 // TrendingPreparer prepares the Trending request. 878 func (client ImagesClient) TrendingPreparer(ctx context.Context, acceptLanguage string, userAgent string, clientID string, clientIP string, location string, countryCode string, market string, safeSearch SafeSearch, setLang string) (*http.Request, error) { 879 urlParameters := map[string]interface{}{ 880 "Endpoint": client.Endpoint, 881 } 882 883 queryParameters := map[string]interface{}{} 884 if len(countryCode) > 0 { 885 queryParameters["cc"] = autorest.Encode("query", countryCode) 886 } 887 if len(market) > 0 { 888 queryParameters["mkt"] = autorest.Encode("query", market) 889 } 890 if len(string(safeSearch)) > 0 { 891 queryParameters["safeSearch"] = autorest.Encode("query", safeSearch) 892 } 893 if len(setLang) > 0 { 894 queryParameters["setLang"] = autorest.Encode("query", setLang) 895 } 896 897 preparer := autorest.CreatePreparer( 898 autorest.AsGet(), 899 autorest.WithCustomBaseURL("{Endpoint}/bing/v7.0", urlParameters), 900 autorest.WithPath("/images/trending"), 901 autorest.WithQueryParameters(queryParameters), 902 autorest.WithHeader("X-BingApis-SDK", "true")) 903 if len(acceptLanguage) > 0 { 904 preparer = autorest.DecoratePreparer(preparer, 905 autorest.WithHeader("Accept-Language", autorest.String(acceptLanguage))) 906 } 907 if len(userAgent) > 0 { 908 preparer = autorest.DecoratePreparer(preparer, 909 autorest.WithHeader("User-Agent", autorest.String(userAgent))) 910 } 911 if len(clientID) > 0 { 912 preparer = autorest.DecoratePreparer(preparer, 913 autorest.WithHeader("X-MSEdge-ClientID", autorest.String(clientID))) 914 } 915 if len(clientIP) > 0 { 916 preparer = autorest.DecoratePreparer(preparer, 917 autorest.WithHeader("X-MSEdge-ClientIP", autorest.String(clientIP))) 918 } 919 if len(location) > 0 { 920 preparer = autorest.DecoratePreparer(preparer, 921 autorest.WithHeader("X-Search-Location", autorest.String(location))) 922 } 923 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 924 } 925 926 // TrendingSender sends the Trending request. The method will close the 927 // http.Response Body if it receives an error. 928 func (client ImagesClient) TrendingSender(req *http.Request) (*http.Response, error) { 929 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 930 } 931 932 // TrendingResponder handles the response to the Trending request. The method always 933 // closes the http.Response Body. 934 func (client ImagesClient) TrendingResponder(resp *http.Response) (result TrendingImages, err error) { 935 err = autorest.Respond( 936 resp, 937 azure.WithErrorUnlessStatusCode(http.StatusOK), 938 autorest.ByUnmarshallingJSON(&result), 939 autorest.ByClosing()) 940 result.Response = autorest.Response{Response: resp} 941 return 942 } 943