...

Source file src/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v1.0/customimagesearch/custominstance.go

Documentation: github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v1.0/customimagesearch

     1  package customimagesearch
     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  // CustomInstanceClient is the the Bing Custom Image Search API lets you send an image search query to Bing and get
    18  // back image search results customized to meet your custom search definition.
    19  type CustomInstanceClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewCustomInstanceClient creates an instance of the CustomInstanceClient client.
    24  func NewCustomInstanceClient() CustomInstanceClient {
    25  	return CustomInstanceClient{New()}
    26  }
    27  
    28  // ImageSearch sends the image search request.
    29  // Parameters:
    30  // customConfig - the identifier for the custom search configuration
    31  // query - the user's search query term. The term cannot be empty. The term may contain [Bing Advanced
    32  // Operators](http://msdn.microsoft.com/library/ff795620.aspx). For example, to limit images to a specific
    33  // domain, use the [site:](http://msdn.microsoft.com/library/ff795613.aspx) operator. To help improve relevance
    34  // of an insights query (see
    35  // [insightsToken](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#insightstoken)),
    36  // you should always include the user's query term. Use this parameter only with the Image Search API.Do not
    37  // specify this parameter when calling the Trending Images API.
    38  // acceptLanguage - a comma-delimited list of one or more languages to use for user interface strings. The list
    39  // is in decreasing order of preference. For additional information, including expected format, see
    40  // [RFC2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). This header and the
    41  // [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang)
    42  // query parameter are mutually exclusive; do not specify both. If you set this header, you must also specify
    43  // the [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) query
    44  // parameter. To determine the market to return results for, Bing uses the first supported language it finds
    45  // from the list and combines it with the cc parameter value. If the list does not include a supported
    46  // language, Bing finds the closest language and market that supports the request or it uses an aggregated or
    47  // default market for the results. To determine the market that Bing used, see the BingAPIs-Market header. Use
    48  // this header and the cc query parameter only if you specify multiple languages. Otherwise, use the
    49  // [mkt](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#mkt) and
    50  // [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang)
    51  // query parameters. A user interface string is a string that's used as a label in a user interface. There are
    52  // few user interface strings in the JSON response objects. Any links to Bing.com properties in the response
    53  // objects apply the specified language.
    54  // userAgent - the user agent originating the request. Bing uses the user agent to provide mobile users with an
    55  // optimized experience. Although optional, you are encouraged to always specify this header. The user-agent
    56  // should be the same string that any commonly used browser sends. For information about user agents, see [RFC
    57  // 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). The following are examples of user-agent
    58  // strings. Windows Phone: Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0;
    59  // ARM; Touch; NOKIA; Lumia 822). Android: Mozilla / 5.0 (Linux; U; Android 2.3.5; en - us; SCH - I500 Build /
    60  // GINGERBREAD) AppleWebKit / 533.1 (KHTML; like Gecko) Version / 4.0 Mobile Safari / 533.1. iPhone: Mozilla /
    61  // 5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit / 536.26 (KHTML; like Gecko) Mobile / 10B142
    62  // iPhone4; 1 BingWeb / 3.03.1428.20120423. PC: Mozilla / 5.0 (Windows NT 6.3; WOW64; Trident / 7.0; Touch;
    63  // rv:11.0) like Gecko. iPad: Mozilla / 5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit / 537.51.1 (KHTML,
    64  // like Gecko) Version / 7.0 Mobile / 11A465 Safari / 9537.53
    65  // clientID - bing uses this header to provide users with consistent behavior across Bing API calls. Bing often
    66  // flights new features and improvements, and it uses the client ID as a key for assigning traffic on different
    67  // flights. If you do not use the same client ID for a user across multiple requests, then Bing may assign the
    68  // user to multiple conflicting flights. Being assigned to multiple conflicting flights can lead to an
    69  // inconsistent user experience. For example, if the second request has a different flight assignment than the
    70  // first, the experience may be unexpected. Also, Bing can use the client ID to tailor web results to that
    71  // client ID’s search history, providing a richer experience for the user. Bing also uses this header to help
    72  // improve result rankings by analyzing the activity generated by a client ID. The relevance improvements help
    73  // with better quality of results delivered by Bing APIs and in turn enables higher click-through rates for the
    74  // API consumer. IMPORTANT: Although optional, you should consider this header required. Persisting the client
    75  // ID across multiple requests for the same end user and device combination enables 1) the API consumer to
    76  // receive a consistent user experience, and 2) higher click-through rates via better quality of results from
    77  // the Bing APIs. Each user that uses your application on the device must have a unique, Bing generated client
    78  // ID. If you do not include this header in the request, Bing generates an ID and returns it in the
    79  // X-MSEdge-ClientID response header. The only time that you should NOT include this header in a request is the
    80  // first time the user uses your app on that device. Use the client ID for each Bing API request that your app
    81  // makes for this user on the device. Persist the client ID. To persist the ID in a browser app, use a
    82  // persistent HTTP cookie to ensure the ID is used across all sessions. Do not use a session cookie. For other
    83  // apps such as mobile apps, use the device's persistent storage to persist the ID. The next time the user uses
    84  // your app on that device, get the client ID that you persisted. Bing responses may or may not include this
    85  // header. If the response includes this header, capture the client ID and use it for all subsequent Bing
    86  // requests for the user on that device. If you include the X-MSEdge-ClientID, you must not include cookies in
    87  // the request.
    88  // clientIP - the IPv4 or IPv6 address of the client device. The IP address is used to discover the user's
    89  // location. Bing uses the location information to determine safe search behavior. Although optional, you are
    90  // encouraged to always specify this header and the X-Search-Location header. Do not obfuscate the address (for
    91  // example, by changing the last octet to 0). Obfuscating the address results in the location not being
    92  // anywhere near the device's actual location, which may result in Bing serving erroneous results.
    93  // location - a semicolon-delimited list of key/value pairs that describe the client's geographical location.
    94  // Bing uses the location information to determine safe search behavior and to return relevant local content.
    95  // Specify the key/value pair as <key>:<value>. The following are the keys that you use to specify the user's
    96  // location. lat (required): The latitude of the client's location, in degrees. The latitude must be greater
    97  // than or equal to -90.0 and less than or equal to +90.0. Negative values indicate southern latitudes and
    98  // positive values indicate northern latitudes. long (required): The longitude of the client's location, in
    99  // degrees. The longitude must be greater than or equal to -180.0 and less than or equal to +180.0. Negative
   100  // values indicate western longitudes and positive values indicate eastern longitudes. re (required): The
   101  // radius, in meters, which specifies the horizontal accuracy of the coordinates. Pass the value returned by
   102  // the device's location service. Typical values might be 22m for GPS/Wi-Fi, 380m for cell tower triangulation,
   103  // and 18,000m for reverse IP lookup. ts (optional): The UTC UNIX timestamp of when the client was at the
   104  // location. (The UNIX timestamp is the number of seconds since January 1, 1970.) head (optional): The client's
   105  // relative heading or direction of travel. Specify the direction of travel as degrees from 0 through 360,
   106  // counting clockwise relative to true north. Specify this key only if the sp key is nonzero. sp (optional):
   107  // The horizontal velocity (speed), in meters per second, that the client device is traveling. alt (optional):
   108  // The altitude of the client device, in meters. are (optional): The radius, in meters, that specifies the
   109  // vertical accuracy of the coordinates. Specify this key only if you specify the alt key. Although many of the
   110  // keys are optional, the more information that you provide, the more accurate the location results are.
   111  // Although optional, you are encouraged to always specify the user's geographical location. Providing the
   112  // location is especially important if the client's IP address does not accurately reflect the user's physical
   113  // location (for example, if the client uses VPN). For optimal results, you should include this header and the
   114  // X-MSEdge-ClientIP header, but at a minimum, you should include this header.
   115  // aspect - filter images by the following aspect ratios. All: Do not filter by aspect.Specifying this value is
   116  // the same as not specifying the aspect parameter. Square: Return images with standard aspect ratio. Wide:
   117  // Return images with wide screen aspect ratio. Tall: Return images with tall aspect ratio.
   118  // colorParameter - filter images by the following color options. ColorOnly: Return color images. Monochrome:
   119  // Return black and white images. Return images with one of the following dominant colors: Black, Blue, Brown,
   120  // Gray, Green, Orange, Pink, Purple, Red, Teal, White, Yellow
   121  // countryCode - a 2-character country code of the country where the results come from. For a list of possible
   122  // values, see [Market
   123  // Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes).
   124  // If you set this parameter, you must also specify the
   125  // [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#acceptlanguage)
   126  // header. Bing uses the first supported language it finds from the languages list, and combine that language
   127  // with the country code that you specify to determine the market to return results for. If the languages list
   128  // does not include a supported language, Bing finds the closest language and market that supports the request,
   129  // or it may use an aggregated or default market for the results instead of a specified one. You should use
   130  // this query parameter and the Accept-Language query parameter only if you specify multiple languages;
   131  // otherwise, you should use the mkt and setLang query parameters. This parameter and the
   132  // [mkt](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#mkt) query
   133  // parameter are mutually exclusive—do not specify both.
   134  // count - the number of images to return in the response. The actual number delivered may be less than
   135  // requested. The default is 35. The maximum value is 150. You use this parameter along with the offset
   136  // parameter to page results.For example, if your user interface displays 20 images per page, set count to 20
   137  // and offset to 0 to get the first page of results.For each subsequent page, increment offset by 20 (for
   138  // example, 0, 20, 40). Use this parameter only with the Image Search API.Do not specify this parameter when
   139  // calling the Insights, Trending Images, or Web Search APIs.
   140  // freshness - filter images by the following discovery options. Day: Return images discovered by Bing within
   141  // the last 24 hours. Week: Return images discovered by Bing within the last 7 days. Month: Return images
   142  // discovered by Bing within the last 30 days.
   143  // height - filter images that have the specified height, in pixels. You may use this filter with the size
   144  // filter to return small images that have a height of 150 pixels.
   145  // ID - an ID that uniquely identifies an image. Use this parameter to ensure that the specified image is the
   146  // first image in the list of images that Bing returns. The
   147  // [Image](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#image)
   148  // object's imageId field contains the ID that you set this parameter to.
   149  // imageContent - filter images by the following content types. Face: Return images that show only a person's
   150  // face. Portrait: Return images that show only a person's head and shoulders.
   151  // imageType - filter images by the following image types. AnimatedGif: Return only animated GIFs. Clipart:
   152  // Return only clip art images. Line: Return only line drawings. Photo: Return only photographs(excluding line
   153  // drawings, animated Gifs, and clip art). Shopping: Return only images that contain items where Bing knows of
   154  // a merchant that is selling the items. This option is valid in the en - US market only.Transparent: Return
   155  // only images with a transparent background.
   156  // license - filter images by the following license types. All: Do not filter by license type.Specifying this
   157  // value is the same as not specifying the license parameter. Any: Return images that are under any license
   158  // type. The response doesn't include images that do not specify a license or the license is unknown. Public:
   159  // Return images where the creator has waived their exclusive rights, to the fullest extent allowed by law.
   160  // Share: Return images that may be shared with others. Changing or editing the image might not be allowed.
   161  // Also, modifying, sharing, and using the image for commercial purposes might not be allowed. Typically, this
   162  // option returns the most images. ShareCommercially: Return images that may be shared with others for personal
   163  // or commercial purposes. Changing or editing the image might not be allowed. Modify: Return images that may
   164  // be modified, shared, and used. Changing or editing the image might not be allowed. Modifying, sharing, and
   165  // using the image for commercial purposes might not be allowed. ModifyCommercially: Return images that may be
   166  // modified, shared, and used for personal or commercial purposes. Typically, this option returns the fewest
   167  // images. For more information about these license types, see [Filter Images By License
   168  // Type](http://go.microsoft.com/fwlink/?LinkId=309768).
   169  // market - the market where the results come from. Typically, mkt is the country where the user is making the
   170  // request from. However, it could be a different country if the user is not located in a country where Bing
   171  // delivers results. The market must be in the form <language code>-<country code>. For example, en-US. The
   172  // string is case insensitive. For a list of possible market values, see [Market
   173  // Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes).
   174  // NOTE: If known, you are encouraged to always specify the market. Specifying the market helps Bing route the
   175  // request and return an appropriate and optimal response. If you specify a market that is not listed in
   176  // [Market
   177  // Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes),
   178  // Bing uses a best fit market code based on an internal mapping that is subject to change. This parameter and
   179  // the [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) query
   180  // parameter are mutually exclusive—do not specify both.
   181  // maxFileSize - filter images that are less than or equal to the specified file size. The maximum file size
   182  // that you may specify is 520,192 bytes. If you specify a larger value, the API uses 520,192. It is possible
   183  // that the response may include images that are slightly larger than the specified maximum. You may specify
   184  // this filter and minFileSize to filter images within a range of file sizes.
   185  // maxHeight - filter images that have a height that is less than or equal to the specified height. Specify the
   186  // height in pixels. You may specify this filter and minHeight to filter images within a range of heights. This
   187  // filter and the height filter are mutually exclusive.
   188  // maxWidth - filter images that have a width that is less than or equal to the specified width. Specify the
   189  // width in pixels. You may specify this filter and maxWidth to filter images within a range of widths. This
   190  // filter and the width filter are mutually exclusive.
   191  // minFileSize - filter images that are greater than or equal to the specified file size. The maximum file size
   192  // that you may specify is 520,192 bytes. If you specify a larger value, the API uses 520,192. It is possible
   193  // that the response may include images that are slightly smaller than the specified minimum. You may specify
   194  // this filter and maxFileSize to filter images within a range of file sizes.
   195  // minHeight - filter images that have a height that is greater than or equal to the specified height. Specify
   196  // the height in pixels. You may specify this filter and maxHeight to filter images within a range of heights.
   197  // This filter and the height filter are mutually exclusive.
   198  // minWidth - filter images that have a width that is greater than or equal to the specified width. Specify the
   199  // width in pixels. You may specify this filter and maxWidth to filter images within a range of widths. This
   200  // filter and the width filter are mutually exclusive.
   201  // offset - the zero-based offset that indicates the number of images to skip before returning images. The
   202  // default is 0. The offset should be less than
   203  // ([totalEstimatedMatches](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#totalestimatedmatches)
   204  // - count). Use this parameter along with the count parameter to page results. For example, if your user
   205  // interface displays 20 images per page, set count to 20 and offset to 0 to get the first page of results. For
   206  // each subsequent page, increment offset by 20 (for example, 0, 20, 40). It is possible for multiple pages to
   207  // include some overlap in results. To prevent duplicates, see
   208  // [nextOffset](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#nextoffset).
   209  // Use this parameter only with the Image API. Do not specify this parameter when calling the Trending Images
   210  // API or the Web Search API.
   211  // safeSearch - filter images for adult content. The following are the possible filter values. Off: May return
   212  // images with adult content. If the request is through the Image Search API, the response includes thumbnail
   213  // images that are clear (non-fuzzy). However, if the request is through the Web Search API, the response
   214  // includes thumbnail images that are pixelated (fuzzy). Moderate: If the request is through the Image Search
   215  // API, the response doesn't include images with adult content. If the request is through the Web Search API,
   216  // the response may include images with adult content (the thumbnail images are pixelated (fuzzy)). Strict: Do
   217  // not return images with adult content. The default is Moderate. If the request comes from a market that
   218  // Bing's adult policy requires that safeSearch is set to Strict, Bing ignores the safeSearch value and uses
   219  // Strict. If you use the site: query operator, there is the chance that the response may contain adult content
   220  // regardless of what the safeSearch query parameter is set to. Use site: only if you are aware of the content
   221  // on the site and your scenario supports the possibility of adult content.
   222  // size - filter images by the following sizes. All: Do not filter by size. Specifying this value is the same
   223  // as not specifying the size parameter. Small: Return images that are less than 200x200 pixels. Medium: Return
   224  // images that are greater than or equal to 200x200 pixels but less than 500x500 pixels. Large: Return images
   225  // that are 500x500 pixels or larger. Wallpaper: Return wallpaper images. You may use this parameter along with
   226  // the height or width parameters. For example, you may use height and size to request small images that are
   227  // 150 pixels tall.
   228  // setLang - the language to use for user interface strings. Specify the language using the ISO 639-1 2-letter
   229  // language code. For example, the language code for English is EN. The default is EN (English). Although
   230  // optional, you should always specify the language. Typically, you set setLang to the same language specified
   231  // by mkt unless the user wants the user interface strings displayed in a different language. This parameter
   232  // and the
   233  // [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#acceptlanguage)
   234  // header are mutually exclusive; do not specify both. A user interface string is a string that's used as a
   235  // label in a user interface. There are few user interface strings in the JSON response objects. Also, any
   236  // links to Bing.com properties in the response objects apply the specified language.
   237  // width - filter images that have the specified width, in pixels. You may use this filter with the size filter
   238  // to return small images that have a width of 150 pixels.
   239  func (client CustomInstanceClient) ImageSearch(ctx context.Context, customConfig string, 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) {
   240  	if tracing.IsEnabled() {
   241  		ctx = tracing.StartSpan(ctx, fqdn+"/CustomInstanceClient.ImageSearch")
   242  		defer func() {
   243  			sc := -1
   244  			if result.Response.Response != nil {
   245  				sc = result.Response.Response.StatusCode
   246  			}
   247  			tracing.EndSpan(ctx, sc, err)
   248  		}()
   249  	}
   250  	req, err := client.ImageSearchPreparer(ctx, customConfig, 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)
   251  	if err != nil {
   252  		err = autorest.NewErrorWithError(err, "customimagesearch.CustomInstanceClient", "ImageSearch", nil, "Failure preparing request")
   253  		return
   254  	}
   255  
   256  	resp, err := client.ImageSearchSender(req)
   257  	if err != nil {
   258  		result.Response = autorest.Response{Response: resp}
   259  		err = autorest.NewErrorWithError(err, "customimagesearch.CustomInstanceClient", "ImageSearch", resp, "Failure sending request")
   260  		return
   261  	}
   262  
   263  	result, err = client.ImageSearchResponder(resp)
   264  	if err != nil {
   265  		err = autorest.NewErrorWithError(err, "customimagesearch.CustomInstanceClient", "ImageSearch", resp, "Failure responding to request")
   266  		return
   267  	}
   268  
   269  	return
   270  }
   271  
   272  // ImageSearchPreparer prepares the ImageSearch request.
   273  func (client CustomInstanceClient) ImageSearchPreparer(ctx context.Context, customConfig string, 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) {
   274  	urlParameters := map[string]interface{}{
   275  		"Endpoint": client.Endpoint,
   276  	}
   277  
   278  	queryParameters := map[string]interface{}{
   279  		"customConfig": autorest.Encode("query", customConfig),
   280  		"q":            autorest.Encode("query", query),
   281  	}
   282  	if len(string(aspect)) > 0 {
   283  		queryParameters["aspect"] = autorest.Encode("query", aspect)
   284  	}
   285  	if len(string(colorParameter)) > 0 {
   286  		queryParameters["color"] = autorest.Encode("query", colorParameter)
   287  	}
   288  	if len(countryCode) > 0 {
   289  		queryParameters["cc"] = autorest.Encode("query", countryCode)
   290  	}
   291  	if count != nil {
   292  		queryParameters["count"] = autorest.Encode("query", *count)
   293  	}
   294  	if len(string(freshness)) > 0 {
   295  		queryParameters["freshness"] = autorest.Encode("query", freshness)
   296  	}
   297  	if height != nil {
   298  		queryParameters["height"] = autorest.Encode("query", *height)
   299  	}
   300  	if len(ID) > 0 {
   301  		queryParameters["id"] = autorest.Encode("query", ID)
   302  	}
   303  	if len(string(imageContent)) > 0 {
   304  		queryParameters["imageContent"] = autorest.Encode("query", imageContent)
   305  	}
   306  	if len(string(imageType)) > 0 {
   307  		queryParameters["imageType"] = autorest.Encode("query", imageType)
   308  	}
   309  	if len(string(license)) > 0 {
   310  		queryParameters["license"] = autorest.Encode("query", license)
   311  	}
   312  	if len(market) > 0 {
   313  		queryParameters["mkt"] = autorest.Encode("query", market)
   314  	}
   315  	if maxFileSize != nil {
   316  		queryParameters["maxFileSize"] = autorest.Encode("query", *maxFileSize)
   317  	}
   318  	if maxHeight != nil {
   319  		queryParameters["maxHeight"] = autorest.Encode("query", *maxHeight)
   320  	}
   321  	if maxWidth != nil {
   322  		queryParameters["maxWidth"] = autorest.Encode("query", *maxWidth)
   323  	}
   324  	if minFileSize != nil {
   325  		queryParameters["minFileSize"] = autorest.Encode("query", *minFileSize)
   326  	}
   327  	if minHeight != nil {
   328  		queryParameters["minHeight"] = autorest.Encode("query", *minHeight)
   329  	}
   330  	if minWidth != nil {
   331  		queryParameters["minWidth"] = autorest.Encode("query", *minWidth)
   332  	}
   333  	if offset != nil {
   334  		queryParameters["offset"] = autorest.Encode("query", *offset)
   335  	}
   336  	if len(string(safeSearch)) > 0 {
   337  		queryParameters["safeSearch"] = autorest.Encode("query", safeSearch)
   338  	}
   339  	if len(string(size)) > 0 {
   340  		queryParameters["size"] = autorest.Encode("query", size)
   341  	}
   342  	if len(setLang) > 0 {
   343  		queryParameters["setLang"] = autorest.Encode("query", setLang)
   344  	}
   345  	if width != nil {
   346  		queryParameters["width"] = autorest.Encode("query", *width)
   347  	}
   348  
   349  	preparer := autorest.CreatePreparer(
   350  		autorest.AsGet(),
   351  		autorest.WithCustomBaseURL("{Endpoint}/bingcustomsearch/v7.0", urlParameters),
   352  		autorest.WithPath("/images/search"),
   353  		autorest.WithQueryParameters(queryParameters),
   354  		autorest.WithHeader("X-BingApis-SDK", "true"))
   355  	if len(acceptLanguage) > 0 {
   356  		preparer = autorest.DecoratePreparer(preparer,
   357  			autorest.WithHeader("Accept-Language", autorest.String(acceptLanguage)))
   358  	}
   359  	if len(userAgent) > 0 {
   360  		preparer = autorest.DecoratePreparer(preparer,
   361  			autorest.WithHeader("User-Agent", autorest.String(userAgent)))
   362  	}
   363  	if len(clientID) > 0 {
   364  		preparer = autorest.DecoratePreparer(preparer,
   365  			autorest.WithHeader("X-MSEdge-ClientID", autorest.String(clientID)))
   366  	}
   367  	if len(clientIP) > 0 {
   368  		preparer = autorest.DecoratePreparer(preparer,
   369  			autorest.WithHeader("X-MSEdge-ClientIP", autorest.String(clientIP)))
   370  	}
   371  	if len(location) > 0 {
   372  		preparer = autorest.DecoratePreparer(preparer,
   373  			autorest.WithHeader("X-Search-Location", autorest.String(location)))
   374  	}
   375  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   376  }
   377  
   378  // ImageSearchSender sends the ImageSearch request. The method will close the
   379  // http.Response Body if it receives an error.
   380  func (client CustomInstanceClient) ImageSearchSender(req *http.Request) (*http.Response, error) {
   381  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   382  }
   383  
   384  // ImageSearchResponder handles the response to the ImageSearch request. The method always
   385  // closes the http.Response Body.
   386  func (client CustomInstanceClient) ImageSearchResponder(resp *http.Response) (result Images, err error) {
   387  	err = autorest.Respond(
   388  		resp,
   389  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   390  		autorest.ByUnmarshallingJSON(&result),
   391  		autorest.ByClosing())
   392  	result.Response = autorest.Response{Response: resp}
   393  	return
   394  }
   395  

View as plain text