...

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

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

     1  package videosearch
     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  // VideosClient is the the Video Search API lets you search on Bing for video that are relevant to the user's search
    18  // query, for insights about a video or for videos that are trending based on search requests made by others. This
    19  // section provides technical details about the query parameters and headers that you use to request videos and the
    20  // JSON response objects that contain them. For examples that show how to make requests, see [Searching the Web for
    21  // Videos](https://docs.microsoft.com/azure/cognitive-services/bing-video-search/search-the-web).
    22  type VideosClient struct {
    23  	BaseClient
    24  }
    25  
    26  // NewVideosClient creates an instance of the VideosClient client.
    27  func NewVideosClient() VideosClient {
    28  	return VideosClient{New()}
    29  }
    30  
    31  // Details sends the details request.
    32  // Parameters:
    33  // query - the user's search query string. The query string cannot be empty. The query string may contain [Bing
    34  // Advanced Operators](http://msdn.microsoft.com/library/ff795620.aspx). For example, to limit videos to a
    35  // specific domain, use the [site:](http://msdn.microsoft.com/library/ff795613.aspx) operator. Use this
    36  // parameter only with the Video Search API. Do not specify this parameter when calling the Trending Videos
    37  // 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-video-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-video-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-video-api-v7-reference#mkt) and
    50  // [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-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  // countryCode - a 2-character country code of the country where the results come from. This API supports only
   116  // the United States market. If you specify this query parameter, it must be set to us. If you set this
   117  // parameter, you must also specify the Accept-Language header. Bing uses the first supported language it finds
   118  // from the languages list, and combine that language with the country code that you specify to determine the
   119  // market to return results for. If the languages list does not include a supported language, Bing finds the
   120  // closest language and market that supports the request, or it may use an aggregated or default market for the
   121  // results instead of a specified one. You should use this query parameter and the Accept-Language query
   122  // parameter only if you specify multiple languages; otherwise, you should use the mkt and setLang query
   123  // parameters. This parameter and the mkt query parameter are mutually exclusive—do not specify both.
   124  // ID - an ID that uniquely identifies a video. The
   125  // [Video](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#video)
   126  // object's videoId field contains the ID that you set this parameter to. You use this parameter to identify
   127  // the video to get insights of.
   128  // modules - a comma-delimited list of insights to request. The following are the possible case-insensitive
   129  // values. All: Return all available insights. RelatedVideos: Return a list of videos that are similar to the
   130  // video specified by the id query parameter. VideoResult: Return the video that you're requesting insights of
   131  // (this is the video that you set the id query parameter to in your insights request). If you specify an
   132  // insight and there is no data for it, the response object does not include the related field. For example, if
   133  // you specify RelatedVideos and none exist, the response does not include the relatedVideos field. Although
   134  // the user's query term is not required, you should always include it because it helps to improve relevance
   135  // and the results.
   136  // market - the market where the results come from. Typically, mkt is the country where the user is making the
   137  // request from. However, it could be a different country if the user is not located in a country where Bing
   138  // delivers results. The market must be in the form <language code>-<country code>. For example, en-US. The
   139  // string is case insensitive. For a list of possible market values, see [Market
   140  // Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#market-codes).
   141  // NOTE: If known, you are encouraged to always specify the market. Specifying the market helps Bing route the
   142  // request and return an appropriate and optimal response. If you specify a market that is not listed in
   143  // [Market
   144  // Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#market-codes),
   145  // Bing uses a best fit market code based on an internal mapping that is subject to change. This parameter and
   146  // the [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#cc) query
   147  // parameter are mutually exclusive—do not specify both.
   148  // resolution - filter videos by the following resolutions: SD480p: Return videos with a 480p or higher
   149  // resolution. HD720p: Return videos with a 720p or higher resolution. HD1080p: Return videos with a 1080p or
   150  // higher resolution. All: Do not filter by resolution.Specifying this value is the same as not specifying the
   151  // resolution parameter.
   152  // safeSearch - filter videos for adult content. The following are the possible filter values. Off: If the
   153  // request is through the Video Search API, the response includes adult videos and the thumbnail images of the
   154  // videos are clear (non-fuzzy). If the request is through the Web Search API, the response includes adult
   155  // videos but the thumbnail images of the videos are pixelated (fuzzy). Moderate: If the request is through the
   156  // Video Search API, the response does not include videos with adult content. If the request is through the Web
   157  // Search API, the response may include videos with adult content but the thumbnail images of the videos are
   158  // pixelated (fuzzy). Strict: Does not return videos with adult content. The default is Moderate. If the
   159  // request comes from a market that Bing's adult policy requires that safeSearch is set to Strict, Bing ignores
   160  // the safeSearch value and uses Strict. If you use the site: query operator, there is the chance that the
   161  // response may contain adult content regardless of what the safeSearch query parameter is set to. Use site:
   162  // only if you are aware of the content on the site and your scenario supports the possibility of adult
   163  // content.
   164  // setLang - the language to use for user interface strings. Specify the language using the ISO 639-1 2-letter
   165  // language code. For example, the language code for English is EN. The default is EN (English). Although
   166  // optional, you should always specify the language. Typically, you set setLang to the same language specified
   167  // by mkt unless the user wants the user interface strings displayed in a different language. This parameter
   168  // and the
   169  // [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#acceptlanguage)
   170  // header are mutually exclusive; do not specify both. A user interface string is a string that's used as a
   171  // label in a user interface. There are few user interface strings in the JSON response objects. Also, any
   172  // links to Bing.com properties in the response objects apply the specified language.
   173  // textDecorations - a Boolean value that determines whether display strings contain decoration markers such as
   174  // hit highlighting characters. If true, the strings may include markers. The default is false. To specify
   175  // whether to use Unicode characters or HTML tags as the markers, see the
   176  // [textFormat](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#textformat)
   177  // query parameter. For information about hit highlighting, see [Hit
   178  // Highlighting](https://docs.microsoft.com/azure/cognitive-services/bing-news-search/hit-highlighting).
   179  // textFormat - the type of markers to use for text decorations (see the textDecorations query parameter).
   180  // Possible values are Raw—Use Unicode characters to mark content that needs special formatting. The Unicode
   181  // characters are in the range E000 through E019. For example, Bing uses E000 and E001 to mark the beginning
   182  // and end of query terms for hit highlighting. HTML—Use HTML tags to mark content that needs special
   183  // formatting. For example, use <b> tags to highlight query terms in display strings. The default is Raw. For
   184  // display strings that contain escapable HTML characters such as <, >, and &, if textFormat is set to HTML,
   185  // Bing escapes the characters as appropriate (for example, < is escaped to &lt;).
   186  func (client VideosClient) Details(ctx context.Context, query string, acceptLanguage string, userAgent string, clientID string, clientIP string, location string, countryCode string, ID string, modules []VideoInsightModule, market string, resolution VideoResolution, safeSearch SafeSearch, setLang string, textDecorations *bool, textFormat TextFormat) (result VideoDetails, err error) {
   187  	if tracing.IsEnabled() {
   188  		ctx = tracing.StartSpan(ctx, fqdn+"/VideosClient.Details")
   189  		defer func() {
   190  			sc := -1
   191  			if result.Response.Response != nil {
   192  				sc = result.Response.Response.StatusCode
   193  			}
   194  			tracing.EndSpan(ctx, sc, err)
   195  		}()
   196  	}
   197  	req, err := client.DetailsPreparer(ctx, query, acceptLanguage, userAgent, clientID, clientIP, location, countryCode, ID, modules, market, resolution, safeSearch, setLang, textDecorations, textFormat)
   198  	if err != nil {
   199  		err = autorest.NewErrorWithError(err, "videosearch.VideosClient", "Details", nil, "Failure preparing request")
   200  		return
   201  	}
   202  
   203  	resp, err := client.DetailsSender(req)
   204  	if err != nil {
   205  		result.Response = autorest.Response{Response: resp}
   206  		err = autorest.NewErrorWithError(err, "videosearch.VideosClient", "Details", resp, "Failure sending request")
   207  		return
   208  	}
   209  
   210  	result, err = client.DetailsResponder(resp)
   211  	if err != nil {
   212  		err = autorest.NewErrorWithError(err, "videosearch.VideosClient", "Details", resp, "Failure responding to request")
   213  		return
   214  	}
   215  
   216  	return
   217  }
   218  
   219  // DetailsPreparer prepares the Details request.
   220  func (client VideosClient) DetailsPreparer(ctx context.Context, query string, acceptLanguage string, userAgent string, clientID string, clientIP string, location string, countryCode string, ID string, modules []VideoInsightModule, market string, resolution VideoResolution, safeSearch SafeSearch, setLang string, textDecorations *bool, textFormat TextFormat) (*http.Request, error) {
   221  	urlParameters := map[string]interface{}{
   222  		"Endpoint": client.Endpoint,
   223  	}
   224  
   225  	queryParameters := map[string]interface{}{
   226  		"q": autorest.Encode("query", query),
   227  	}
   228  	if len(countryCode) > 0 {
   229  		queryParameters["cc"] = autorest.Encode("query", countryCode)
   230  	}
   231  	if len(ID) > 0 {
   232  		queryParameters["id"] = autorest.Encode("query", ID)
   233  	}
   234  	if modules != nil && len(modules) > 0 {
   235  		queryParameters["modules"] = autorest.Encode("query", modules, ",")
   236  	}
   237  	if len(market) > 0 {
   238  		queryParameters["mkt"] = autorest.Encode("query", market)
   239  	}
   240  	if len(string(resolution)) > 0 {
   241  		queryParameters["resolution"] = autorest.Encode("query", resolution)
   242  	}
   243  	if len(string(safeSearch)) > 0 {
   244  		queryParameters["safeSearch"] = autorest.Encode("query", safeSearch)
   245  	}
   246  	if len(setLang) > 0 {
   247  		queryParameters["setLang"] = autorest.Encode("query", setLang)
   248  	}
   249  	if textDecorations != nil {
   250  		queryParameters["textDecorations"] = autorest.Encode("query", *textDecorations)
   251  	}
   252  	if len(string(textFormat)) > 0 {
   253  		queryParameters["textFormat"] = autorest.Encode("query", textFormat)
   254  	}
   255  
   256  	preparer := autorest.CreatePreparer(
   257  		autorest.AsGet(),
   258  		autorest.WithCustomBaseURL("{Endpoint}/bing/v7.0", urlParameters),
   259  		autorest.WithPath("/videos/details"),
   260  		autorest.WithQueryParameters(queryParameters),
   261  		autorest.WithHeader("X-BingApis-SDK", "true"))
   262  	if len(acceptLanguage) > 0 {
   263  		preparer = autorest.DecoratePreparer(preparer,
   264  			autorest.WithHeader("Accept-Language", autorest.String(acceptLanguage)))
   265  	}
   266  	if len(userAgent) > 0 {
   267  		preparer = autorest.DecoratePreparer(preparer,
   268  			autorest.WithHeader("User-Agent", autorest.String(userAgent)))
   269  	}
   270  	if len(clientID) > 0 {
   271  		preparer = autorest.DecoratePreparer(preparer,
   272  			autorest.WithHeader("X-MSEdge-ClientID", autorest.String(clientID)))
   273  	}
   274  	if len(clientIP) > 0 {
   275  		preparer = autorest.DecoratePreparer(preparer,
   276  			autorest.WithHeader("X-MSEdge-ClientIP", autorest.String(clientIP)))
   277  	}
   278  	if len(location) > 0 {
   279  		preparer = autorest.DecoratePreparer(preparer,
   280  			autorest.WithHeader("X-Search-Location", autorest.String(location)))
   281  	}
   282  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   283  }
   284  
   285  // DetailsSender sends the Details request. The method will close the
   286  // http.Response Body if it receives an error.
   287  func (client VideosClient) DetailsSender(req *http.Request) (*http.Response, error) {
   288  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   289  }
   290  
   291  // DetailsResponder handles the response to the Details request. The method always
   292  // closes the http.Response Body.
   293  func (client VideosClient) DetailsResponder(resp *http.Response) (result VideoDetails, err error) {
   294  	err = autorest.Respond(
   295  		resp,
   296  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   297  		autorest.ByUnmarshallingJSON(&result),
   298  		autorest.ByClosing())
   299  	result.Response = autorest.Response{Response: resp}
   300  	return
   301  }
   302  
   303  // Search sends the search request.
   304  // Parameters:
   305  // query - the user's search query string. The query string cannot be empty. The query string may contain [Bing
   306  // Advanced Operators](http://msdn.microsoft.com/library/ff795620.aspx). For example, to limit videos to a
   307  // specific domain, use the [site:](http://msdn.microsoft.com/library/ff795613.aspx) operator. Use this
   308  // parameter only with the Video Search API. Do not specify this parameter when calling the Trending Videos
   309  // API.
   310  // acceptLanguage - a comma-delimited list of one or more languages to use for user interface strings. The list
   311  // is in decreasing order of preference. For additional information, including expected format, see
   312  // [RFC2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). This header and the
   313  // [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#setlang)
   314  // query parameter are mutually exclusive; do not specify both. If you set this header, you must also specify
   315  // the [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#cc) query
   316  // parameter. To determine the market to return results for, Bing uses the first supported language it finds
   317  // from the list and combines it with the cc parameter value. If the list does not include a supported
   318  // language, Bing finds the closest language and market that supports the request or it uses an aggregated or
   319  // default market for the results. To determine the market that Bing used, see the BingAPIs-Market header. Use
   320  // this header and the cc query parameter only if you specify multiple languages. Otherwise, use the
   321  // [mkt](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#mkt) and
   322  // [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#setlang)
   323  // query parameters. A user interface string is a string that's used as a label in a user interface. There are
   324  // few user interface strings in the JSON response objects. Any links to Bing.com properties in the response
   325  // objects apply the specified language.
   326  // userAgent - the user agent originating the request. Bing uses the user agent to provide mobile users with an
   327  // optimized experience. Although optional, you are encouraged to always specify this header. The user-agent
   328  // should be the same string that any commonly used browser sends. For information about user agents, see [RFC
   329  // 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). The following are examples of user-agent
   330  // strings. Windows Phone: Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0;
   331  // ARM; Touch; NOKIA; Lumia 822). Android: Mozilla / 5.0 (Linux; U; Android 2.3.5; en - us; SCH - I500 Build /
   332  // GINGERBREAD) AppleWebKit / 533.1 (KHTML; like Gecko) Version / 4.0 Mobile Safari / 533.1. iPhone: Mozilla /
   333  // 5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit / 536.26 (KHTML; like Gecko) Mobile / 10B142
   334  // iPhone4; 1 BingWeb / 3.03.1428.20120423. PC: Mozilla / 5.0 (Windows NT 6.3; WOW64; Trident / 7.0; Touch;
   335  // rv:11.0) like Gecko. iPad: Mozilla / 5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit / 537.51.1 (KHTML,
   336  // like Gecko) Version / 7.0 Mobile / 11A465 Safari / 9537.53
   337  // clientID - bing uses this header to provide users with consistent behavior across Bing API calls. Bing often
   338  // flights new features and improvements, and it uses the client ID as a key for assigning traffic on different
   339  // flights. If you do not use the same client ID for a user across multiple requests, then Bing may assign the
   340  // user to multiple conflicting flights. Being assigned to multiple conflicting flights can lead to an
   341  // inconsistent user experience. For example, if the second request has a different flight assignment than the
   342  // first, the experience may be unexpected. Also, Bing can use the client ID to tailor web results to that
   343  // client ID’s search history, providing a richer experience for the user. Bing also uses this header to help
   344  // improve result rankings by analyzing the activity generated by a client ID. The relevance improvements help
   345  // with better quality of results delivered by Bing APIs and in turn enables higher click-through rates for the
   346  // API consumer. IMPORTANT: Although optional, you should consider this header required. Persisting the client
   347  // ID across multiple requests for the same end user and device combination enables 1) the API consumer to
   348  // receive a consistent user experience, and 2) higher click-through rates via better quality of results from
   349  // the Bing APIs. Each user that uses your application on the device must have a unique, Bing generated client
   350  // ID. If you do not include this header in the request, Bing generates an ID and returns it in the
   351  // X-MSEdge-ClientID response header. The only time that you should NOT include this header in a request is the
   352  // first time the user uses your app on that device. Use the client ID for each Bing API request that your app
   353  // makes for this user on the device. Persist the client ID. To persist the ID in a browser app, use a
   354  // persistent HTTP cookie to ensure the ID is used across all sessions. Do not use a session cookie. For other
   355  // apps such as mobile apps, use the device's persistent storage to persist the ID. The next time the user uses
   356  // your app on that device, get the client ID that you persisted. Bing responses may or may not include this
   357  // header. If the response includes this header, capture the client ID and use it for all subsequent Bing
   358  // requests for the user on that device. If you include the X-MSEdge-ClientID, you must not include cookies in
   359  // the request.
   360  // clientIP - the IPv4 or IPv6 address of the client device. The IP address is used to discover the user's
   361  // location. Bing uses the location information to determine safe search behavior. Although optional, you are
   362  // encouraged to always specify this header and the X-Search-Location header. Do not obfuscate the address (for
   363  // example, by changing the last octet to 0). Obfuscating the address results in the location not being
   364  // anywhere near the device's actual location, which may result in Bing serving erroneous results.
   365  // location - a semicolon-delimited list of key/value pairs that describe the client's geographical location.
   366  // Bing uses the location information to determine safe search behavior and to return relevant local content.
   367  // Specify the key/value pair as <key>:<value>. The following are the keys that you use to specify the user's
   368  // location. lat (required): The latitude of the client's location, in degrees. The latitude must be greater
   369  // than or equal to -90.0 and less than or equal to +90.0. Negative values indicate southern latitudes and
   370  // positive values indicate northern latitudes. long (required): The longitude of the client's location, in
   371  // degrees. The longitude must be greater than or equal to -180.0 and less than or equal to +180.0. Negative
   372  // values indicate western longitudes and positive values indicate eastern longitudes. re (required): The
   373  // radius, in meters, which specifies the horizontal accuracy of the coordinates. Pass the value returned by
   374  // the device's location service. Typical values might be 22m for GPS/Wi-Fi, 380m for cell tower triangulation,
   375  // and 18,000m for reverse IP lookup. ts (optional): The UTC UNIX timestamp of when the client was at the
   376  // location. (The UNIX timestamp is the number of seconds since January 1, 1970.) head (optional): The client's
   377  // relative heading or direction of travel. Specify the direction of travel as degrees from 0 through 360,
   378  // counting clockwise relative to true north. Specify this key only if the sp key is nonzero. sp (optional):
   379  // The horizontal velocity (speed), in meters per second, that the client device is traveling. alt (optional):
   380  // The altitude of the client device, in meters. are (optional): The radius, in meters, that specifies the
   381  // vertical accuracy of the coordinates. Specify this key only if you specify the alt key. Although many of the
   382  // keys are optional, the more information that you provide, the more accurate the location results are.
   383  // Although optional, you are encouraged to always specify the user's geographical location. Providing the
   384  // location is especially important if the client's IP address does not accurately reflect the user's physical
   385  // location (for example, if the client uses VPN). For optimal results, you should include this header and the
   386  // X-MSEdge-ClientIP header, but at a minimum, you should include this header.
   387  // countryCode - a 2-character country code of the country where the results come from. This API supports only
   388  // the United States market. If you specify this query parameter, it must be set to us. If you set this
   389  // parameter, you must also specify the Accept-Language header. Bing uses the first supported language it finds
   390  // from the languages list, and combine that language with the country code that you specify to determine the
   391  // market to return results for. If the languages list does not include a supported language, Bing finds the
   392  // closest language and market that supports the request, or it may use an aggregated or default market for the
   393  // results instead of a specified one. You should use this query parameter and the Accept-Language query
   394  // parameter only if you specify multiple languages; otherwise, you should use the mkt and setLang query
   395  // parameters. This parameter and the mkt query parameter are mutually exclusive—do not specify both.
   396  // count - the number of videos to return in the response. The actual number delivered may be less than
   397  // requested. The default is 35. The maximum is 105. You may use this parameter along with the offset parameter
   398  // to page results. For example, if your user interface presents 20 videos per page, set count to 20 and offset
   399  // to 0 to get the first page of results. For each subsequent page, increment offset by 20 (for example, 0, 20,
   400  // 40). Use this parameter only with the Video Search API. Do not specify this parameter when calling the
   401  // Trending Videos API or the Web Search API.
   402  // freshness - filter videos by the date and time that Bing discovered the video. The following are the
   403  // possible filter values. Day: Return videos discovered within the last 24 hours. Week: Return videos
   404  // discovered within the last 7 days. Month: Return videos discovered within the last 30 days.
   405  // ID - an ID that uniquely identifies a video. The
   406  // [Video](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#video)
   407  // object's videoId field contains the ID that you set this parameter to. You use this parameter to ensure that
   408  // the specified video is the first video in the list of videos that Bing returns.
   409  // length - filter videos by the following lengths: Short: Return videos that are less than 5 minutes. Medium:
   410  // Return videos that are between 5 and 20 minutes, inclusive. Long: Return videos that are longer than 20
   411  // minutes. All: Do not filter by length.Specifying this value is the same as not specifying the videoLength
   412  // parameter.
   413  // market - the market where the results come from. Typically, mkt is the country where the user is making the
   414  // request from. However, it could be a different country if the user is not located in a country where Bing
   415  // delivers results. The market must be in the form <language code>-<country code>. For example, en-US. The
   416  // string is case insensitive. For a list of possible market values, see [Market
   417  // Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#market-codes).
   418  // NOTE: If known, you are encouraged to always specify the market. Specifying the market helps Bing route the
   419  // request and return an appropriate and optimal response. If you specify a market that is not listed in
   420  // [Market
   421  // Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#market-codes),
   422  // Bing uses a best fit market code based on an internal mapping that is subject to change. This parameter and
   423  // the [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#cc) query
   424  // parameter are mutually exclusive—do not specify both.
   425  // offset - the zero-based offset that indicates the number of videos to skip before returning videos. The
   426  // default is 0. The offset should be less than
   427  // ([totalEstimatedMatches](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#videos-totalmatches)
   428  // - count). Use this parameter along with the count parameter to page results. For example, if your user
   429  // interface displays 20 videos per page, set count to 20 and offset to 0 to get the first page of results. For
   430  // each subsequent page, increment offset by 20 (for example, 0, 20, 40). It is possible for multiple pages to
   431  // include some overlap in results. To prevent duplicates, see
   432  // [nextOffset](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#videos-nextoffset).
   433  // Use this parameter only with the Video Search API.
   434  // pricing - filter videos by the following pricing options: Free: Return videos that are free to view. Paid:
   435  // Return videos that require a subscription or payment to view. All: Do not filter by pricing.Specifying this
   436  // value is the same as not specifying the pricing parameter.
   437  // resolution - filter videos by the following resolutions: SD480p: Return videos with a 480p or higher
   438  // resolution. HD720p: Return videos with a 720p or higher resolution. HD1080p: Return videos with a 1080p or
   439  // higher resolution. All: Do not filter by resolution.Specifying this value is the same as not specifying the
   440  // resolution parameter.
   441  // safeSearch - filter videos for adult content. The following are the possible filter values. Off: If the
   442  // request is through the Video Search API, the response includes adult videos and the thumbnail images of the
   443  // videos are clear (non-fuzzy). If the request is through the Web Search API, the response includes adult
   444  // videos but the thumbnail images of the videos are pixelated (fuzzy). Moderate: If the request is through the
   445  // Video Search API, the response does not include videos with adult content. If the request is through the Web
   446  // Search API, the response may include videos with adult content but the thumbnail images of the videos are
   447  // pixelated (fuzzy). Strict: Does not return videos with adult content. The default is Moderate. If the
   448  // request comes from a market that Bing's adult policy requires that safeSearch is set to Strict, Bing ignores
   449  // the safeSearch value and uses Strict. If you use the site: query operator, there is the chance that the
   450  // response may contain adult content regardless of what the safeSearch query parameter is set to. Use site:
   451  // only if you are aware of the content on the site and your scenario supports the possibility of adult
   452  // content.
   453  // setLang - the language to use for user interface strings. Specify the language using the ISO 639-1 2-letter
   454  // language code. For example, the language code for English is EN. The default is EN (English). Although
   455  // optional, you should always specify the language. Typically, you set setLang to the same language specified
   456  // by mkt unless the user wants the user interface strings displayed in a different language. This parameter
   457  // and the
   458  // [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#acceptlanguage)
   459  // header are mutually exclusive; do not specify both. A user interface string is a string that's used as a
   460  // label in a user interface. There are few user interface strings in the JSON response objects. Also, any
   461  // links to Bing.com properties in the response objects apply the specified language.
   462  // textDecorations - a Boolean value that determines whether display strings contain decoration markers such as
   463  // hit highlighting characters. If true, the strings may include markers. The default is false. To specify
   464  // whether to use Unicode characters or HTML tags as the markers, see the
   465  // [textFormat](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#textformat)
   466  // query parameter. For information about hit highlighting, see [Hit
   467  // Highlighting](https://docs.microsoft.com/azure/cognitive-services/bing-news-search/hit-highlighting).
   468  // textFormat - the type of markers to use for text decorations (see the textDecorations query parameter).
   469  // Possible values are Raw—Use Unicode characters to mark content that needs special formatting. The Unicode
   470  // characters are in the range E000 through E019. For example, Bing uses E000 and E001 to mark the beginning
   471  // and end of query terms for hit highlighting. HTML—Use HTML tags to mark content that needs special
   472  // formatting. For example, use <b> tags to highlight query terms in display strings. The default is Raw. For
   473  // display strings that contain escapable HTML characters such as <, >, and &, if textFormat is set to HTML,
   474  // Bing escapes the characters as appropriate (for example, < is escaped to &lt;).
   475  func (client VideosClient) Search(ctx context.Context, query string, acceptLanguage string, userAgent string, clientID string, clientIP string, location string, countryCode string, count *int32, freshness Freshness, ID string, length VideoLength, market string, offset *int32, pricing VideoPricing, resolution VideoResolution, safeSearch SafeSearch, setLang string, textDecorations *bool, textFormat TextFormat) (result Videos, err error) {
   476  	if tracing.IsEnabled() {
   477  		ctx = tracing.StartSpan(ctx, fqdn+"/VideosClient.Search")
   478  		defer func() {
   479  			sc := -1
   480  			if result.Response.Response != nil {
   481  				sc = result.Response.Response.StatusCode
   482  			}
   483  			tracing.EndSpan(ctx, sc, err)
   484  		}()
   485  	}
   486  	req, err := client.SearchPreparer(ctx, query, acceptLanguage, userAgent, clientID, clientIP, location, countryCode, count, freshness, ID, length, market, offset, pricing, resolution, safeSearch, setLang, textDecorations, textFormat)
   487  	if err != nil {
   488  		err = autorest.NewErrorWithError(err, "videosearch.VideosClient", "Search", nil, "Failure preparing request")
   489  		return
   490  	}
   491  
   492  	resp, err := client.SearchSender(req)
   493  	if err != nil {
   494  		result.Response = autorest.Response{Response: resp}
   495  		err = autorest.NewErrorWithError(err, "videosearch.VideosClient", "Search", resp, "Failure sending request")
   496  		return
   497  	}
   498  
   499  	result, err = client.SearchResponder(resp)
   500  	if err != nil {
   501  		err = autorest.NewErrorWithError(err, "videosearch.VideosClient", "Search", resp, "Failure responding to request")
   502  		return
   503  	}
   504  
   505  	return
   506  }
   507  
   508  // SearchPreparer prepares the Search request.
   509  func (client VideosClient) SearchPreparer(ctx context.Context, query string, acceptLanguage string, userAgent string, clientID string, clientIP string, location string, countryCode string, count *int32, freshness Freshness, ID string, length VideoLength, market string, offset *int32, pricing VideoPricing, resolution VideoResolution, safeSearch SafeSearch, setLang string, textDecorations *bool, textFormat TextFormat) (*http.Request, error) {
   510  	urlParameters := map[string]interface{}{
   511  		"Endpoint": client.Endpoint,
   512  	}
   513  
   514  	queryParameters := map[string]interface{}{
   515  		"q": autorest.Encode("query", query),
   516  	}
   517  	if len(countryCode) > 0 {
   518  		queryParameters["cc"] = autorest.Encode("query", countryCode)
   519  	}
   520  	if count != nil {
   521  		queryParameters["count"] = autorest.Encode("query", *count)
   522  	}
   523  	if len(string(freshness)) > 0 {
   524  		queryParameters["freshness"] = autorest.Encode("query", freshness)
   525  	}
   526  	if len(ID) > 0 {
   527  		queryParameters["id"] = autorest.Encode("query", ID)
   528  	}
   529  	if len(string(length)) > 0 {
   530  		queryParameters["length"] = autorest.Encode("query", length)
   531  	}
   532  	if len(market) > 0 {
   533  		queryParameters["mkt"] = autorest.Encode("query", market)
   534  	}
   535  	if offset != nil {
   536  		queryParameters["offset"] = autorest.Encode("query", *offset)
   537  	}
   538  	if len(string(pricing)) > 0 {
   539  		queryParameters["pricing"] = autorest.Encode("query", pricing)
   540  	}
   541  	if len(string(resolution)) > 0 {
   542  		queryParameters["resolution"] = autorest.Encode("query", resolution)
   543  	}
   544  	if len(string(safeSearch)) > 0 {
   545  		queryParameters["safeSearch"] = autorest.Encode("query", safeSearch)
   546  	}
   547  	if len(setLang) > 0 {
   548  		queryParameters["setLang"] = autorest.Encode("query", setLang)
   549  	}
   550  	if textDecorations != nil {
   551  		queryParameters["textDecorations"] = autorest.Encode("query", *textDecorations)
   552  	}
   553  	if len(string(textFormat)) > 0 {
   554  		queryParameters["textFormat"] = autorest.Encode("query", textFormat)
   555  	}
   556  
   557  	preparer := autorest.CreatePreparer(
   558  		autorest.AsGet(),
   559  		autorest.WithCustomBaseURL("{Endpoint}/bing/v7.0", urlParameters),
   560  		autorest.WithPath("/videos/search"),
   561  		autorest.WithQueryParameters(queryParameters),
   562  		autorest.WithHeader("X-BingApis-SDK", "true"))
   563  	if len(acceptLanguage) > 0 {
   564  		preparer = autorest.DecoratePreparer(preparer,
   565  			autorest.WithHeader("Accept-Language", autorest.String(acceptLanguage)))
   566  	}
   567  	if len(userAgent) > 0 {
   568  		preparer = autorest.DecoratePreparer(preparer,
   569  			autorest.WithHeader("User-Agent", autorest.String(userAgent)))
   570  	}
   571  	if len(clientID) > 0 {
   572  		preparer = autorest.DecoratePreparer(preparer,
   573  			autorest.WithHeader("X-MSEdge-ClientID", autorest.String(clientID)))
   574  	}
   575  	if len(clientIP) > 0 {
   576  		preparer = autorest.DecoratePreparer(preparer,
   577  			autorest.WithHeader("X-MSEdge-ClientIP", autorest.String(clientIP)))
   578  	}
   579  	if len(location) > 0 {
   580  		preparer = autorest.DecoratePreparer(preparer,
   581  			autorest.WithHeader("X-Search-Location", autorest.String(location)))
   582  	}
   583  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   584  }
   585  
   586  // SearchSender sends the Search request. The method will close the
   587  // http.Response Body if it receives an error.
   588  func (client VideosClient) SearchSender(req *http.Request) (*http.Response, error) {
   589  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   590  }
   591  
   592  // SearchResponder handles the response to the Search request. The method always
   593  // closes the http.Response Body.
   594  func (client VideosClient) SearchResponder(resp *http.Response) (result Videos, err error) {
   595  	err = autorest.Respond(
   596  		resp,
   597  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   598  		autorest.ByUnmarshallingJSON(&result),
   599  		autorest.ByClosing())
   600  	result.Response = autorest.Response{Response: resp}
   601  	return
   602  }
   603  
   604  // Trending sends the trending request.
   605  // Parameters:
   606  // acceptLanguage - a comma-delimited list of one or more languages to use for user interface strings. The list
   607  // is in decreasing order of preference. For additional information, including expected format, see
   608  // [RFC2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). This header and the
   609  // [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#setlang)
   610  // query parameter are mutually exclusive; do not specify both. If you set this header, you must also specify
   611  // the [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#cc) query
   612  // parameter. To determine the market to return results for, Bing uses the first supported language it finds
   613  // from the list and combines it with the cc parameter value. If the list does not include a supported
   614  // language, Bing finds the closest language and market that supports the request or it uses an aggregated or
   615  // default market for the results. To determine the market that Bing used, see the BingAPIs-Market header. Use
   616  // this header and the cc query parameter only if you specify multiple languages. Otherwise, use the
   617  // [mkt](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#mkt) and
   618  // [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#setlang)
   619  // query parameters. A user interface string is a string that's used as a label in a user interface. There are
   620  // few user interface strings in the JSON response objects. Any links to Bing.com properties in the response
   621  // objects apply the specified language.
   622  // userAgent - the user agent originating the request. Bing uses the user agent to provide mobile users with an
   623  // optimized experience. Although optional, you are encouraged to always specify this header. The user-agent
   624  // should be the same string that any commonly used browser sends. For information about user agents, see [RFC
   625  // 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). The following are examples of user-agent
   626  // strings. Windows Phone: Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0;
   627  // ARM; Touch; NOKIA; Lumia 822). Android: Mozilla / 5.0 (Linux; U; Android 2.3.5; en - us; SCH - I500 Build /
   628  // GINGERBREAD) AppleWebKit / 533.1 (KHTML; like Gecko) Version / 4.0 Mobile Safari / 533.1. iPhone: Mozilla /
   629  // 5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit / 536.26 (KHTML; like Gecko) Mobile / 10B142
   630  // iPhone4; 1 BingWeb / 3.03.1428.20120423. PC: Mozilla / 5.0 (Windows NT 6.3; WOW64; Trident / 7.0; Touch;
   631  // rv:11.0) like Gecko. iPad: Mozilla / 5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit / 537.51.1 (KHTML,
   632  // like Gecko) Version / 7.0 Mobile / 11A465 Safari / 9537.53
   633  // clientID - bing uses this header to provide users with consistent behavior across Bing API calls. Bing often
   634  // flights new features and improvements, and it uses the client ID as a key for assigning traffic on different
   635  // flights. If you do not use the same client ID for a user across multiple requests, then Bing may assign the
   636  // user to multiple conflicting flights. Being assigned to multiple conflicting flights can lead to an
   637  // inconsistent user experience. For example, if the second request has a different flight assignment than the
   638  // first, the experience may be unexpected. Also, Bing can use the client ID to tailor web results to that
   639  // client ID’s search history, providing a richer experience for the user. Bing also uses this header to help
   640  // improve result rankings by analyzing the activity generated by a client ID. The relevance improvements help
   641  // with better quality of results delivered by Bing APIs and in turn enables higher click-through rates for the
   642  // API consumer. IMPORTANT: Although optional, you should consider this header required. Persisting the client
   643  // ID across multiple requests for the same end user and device combination enables 1) the API consumer to
   644  // receive a consistent user experience, and 2) higher click-through rates via better quality of results from
   645  // the Bing APIs. Each user that uses your application on the device must have a unique, Bing generated client
   646  // ID. If you do not include this header in the request, Bing generates an ID and returns it in the
   647  // X-MSEdge-ClientID response header. The only time that you should NOT include this header in a request is the
   648  // first time the user uses your app on that device. Use the client ID for each Bing API request that your app
   649  // makes for this user on the device. Persist the client ID. To persist the ID in a browser app, use a
   650  // persistent HTTP cookie to ensure the ID is used across all sessions. Do not use a session cookie. For other
   651  // apps such as mobile apps, use the device's persistent storage to persist the ID. The next time the user uses
   652  // your app on that device, get the client ID that you persisted. Bing responses may or may not include this
   653  // header. If the response includes this header, capture the client ID and use it for all subsequent Bing
   654  // requests for the user on that device. If you include the X-MSEdge-ClientID, you must not include cookies in
   655  // the request.
   656  // clientIP - the IPv4 or IPv6 address of the client device. The IP address is used to discover the user's
   657  // location. Bing uses the location information to determine safe search behavior. Although optional, you are
   658  // encouraged to always specify this header and the X-Search-Location header. Do not obfuscate the address (for
   659  // example, by changing the last octet to 0). Obfuscating the address results in the location not being
   660  // anywhere near the device's actual location, which may result in Bing serving erroneous results.
   661  // location - a semicolon-delimited list of key/value pairs that describe the client's geographical location.
   662  // Bing uses the location information to determine safe search behavior and to return relevant local content.
   663  // Specify the key/value pair as <key>:<value>. The following are the keys that you use to specify the user's
   664  // location. lat (required): The latitude of the client's location, in degrees. The latitude must be greater
   665  // than or equal to -90.0 and less than or equal to +90.0. Negative values indicate southern latitudes and
   666  // positive values indicate northern latitudes. long (required): The longitude of the client's location, in
   667  // degrees. The longitude must be greater than or equal to -180.0 and less than or equal to +180.0. Negative
   668  // values indicate western longitudes and positive values indicate eastern longitudes. re (required): The
   669  // radius, in meters, which specifies the horizontal accuracy of the coordinates. Pass the value returned by
   670  // the device's location service. Typical values might be 22m for GPS/Wi-Fi, 380m for cell tower triangulation,
   671  // and 18,000m for reverse IP lookup. ts (optional): The UTC UNIX timestamp of when the client was at the
   672  // location. (The UNIX timestamp is the number of seconds since January 1, 1970.) head (optional): The client's
   673  // relative heading or direction of travel. Specify the direction of travel as degrees from 0 through 360,
   674  // counting clockwise relative to true north. Specify this key only if the sp key is nonzero. sp (optional):
   675  // The horizontal velocity (speed), in meters per second, that the client device is traveling. alt (optional):
   676  // The altitude of the client device, in meters. are (optional): The radius, in meters, that specifies the
   677  // vertical accuracy of the coordinates. Specify this key only if you specify the alt key. Although many of the
   678  // keys are optional, the more information that you provide, the more accurate the location results are.
   679  // Although optional, you are encouraged to always specify the user's geographical location. Providing the
   680  // location is especially important if the client's IP address does not accurately reflect the user's physical
   681  // location (for example, if the client uses VPN). For optimal results, you should include this header and the
   682  // X-MSEdge-ClientIP header, but at a minimum, you should include this header.
   683  // countryCode - a 2-character country code of the country where the results come from. This API supports only
   684  // the United States market. If you specify this query parameter, it must be set to us. If you set this
   685  // parameter, you must also specify the Accept-Language header. Bing uses the first supported language it finds
   686  // from the languages list, and combine that language with the country code that you specify to determine the
   687  // market to return results for. If the languages list does not include a supported language, Bing finds the
   688  // closest language and market that supports the request, or it may use an aggregated or default market for the
   689  // results instead of a specified one. You should use this query parameter and the Accept-Language query
   690  // parameter only if you specify multiple languages; otherwise, you should use the mkt and setLang query
   691  // parameters. This parameter and the mkt query parameter are mutually exclusive—do not specify both.
   692  // market - the market where the results come from. Typically, mkt is the country where the user is making the
   693  // request from. However, it could be a different country if the user is not located in a country where Bing
   694  // delivers results. The market must be in the form <language code>-<country code>. For example, en-US. The
   695  // string is case insensitive. For a list of possible market values, see [Market
   696  // Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#market-codes).
   697  // NOTE: If known, you are encouraged to always specify the market. Specifying the market helps Bing route the
   698  // request and return an appropriate and optimal response. If you specify a market that is not listed in
   699  // [Market
   700  // Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#market-codes),
   701  // Bing uses a best fit market code based on an internal mapping that is subject to change. This parameter and
   702  // the [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#cc) query
   703  // parameter are mutually exclusive—do not specify both.
   704  // safeSearch - filter videos for adult content. The following are the possible filter values. Off: If the
   705  // request is through the Video Search API, the response includes adult videos and the thumbnail images of the
   706  // videos are clear (non-fuzzy). If the request is through the Web Search API, the response includes adult
   707  // videos but the thumbnail images of the videos are pixelated (fuzzy). Moderate: If the request is through the
   708  // Video Search API, the response does not include videos with adult content. If the request is through the Web
   709  // Search API, the response may include videos with adult content but the thumbnail images of the videos are
   710  // pixelated (fuzzy). Strict: Does not return videos with adult content. The default is Moderate. If the
   711  // request comes from a market that Bing's adult policy requires that safeSearch is set to Strict, Bing ignores
   712  // the safeSearch value and uses Strict. If you use the site: query operator, there is the chance that the
   713  // response may contain adult content regardless of what the safeSearch query parameter is set to. Use site:
   714  // only if you are aware of the content on the site and your scenario supports the possibility of adult
   715  // content.
   716  // setLang - the language to use for user interface strings. Specify the language using the ISO 639-1 2-letter
   717  // language code. For example, the language code for English is EN. The default is EN (English). Although
   718  // optional, you should always specify the language. Typically, you set setLang to the same language specified
   719  // by mkt unless the user wants the user interface strings displayed in a different language. This parameter
   720  // and the
   721  // [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#acceptlanguage)
   722  // header are mutually exclusive; do not specify both. A user interface string is a string that's used as a
   723  // label in a user interface. There are few user interface strings in the JSON response objects. Also, any
   724  // links to Bing.com properties in the response objects apply the specified language.
   725  // textDecorations - a Boolean value that determines whether display strings contain decoration markers such as
   726  // hit highlighting characters. If true, the strings may include markers. The default is false. To specify
   727  // whether to use Unicode characters or HTML tags as the markers, see the
   728  // [textFormat](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-video-api-v7-reference#textformat)
   729  // query parameter. For information about hit highlighting, see [Hit
   730  // Highlighting](https://docs.microsoft.com/azure/cognitive-services/bing-news-search/hit-highlighting).
   731  // textFormat - the type of markers to use for text decorations (see the textDecorations query parameter).
   732  // Possible values are Raw—Use Unicode characters to mark content that needs special formatting. The Unicode
   733  // characters are in the range E000 through E019. For example, Bing uses E000 and E001 to mark the beginning
   734  // and end of query terms for hit highlighting. HTML—Use HTML tags to mark content that needs special
   735  // formatting. For example, use <b> tags to highlight query terms in display strings. The default is Raw. For
   736  // display strings that contain escapable HTML characters such as <, >, and &, if textFormat is set to HTML,
   737  // Bing escapes the characters as appropriate (for example, < is escaped to &lt;).
   738  func (client VideosClient) Trending(ctx context.Context, acceptLanguage string, userAgent string, clientID string, clientIP string, location string, countryCode string, market string, safeSearch SafeSearch, setLang string, textDecorations *bool, textFormat TextFormat) (result TrendingVideos, err error) {
   739  	if tracing.IsEnabled() {
   740  		ctx = tracing.StartSpan(ctx, fqdn+"/VideosClient.Trending")
   741  		defer func() {
   742  			sc := -1
   743  			if result.Response.Response != nil {
   744  				sc = result.Response.Response.StatusCode
   745  			}
   746  			tracing.EndSpan(ctx, sc, err)
   747  		}()
   748  	}
   749  	req, err := client.TrendingPreparer(ctx, acceptLanguage, userAgent, clientID, clientIP, location, countryCode, market, safeSearch, setLang, textDecorations, textFormat)
   750  	if err != nil {
   751  		err = autorest.NewErrorWithError(err, "videosearch.VideosClient", "Trending", nil, "Failure preparing request")
   752  		return
   753  	}
   754  
   755  	resp, err := client.TrendingSender(req)
   756  	if err != nil {
   757  		result.Response = autorest.Response{Response: resp}
   758  		err = autorest.NewErrorWithError(err, "videosearch.VideosClient", "Trending", resp, "Failure sending request")
   759  		return
   760  	}
   761  
   762  	result, err = client.TrendingResponder(resp)
   763  	if err != nil {
   764  		err = autorest.NewErrorWithError(err, "videosearch.VideosClient", "Trending", resp, "Failure responding to request")
   765  		return
   766  	}
   767  
   768  	return
   769  }
   770  
   771  // TrendingPreparer prepares the Trending request.
   772  func (client VideosClient) TrendingPreparer(ctx context.Context, acceptLanguage string, userAgent string, clientID string, clientIP string, location string, countryCode string, market string, safeSearch SafeSearch, setLang string, textDecorations *bool, textFormat TextFormat) (*http.Request, error) {
   773  	urlParameters := map[string]interface{}{
   774  		"Endpoint": client.Endpoint,
   775  	}
   776  
   777  	queryParameters := map[string]interface{}{}
   778  	if len(countryCode) > 0 {
   779  		queryParameters["cc"] = autorest.Encode("query", countryCode)
   780  	}
   781  	if len(market) > 0 {
   782  		queryParameters["mkt"] = autorest.Encode("query", market)
   783  	}
   784  	if len(string(safeSearch)) > 0 {
   785  		queryParameters["safeSearch"] = autorest.Encode("query", safeSearch)
   786  	}
   787  	if len(setLang) > 0 {
   788  		queryParameters["setLang"] = autorest.Encode("query", setLang)
   789  	}
   790  	if textDecorations != nil {
   791  		queryParameters["textDecorations"] = autorest.Encode("query", *textDecorations)
   792  	}
   793  	if len(string(textFormat)) > 0 {
   794  		queryParameters["textFormat"] = autorest.Encode("query", textFormat)
   795  	}
   796  
   797  	preparer := autorest.CreatePreparer(
   798  		autorest.AsGet(),
   799  		autorest.WithCustomBaseURL("{Endpoint}/bing/v7.0", urlParameters),
   800  		autorest.WithPath("/videos/trending"),
   801  		autorest.WithQueryParameters(queryParameters),
   802  		autorest.WithHeader("X-BingApis-SDK", "true"))
   803  	if len(acceptLanguage) > 0 {
   804  		preparer = autorest.DecoratePreparer(preparer,
   805  			autorest.WithHeader("Accept-Language", autorest.String(acceptLanguage)))
   806  	}
   807  	if len(userAgent) > 0 {
   808  		preparer = autorest.DecoratePreparer(preparer,
   809  			autorest.WithHeader("User-Agent", autorest.String(userAgent)))
   810  	}
   811  	if len(clientID) > 0 {
   812  		preparer = autorest.DecoratePreparer(preparer,
   813  			autorest.WithHeader("X-MSEdge-ClientID", autorest.String(clientID)))
   814  	}
   815  	if len(clientIP) > 0 {
   816  		preparer = autorest.DecoratePreparer(preparer,
   817  			autorest.WithHeader("X-MSEdge-ClientIP", autorest.String(clientIP)))
   818  	}
   819  	if len(location) > 0 {
   820  		preparer = autorest.DecoratePreparer(preparer,
   821  			autorest.WithHeader("X-Search-Location", autorest.String(location)))
   822  	}
   823  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   824  }
   825  
   826  // TrendingSender sends the Trending request. The method will close the
   827  // http.Response Body if it receives an error.
   828  func (client VideosClient) TrendingSender(req *http.Request) (*http.Response, error) {
   829  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   830  }
   831  
   832  // TrendingResponder handles the response to the Trending request. The method always
   833  // closes the http.Response Body.
   834  func (client VideosClient) TrendingResponder(resp *http.Response) (result TrendingVideos, err error) {
   835  	err = autorest.Respond(
   836  		resp,
   837  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   838  		autorest.ByUnmarshallingJSON(&result),
   839  		autorest.ByClosing())
   840  	result.Response = autorest.Response{Response: resp}
   841  	return
   842  }
   843  

View as plain text