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