You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

531 lines
18 KiB

  1. // Copyright 2019 Google LLC.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Code generated file. DO NOT EDIT.
  5. // Package indexing provides access to the Indexing API.
  6. //
  7. // For product documentation, see: https://developers.google.com/search/apis/indexing-api/
  8. //
  9. // Creating a client
  10. //
  11. // Usage example:
  12. //
  13. // import "google.golang.org/api/indexing/v3"
  14. // ...
  15. // ctx := context.Background()
  16. // indexingService, err := indexing.NewService(ctx)
  17. //
  18. // In this example, Google Application Default Credentials are used for authentication.
  19. //
  20. // For information on how to create and obtain Application Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.
  21. //
  22. // Other authentication options
  23. //
  24. // To use an API key for authentication (note: some APIs do not support API keys), use option.WithAPIKey:
  25. //
  26. // indexingService, err := indexing.NewService(ctx, option.WithAPIKey("AIza..."))
  27. //
  28. // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth flow), use option.WithTokenSource:
  29. //
  30. // config := &oauth2.Config{...}
  31. // // ...
  32. // token, err := config.Exchange(ctx, ...)
  33. // indexingService, err := indexing.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
  34. //
  35. // See https://godoc.org/google.golang.org/api/option/ for details on options.
  36. package indexing // import "google.golang.org/api/indexing/v3"
  37. import (
  38. "bytes"
  39. "context"
  40. "encoding/json"
  41. "errors"
  42. "fmt"
  43. "io"
  44. "net/http"
  45. "net/url"
  46. "strconv"
  47. "strings"
  48. gensupport "google.golang.org/api/gensupport"
  49. googleapi "google.golang.org/api/googleapi"
  50. option "google.golang.org/api/option"
  51. htransport "google.golang.org/api/transport/http"
  52. )
  53. // Always reference these packages, just in case the auto-generated code
  54. // below doesn't.
  55. var _ = bytes.NewBuffer
  56. var _ = strconv.Itoa
  57. var _ = fmt.Sprintf
  58. var _ = json.NewDecoder
  59. var _ = io.Copy
  60. var _ = url.Parse
  61. var _ = gensupport.MarshalJSON
  62. var _ = googleapi.Version
  63. var _ = errors.New
  64. var _ = strings.Replace
  65. var _ = context.Canceled
  66. const apiId = "indexing:v3"
  67. const apiName = "indexing"
  68. const apiVersion = "v3"
  69. const basePath = "https://indexing.googleapis.com/"
  70. // OAuth2 scopes used by this API.
  71. const (
  72. // Submit data to Google for indexing
  73. IndexingScope = "https://www.googleapis.com/auth/indexing"
  74. )
  75. // NewService creates a new Service.
  76. func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
  77. scopesOption := option.WithScopes(
  78. "https://www.googleapis.com/auth/indexing",
  79. )
  80. // NOTE: prepend, so we don't override user-specified scopes.
  81. opts = append([]option.ClientOption{scopesOption}, opts...)
  82. client, endpoint, err := htransport.NewClient(ctx, opts...)
  83. if err != nil {
  84. return nil, err
  85. }
  86. s, err := New(client)
  87. if err != nil {
  88. return nil, err
  89. }
  90. if endpoint != "" {
  91. s.BasePath = endpoint
  92. }
  93. return s, nil
  94. }
  95. // New creates a new Service. It uses the provided http.Client for requests.
  96. //
  97. // Deprecated: please use NewService instead.
  98. // To provide a custom HTTP client, use option.WithHTTPClient.
  99. // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
  100. func New(client *http.Client) (*Service, error) {
  101. if client == nil {
  102. return nil, errors.New("client is nil")
  103. }
  104. s := &Service{client: client, BasePath: basePath}
  105. s.UrlNotifications = NewUrlNotificationsService(s)
  106. return s, nil
  107. }
  108. type Service struct {
  109. client *http.Client
  110. BasePath string // API endpoint base URL
  111. UserAgent string // optional additional User-Agent fragment
  112. UrlNotifications *UrlNotificationsService
  113. }
  114. func (s *Service) userAgent() string {
  115. if s.UserAgent == "" {
  116. return googleapi.UserAgent
  117. }
  118. return googleapi.UserAgent + " " + s.UserAgent
  119. }
  120. func NewUrlNotificationsService(s *Service) *UrlNotificationsService {
  121. rs := &UrlNotificationsService{s: s}
  122. return rs
  123. }
  124. type UrlNotificationsService struct {
  125. s *Service
  126. }
  127. // PublishUrlNotificationResponse: Output for PublishUrlNotification
  128. type PublishUrlNotificationResponse struct {
  129. // UrlNotificationMetadata: Description of the notification events
  130. // received for this URL.
  131. UrlNotificationMetadata *UrlNotificationMetadata `json:"urlNotificationMetadata,omitempty"`
  132. // ServerResponse contains the HTTP response code and headers from the
  133. // server.
  134. googleapi.ServerResponse `json:"-"`
  135. // ForceSendFields is a list of field names (e.g.
  136. // "UrlNotificationMetadata") to unconditionally include in API
  137. // requests. By default, fields with empty values are omitted from API
  138. // requests. However, any non-pointer, non-interface field appearing in
  139. // ForceSendFields will be sent to the server regardless of whether the
  140. // field is empty or not. This may be used to include empty fields in
  141. // Patch requests.
  142. ForceSendFields []string `json:"-"`
  143. // NullFields is a list of field names (e.g. "UrlNotificationMetadata")
  144. // to include in API requests with the JSON null value. By default,
  145. // fields with empty values are omitted from API requests. However, any
  146. // field with an empty value appearing in NullFields will be sent to the
  147. // server as null. It is an error if a field in this list has a
  148. // non-empty value. This may be used to include null fields in Patch
  149. // requests.
  150. NullFields []string `json:"-"`
  151. }
  152. func (s *PublishUrlNotificationResponse) MarshalJSON() ([]byte, error) {
  153. type NoMethod PublishUrlNotificationResponse
  154. raw := NoMethod(*s)
  155. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  156. }
  157. // UrlNotification: `UrlNotification` is the resource used in all
  158. // Indexing API calls.
  159. // It describes one event in the life cycle of a Web Document.
  160. type UrlNotification struct {
  161. // NotifyTime: Creation timestamp for this notification.
  162. // Users should _not_ specify it, the field is ignored at the request
  163. // time.
  164. NotifyTime string `json:"notifyTime,omitempty"`
  165. // Type: The URL life cycle event that Google is being notified about.
  166. //
  167. // Possible values:
  168. // "URL_NOTIFICATION_TYPE_UNSPECIFIED" - Unspecified.
  169. // "URL_UPDATED" - The given URL (Web document) has been updated.
  170. // "URL_DELETED" - The given URL (Web document) has been deleted.
  171. Type string `json:"type,omitempty"`
  172. // Url: The object of this notification. The URL must be owned by the
  173. // publisher
  174. // of this notification and, in case of `URL_UPDATED` notifications, it
  175. // _must_
  176. // be crawlable by Google.
  177. Url string `json:"url,omitempty"`
  178. // ForceSendFields is a list of field names (e.g. "NotifyTime") to
  179. // unconditionally include in API requests. By default, fields with
  180. // empty values are omitted from API requests. However, any non-pointer,
  181. // non-interface field appearing in ForceSendFields will be sent to the
  182. // server regardless of whether the field is empty or not. This may be
  183. // used to include empty fields in Patch requests.
  184. ForceSendFields []string `json:"-"`
  185. // NullFields is a list of field names (e.g. "NotifyTime") to include in
  186. // API requests with the JSON null value. By default, fields with empty
  187. // values are omitted from API requests. However, any field with an
  188. // empty value appearing in NullFields will be sent to the server as
  189. // null. It is an error if a field in this list has a non-empty value.
  190. // This may be used to include null fields in Patch requests.
  191. NullFields []string `json:"-"`
  192. }
  193. func (s *UrlNotification) MarshalJSON() ([]byte, error) {
  194. type NoMethod UrlNotification
  195. raw := NoMethod(*s)
  196. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  197. }
  198. // UrlNotificationMetadata: Summary of the most recent Indexing API
  199. // notifications successfully received,
  200. // for a given URL.
  201. type UrlNotificationMetadata struct {
  202. // LatestRemove: Latest notification received with type `URL_REMOVED`.
  203. LatestRemove *UrlNotification `json:"latestRemove,omitempty"`
  204. // LatestUpdate: Latest notification received with type `URL_UPDATED`.
  205. LatestUpdate *UrlNotification `json:"latestUpdate,omitempty"`
  206. // Url: URL to which this metadata refers.
  207. Url string `json:"url,omitempty"`
  208. // ServerResponse contains the HTTP response code and headers from the
  209. // server.
  210. googleapi.ServerResponse `json:"-"`
  211. // ForceSendFields is a list of field names (e.g. "LatestRemove") to
  212. // unconditionally include in API requests. By default, fields with
  213. // empty values are omitted from API requests. However, any non-pointer,
  214. // non-interface field appearing in ForceSendFields will be sent to the
  215. // server regardless of whether the field is empty or not. This may be
  216. // used to include empty fields in Patch requests.
  217. ForceSendFields []string `json:"-"`
  218. // NullFields is a list of field names (e.g. "LatestRemove") to include
  219. // in API requests with the JSON null value. By default, fields with
  220. // empty values are omitted from API requests. However, any field with
  221. // an empty value appearing in NullFields will be sent to the server as
  222. // null. It is an error if a field in this list has a non-empty value.
  223. // This may be used to include null fields in Patch requests.
  224. NullFields []string `json:"-"`
  225. }
  226. func (s *UrlNotificationMetadata) MarshalJSON() ([]byte, error) {
  227. type NoMethod UrlNotificationMetadata
  228. raw := NoMethod(*s)
  229. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  230. }
  231. // method id "indexing.urlNotifications.getMetadata":
  232. type UrlNotificationsGetMetadataCall struct {
  233. s *Service
  234. urlParams_ gensupport.URLParams
  235. ifNoneMatch_ string
  236. ctx_ context.Context
  237. header_ http.Header
  238. }
  239. // GetMetadata: Gets metadata about a Web Document. This method can
  240. // _only_ be used to query
  241. // URLs that were previously seen in successful Indexing API
  242. // notifications.
  243. // Includes the latest `UrlNotification` received via this API.
  244. func (r *UrlNotificationsService) GetMetadata() *UrlNotificationsGetMetadataCall {
  245. c := &UrlNotificationsGetMetadataCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  246. return c
  247. }
  248. // Url sets the optional parameter "url": URL that is being queried.
  249. func (c *UrlNotificationsGetMetadataCall) Url(url string) *UrlNotificationsGetMetadataCall {
  250. c.urlParams_.Set("url", url)
  251. return c
  252. }
  253. // Fields allows partial responses to be retrieved. See
  254. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  255. // for more information.
  256. func (c *UrlNotificationsGetMetadataCall) Fields(s ...googleapi.Field) *UrlNotificationsGetMetadataCall {
  257. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  258. return c
  259. }
  260. // IfNoneMatch sets the optional parameter which makes the operation
  261. // fail if the object's ETag matches the given value. This is useful for
  262. // getting updates only after the object has changed since the last
  263. // request. Use googleapi.IsNotModified to check whether the response
  264. // error from Do is the result of In-None-Match.
  265. func (c *UrlNotificationsGetMetadataCall) IfNoneMatch(entityTag string) *UrlNotificationsGetMetadataCall {
  266. c.ifNoneMatch_ = entityTag
  267. return c
  268. }
  269. // Context sets the context to be used in this call's Do method. Any
  270. // pending HTTP request will be aborted if the provided context is
  271. // canceled.
  272. func (c *UrlNotificationsGetMetadataCall) Context(ctx context.Context) *UrlNotificationsGetMetadataCall {
  273. c.ctx_ = ctx
  274. return c
  275. }
  276. // Header returns an http.Header that can be modified by the caller to
  277. // add HTTP headers to the request.
  278. func (c *UrlNotificationsGetMetadataCall) Header() http.Header {
  279. if c.header_ == nil {
  280. c.header_ = make(http.Header)
  281. }
  282. return c.header_
  283. }
  284. func (c *UrlNotificationsGetMetadataCall) doRequest(alt string) (*http.Response, error) {
  285. reqHeaders := make(http.Header)
  286. for k, v := range c.header_ {
  287. reqHeaders[k] = v
  288. }
  289. reqHeaders.Set("User-Agent", c.s.userAgent())
  290. if c.ifNoneMatch_ != "" {
  291. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  292. }
  293. var body io.Reader = nil
  294. c.urlParams_.Set("alt", alt)
  295. c.urlParams_.Set("prettyPrint", "false")
  296. urls := googleapi.ResolveRelative(c.s.BasePath, "v3/urlNotifications/metadata")
  297. urls += "?" + c.urlParams_.Encode()
  298. req, err := http.NewRequest("GET", urls, body)
  299. if err != nil {
  300. return nil, err
  301. }
  302. req.Header = reqHeaders
  303. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  304. }
  305. // Do executes the "indexing.urlNotifications.getMetadata" call.
  306. // Exactly one of *UrlNotificationMetadata or error will be non-nil. Any
  307. // non-2xx status code is an error. Response headers are in either
  308. // *UrlNotificationMetadata.ServerResponse.Header or (if a response was
  309. // returned at all) in error.(*googleapi.Error).Header. Use
  310. // googleapi.IsNotModified to check whether the returned error was
  311. // because http.StatusNotModified was returned.
  312. func (c *UrlNotificationsGetMetadataCall) Do(opts ...googleapi.CallOption) (*UrlNotificationMetadata, error) {
  313. gensupport.SetOptions(c.urlParams_, opts...)
  314. res, err := c.doRequest("json")
  315. if res != nil && res.StatusCode == http.StatusNotModified {
  316. if res.Body != nil {
  317. res.Body.Close()
  318. }
  319. return nil, &googleapi.Error{
  320. Code: res.StatusCode,
  321. Header: res.Header,
  322. }
  323. }
  324. if err != nil {
  325. return nil, err
  326. }
  327. defer googleapi.CloseBody(res)
  328. if err := googleapi.CheckResponse(res); err != nil {
  329. return nil, err
  330. }
  331. ret := &UrlNotificationMetadata{
  332. ServerResponse: googleapi.ServerResponse{
  333. Header: res.Header,
  334. HTTPStatusCode: res.StatusCode,
  335. },
  336. }
  337. target := &ret
  338. if err := gensupport.DecodeResponse(target, res); err != nil {
  339. return nil, err
  340. }
  341. return ret, nil
  342. // {
  343. // "description": "Gets metadata about a Web Document. This method can _only_ be used to query\nURLs that were previously seen in successful Indexing API notifications.\nIncludes the latest `UrlNotification` received via this API.",
  344. // "flatPath": "v3/urlNotifications/metadata",
  345. // "httpMethod": "GET",
  346. // "id": "indexing.urlNotifications.getMetadata",
  347. // "parameterOrder": [],
  348. // "parameters": {
  349. // "url": {
  350. // "description": "URL that is being queried.",
  351. // "location": "query",
  352. // "type": "string"
  353. // }
  354. // },
  355. // "path": "v3/urlNotifications/metadata",
  356. // "response": {
  357. // "$ref": "UrlNotificationMetadata"
  358. // },
  359. // "scopes": [
  360. // "https://www.googleapis.com/auth/indexing"
  361. // ]
  362. // }
  363. }
  364. // method id "indexing.urlNotifications.publish":
  365. type UrlNotificationsPublishCall struct {
  366. s *Service
  367. urlnotification *UrlNotification
  368. urlParams_ gensupport.URLParams
  369. ctx_ context.Context
  370. header_ http.Header
  371. }
  372. // Publish: Notifies that a URL has been updated or deleted.
  373. func (r *UrlNotificationsService) Publish(urlnotification *UrlNotification) *UrlNotificationsPublishCall {
  374. c := &UrlNotificationsPublishCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  375. c.urlnotification = urlnotification
  376. return c
  377. }
  378. // Fields allows partial responses to be retrieved. See
  379. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  380. // for more information.
  381. func (c *UrlNotificationsPublishCall) Fields(s ...googleapi.Field) *UrlNotificationsPublishCall {
  382. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  383. return c
  384. }
  385. // Context sets the context to be used in this call's Do method. Any
  386. // pending HTTP request will be aborted if the provided context is
  387. // canceled.
  388. func (c *UrlNotificationsPublishCall) Context(ctx context.Context) *UrlNotificationsPublishCall {
  389. c.ctx_ = ctx
  390. return c
  391. }
  392. // Header returns an http.Header that can be modified by the caller to
  393. // add HTTP headers to the request.
  394. func (c *UrlNotificationsPublishCall) Header() http.Header {
  395. if c.header_ == nil {
  396. c.header_ = make(http.Header)
  397. }
  398. return c.header_
  399. }
  400. func (c *UrlNotificationsPublishCall) doRequest(alt string) (*http.Response, error) {
  401. reqHeaders := make(http.Header)
  402. for k, v := range c.header_ {
  403. reqHeaders[k] = v
  404. }
  405. reqHeaders.Set("User-Agent", c.s.userAgent())
  406. var body io.Reader = nil
  407. body, err := googleapi.WithoutDataWrapper.JSONReader(c.urlnotification)
  408. if err != nil {
  409. return nil, err
  410. }
  411. reqHeaders.Set("Content-Type", "application/json")
  412. c.urlParams_.Set("alt", alt)
  413. c.urlParams_.Set("prettyPrint", "false")
  414. urls := googleapi.ResolveRelative(c.s.BasePath, "v3/urlNotifications:publish")
  415. urls += "?" + c.urlParams_.Encode()
  416. req, err := http.NewRequest("POST", urls, body)
  417. if err != nil {
  418. return nil, err
  419. }
  420. req.Header = reqHeaders
  421. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  422. }
  423. // Do executes the "indexing.urlNotifications.publish" call.
  424. // Exactly one of *PublishUrlNotificationResponse or error will be
  425. // non-nil. Any non-2xx status code is an error. Response headers are in
  426. // either *PublishUrlNotificationResponse.ServerResponse.Header or (if a
  427. // response was returned at all) in error.(*googleapi.Error).Header. Use
  428. // googleapi.IsNotModified to check whether the returned error was
  429. // because http.StatusNotModified was returned.
  430. func (c *UrlNotificationsPublishCall) Do(opts ...googleapi.CallOption) (*PublishUrlNotificationResponse, error) {
  431. gensupport.SetOptions(c.urlParams_, opts...)
  432. res, err := c.doRequest("json")
  433. if res != nil && res.StatusCode == http.StatusNotModified {
  434. if res.Body != nil {
  435. res.Body.Close()
  436. }
  437. return nil, &googleapi.Error{
  438. Code: res.StatusCode,
  439. Header: res.Header,
  440. }
  441. }
  442. if err != nil {
  443. return nil, err
  444. }
  445. defer googleapi.CloseBody(res)
  446. if err := googleapi.CheckResponse(res); err != nil {
  447. return nil, err
  448. }
  449. ret := &PublishUrlNotificationResponse{
  450. ServerResponse: googleapi.ServerResponse{
  451. Header: res.Header,
  452. HTTPStatusCode: res.StatusCode,
  453. },
  454. }
  455. target := &ret
  456. if err := gensupport.DecodeResponse(target, res); err != nil {
  457. return nil, err
  458. }
  459. return ret, nil
  460. // {
  461. // "description": "Notifies that a URL has been updated or deleted.",
  462. // "flatPath": "v3/urlNotifications:publish",
  463. // "httpMethod": "POST",
  464. // "id": "indexing.urlNotifications.publish",
  465. // "parameterOrder": [],
  466. // "parameters": {},
  467. // "path": "v3/urlNotifications:publish",
  468. // "request": {
  469. // "$ref": "UrlNotification"
  470. // },
  471. // "response": {
  472. // "$ref": "PublishUrlNotificationResponse"
  473. // },
  474. // "scopes": [
  475. // "https://www.googleapis.com/auth/indexing"
  476. // ]
  477. // }
  478. }