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