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.
 
 
 

437 lines
15 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 acceleratedmobilepageurl provides access to the Accelerated Mobile Pages (AMP) URL API.
  6. //
  7. // For product documentation, see: https://developers.google.com/amp/cache/
  8. //
  9. // Creating a client
  10. //
  11. // Usage example:
  12. //
  13. // import "google.golang.org/api/acceleratedmobilepageurl/v1"
  14. // ...
  15. // ctx := context.Background()
  16. // acceleratedmobilepageurlService, err := acceleratedmobilepageurl.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. // acceleratedmobilepageurlService, err := acceleratedmobilepageurl.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. // acceleratedmobilepageurlService, err := acceleratedmobilepageurl.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 acceleratedmobilepageurl // import "google.golang.org/api/acceleratedmobilepageurl/v1"
  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 = "acceleratedmobilepageurl:v1"
  67. const apiName = "acceleratedmobilepageurl"
  68. const apiVersion = "v1"
  69. const basePath = "https://acceleratedmobilepageurl.googleapis.com/"
  70. // NewService creates a new Service.
  71. func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
  72. client, endpoint, err := htransport.NewClient(ctx, opts...)
  73. if err != nil {
  74. return nil, err
  75. }
  76. s, err := New(client)
  77. if err != nil {
  78. return nil, err
  79. }
  80. if endpoint != "" {
  81. s.BasePath = endpoint
  82. }
  83. return s, nil
  84. }
  85. // New creates a new Service. It uses the provided http.Client for requests.
  86. //
  87. // Deprecated: please use NewService instead.
  88. // To provide a custom HTTP client, use option.WithHTTPClient.
  89. // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
  90. func New(client *http.Client) (*Service, error) {
  91. if client == nil {
  92. return nil, errors.New("client is nil")
  93. }
  94. s := &Service{client: client, BasePath: basePath}
  95. s.AmpUrls = NewAmpUrlsService(s)
  96. return s, nil
  97. }
  98. type Service struct {
  99. client *http.Client
  100. BasePath string // API endpoint base URL
  101. UserAgent string // optional additional User-Agent fragment
  102. AmpUrls *AmpUrlsService
  103. }
  104. func (s *Service) userAgent() string {
  105. if s.UserAgent == "" {
  106. return googleapi.UserAgent
  107. }
  108. return googleapi.UserAgent + " " + s.UserAgent
  109. }
  110. func NewAmpUrlsService(s *Service) *AmpUrlsService {
  111. rs := &AmpUrlsService{s: s}
  112. return rs
  113. }
  114. type AmpUrlsService struct {
  115. s *Service
  116. }
  117. // AmpUrl: AMP URL response for a requested URL.
  118. type AmpUrl struct {
  119. // AmpUrl: The AMP URL pointing to the publisher's web server.
  120. AmpUrl string `json:"ampUrl,omitempty"`
  121. // CdnAmpUrl: The [AMP Cache
  122. // URL](/amp/cache/overview#amp-cache-url-format) pointing to
  123. // the cached document in the Google AMP Cache.
  124. CdnAmpUrl string `json:"cdnAmpUrl,omitempty"`
  125. // OriginalUrl: The original non-AMP URL.
  126. OriginalUrl string `json:"originalUrl,omitempty"`
  127. // ForceSendFields is a list of field names (e.g. "AmpUrl") to
  128. // unconditionally include in API requests. By default, fields with
  129. // empty values are omitted from API requests. However, any non-pointer,
  130. // non-interface field appearing in ForceSendFields will be sent to the
  131. // server regardless of whether the field is empty or not. This may be
  132. // used to include empty fields in Patch requests.
  133. ForceSendFields []string `json:"-"`
  134. // NullFields is a list of field names (e.g. "AmpUrl") to include in API
  135. // requests with the JSON null value. By default, fields with empty
  136. // values are omitted from API requests. However, any field with an
  137. // empty value appearing in NullFields will be sent to the server as
  138. // null. It is an error if a field in this list has a non-empty value.
  139. // This may be used to include null fields in Patch requests.
  140. NullFields []string `json:"-"`
  141. }
  142. func (s *AmpUrl) MarshalJSON() ([]byte, error) {
  143. type NoMethod AmpUrl
  144. raw := NoMethod(*s)
  145. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  146. }
  147. // AmpUrlError: AMP URL Error resource for a requested URL that couldn't
  148. // be found.
  149. type AmpUrlError struct {
  150. // ErrorCode: The error code of an API call.
  151. //
  152. // Possible values:
  153. // "ERROR_CODE_UNSPECIFIED" - Not specified error.
  154. // "INPUT_URL_NOT_FOUND" - Indicates the requested URL is not found in
  155. // the index, possibly because
  156. // it's unable to be found, not able to be accessed by Googlebot, or
  157. // some
  158. // other error.
  159. // "NO_AMP_URL" - Indicates no AMP URL has been found that corresponds
  160. // to the requested
  161. // URL.
  162. // "APPLICATION_ERROR" - Indicates some kind of application error
  163. // occurred at the server.
  164. // Client advised to retry.
  165. // "URL_IS_VALID_AMP" - DEPRECATED: Indicates the requested URL is a
  166. // valid AMP URL. This is a
  167. // non-error state, should not be relied upon as a sign of success
  168. // or
  169. // failure. It will be removed in future versions of the API.
  170. // "URL_IS_INVALID_AMP" - Indicates that an AMP URL has been found
  171. // that corresponds to the request
  172. // URL, but it is not valid AMP HTML.
  173. ErrorCode string `json:"errorCode,omitempty"`
  174. // ErrorMessage: An optional descriptive error message.
  175. ErrorMessage string `json:"errorMessage,omitempty"`
  176. // OriginalUrl: The original non-AMP URL.
  177. OriginalUrl string `json:"originalUrl,omitempty"`
  178. // ForceSendFields is a list of field names (e.g. "ErrorCode") 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. "ErrorCode") 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 *AmpUrlError) MarshalJSON() ([]byte, error) {
  194. type NoMethod AmpUrlError
  195. raw := NoMethod(*s)
  196. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  197. }
  198. // BatchGetAmpUrlsRequest: AMP URL request for a batch of URLs.
  199. type BatchGetAmpUrlsRequest struct {
  200. // LookupStrategy: The lookup_strategy being requested.
  201. //
  202. // Possible values:
  203. // "FETCH_LIVE_DOC" - FETCH_LIVE_DOC strategy involves live document
  204. // fetch of URLs not found in
  205. // the index. Any request URL not found in the index is crawled in
  206. // realtime
  207. // to validate if there is a corresponding AMP URL. This strategy has
  208. // higher
  209. // coverage but with extra latency introduced by realtime crawling. This
  210. // is
  211. // the default strategy. Applications using this strategy should set
  212. // higher
  213. // HTTP timeouts of the API calls.
  214. // "IN_INDEX_DOC" - IN_INDEX_DOC strategy skips fetching live
  215. // documents of URL(s) not found
  216. // in index. For applications which need low latency use of
  217. // IN_INDEX_DOC
  218. // strategy is recommended.
  219. LookupStrategy string `json:"lookupStrategy,omitempty"`
  220. // Urls: List of URLs to look up for the paired AMP URLs.
  221. // The URLs are case-sensitive. Up to 50 URLs per lookup
  222. // (see [Usage Limits](/amp/cache/reference/limits)).
  223. Urls []string `json:"urls,omitempty"`
  224. // ForceSendFields is a list of field names (e.g. "LookupStrategy") to
  225. // unconditionally include in API requests. By default, fields with
  226. // empty values are omitted from API requests. However, any non-pointer,
  227. // non-interface field appearing in ForceSendFields will be sent to the
  228. // server regardless of whether the field is empty or not. This may be
  229. // used to include empty fields in Patch requests.
  230. ForceSendFields []string `json:"-"`
  231. // NullFields is a list of field names (e.g. "LookupStrategy") to
  232. // include in API requests with the JSON null value. By default, fields
  233. // with empty values are omitted from API requests. However, any field
  234. // with an empty value appearing in NullFields will be sent to the
  235. // server as null. It is an error if a field in this list has a
  236. // non-empty value. This may be used to include null fields in Patch
  237. // requests.
  238. NullFields []string `json:"-"`
  239. }
  240. func (s *BatchGetAmpUrlsRequest) MarshalJSON() ([]byte, error) {
  241. type NoMethod BatchGetAmpUrlsRequest
  242. raw := NoMethod(*s)
  243. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  244. }
  245. // BatchGetAmpUrlsResponse: Batch AMP URL response.
  246. type BatchGetAmpUrlsResponse struct {
  247. // AmpUrls: For each URL in BatchAmpUrlsRequest, the URL response. The
  248. // response might
  249. // not be in the same order as URLs in the batch request.
  250. // If BatchAmpUrlsRequest contains duplicate URLs, AmpUrl is
  251. // generated
  252. // only once.
  253. AmpUrls []*AmpUrl `json:"ampUrls,omitempty"`
  254. // UrlErrors: The errors for requested URLs that have no AMP URL.
  255. UrlErrors []*AmpUrlError `json:"urlErrors,omitempty"`
  256. // ServerResponse contains the HTTP response code and headers from the
  257. // server.
  258. googleapi.ServerResponse `json:"-"`
  259. // ForceSendFields is a list of field names (e.g. "AmpUrls") to
  260. // unconditionally include in API requests. By default, fields with
  261. // empty values are omitted from API requests. However, any non-pointer,
  262. // non-interface field appearing in ForceSendFields will be sent to the
  263. // server regardless of whether the field is empty or not. This may be
  264. // used to include empty fields in Patch requests.
  265. ForceSendFields []string `json:"-"`
  266. // NullFields is a list of field names (e.g. "AmpUrls") to include in
  267. // API requests with the JSON null value. By default, fields with empty
  268. // values are omitted from API requests. However, any field with an
  269. // empty value appearing in NullFields will be sent to the server as
  270. // null. It is an error if a field in this list has a non-empty value.
  271. // This may be used to include null fields in Patch requests.
  272. NullFields []string `json:"-"`
  273. }
  274. func (s *BatchGetAmpUrlsResponse) MarshalJSON() ([]byte, error) {
  275. type NoMethod BatchGetAmpUrlsResponse
  276. raw := NoMethod(*s)
  277. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  278. }
  279. // method id "acceleratedmobilepageurl.ampUrls.batchGet":
  280. type AmpUrlsBatchGetCall struct {
  281. s *Service
  282. batchgetampurlsrequest *BatchGetAmpUrlsRequest
  283. urlParams_ gensupport.URLParams
  284. ctx_ context.Context
  285. header_ http.Header
  286. }
  287. // BatchGet: Returns AMP URL(s) and equivalent
  288. // [AMP Cache URL(s)](/amp/cache/overview#amp-cache-url-format).
  289. func (r *AmpUrlsService) BatchGet(batchgetampurlsrequest *BatchGetAmpUrlsRequest) *AmpUrlsBatchGetCall {
  290. c := &AmpUrlsBatchGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  291. c.batchgetampurlsrequest = batchgetampurlsrequest
  292. return c
  293. }
  294. // Fields allows partial responses to be retrieved. See
  295. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  296. // for more information.
  297. func (c *AmpUrlsBatchGetCall) Fields(s ...googleapi.Field) *AmpUrlsBatchGetCall {
  298. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  299. return c
  300. }
  301. // Context sets the context to be used in this call's Do method. Any
  302. // pending HTTP request will be aborted if the provided context is
  303. // canceled.
  304. func (c *AmpUrlsBatchGetCall) Context(ctx context.Context) *AmpUrlsBatchGetCall {
  305. c.ctx_ = ctx
  306. return c
  307. }
  308. // Header returns an http.Header that can be modified by the caller to
  309. // add HTTP headers to the request.
  310. func (c *AmpUrlsBatchGetCall) Header() http.Header {
  311. if c.header_ == nil {
  312. c.header_ = make(http.Header)
  313. }
  314. return c.header_
  315. }
  316. func (c *AmpUrlsBatchGetCall) doRequest(alt string) (*http.Response, error) {
  317. reqHeaders := make(http.Header)
  318. for k, v := range c.header_ {
  319. reqHeaders[k] = v
  320. }
  321. reqHeaders.Set("User-Agent", c.s.userAgent())
  322. var body io.Reader = nil
  323. body, err := googleapi.WithoutDataWrapper.JSONReader(c.batchgetampurlsrequest)
  324. if err != nil {
  325. return nil, err
  326. }
  327. reqHeaders.Set("Content-Type", "application/json")
  328. c.urlParams_.Set("alt", alt)
  329. c.urlParams_.Set("prettyPrint", "false")
  330. urls := googleapi.ResolveRelative(c.s.BasePath, "v1/ampUrls:batchGet")
  331. urls += "?" + c.urlParams_.Encode()
  332. req, err := http.NewRequest("POST", urls, body)
  333. if err != nil {
  334. return nil, err
  335. }
  336. req.Header = reqHeaders
  337. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  338. }
  339. // Do executes the "acceleratedmobilepageurl.ampUrls.batchGet" call.
  340. // Exactly one of *BatchGetAmpUrlsResponse or error will be non-nil. Any
  341. // non-2xx status code is an error. Response headers are in either
  342. // *BatchGetAmpUrlsResponse.ServerResponse.Header or (if a response was
  343. // returned at all) in error.(*googleapi.Error).Header. Use
  344. // googleapi.IsNotModified to check whether the returned error was
  345. // because http.StatusNotModified was returned.
  346. func (c *AmpUrlsBatchGetCall) Do(opts ...googleapi.CallOption) (*BatchGetAmpUrlsResponse, error) {
  347. gensupport.SetOptions(c.urlParams_, opts...)
  348. res, err := c.doRequest("json")
  349. if res != nil && res.StatusCode == http.StatusNotModified {
  350. if res.Body != nil {
  351. res.Body.Close()
  352. }
  353. return nil, &googleapi.Error{
  354. Code: res.StatusCode,
  355. Header: res.Header,
  356. }
  357. }
  358. if err != nil {
  359. return nil, err
  360. }
  361. defer googleapi.CloseBody(res)
  362. if err := googleapi.CheckResponse(res); err != nil {
  363. return nil, err
  364. }
  365. ret := &BatchGetAmpUrlsResponse{
  366. ServerResponse: googleapi.ServerResponse{
  367. Header: res.Header,
  368. HTTPStatusCode: res.StatusCode,
  369. },
  370. }
  371. target := &ret
  372. if err := gensupport.DecodeResponse(target, res); err != nil {
  373. return nil, err
  374. }
  375. return ret, nil
  376. // {
  377. // "description": "Returns AMP URL(s) and equivalent\n[AMP Cache URL(s)](/amp/cache/overview#amp-cache-url-format).",
  378. // "flatPath": "v1/ampUrls:batchGet",
  379. // "httpMethod": "POST",
  380. // "id": "acceleratedmobilepageurl.ampUrls.batchGet",
  381. // "parameterOrder": [],
  382. // "parameters": {},
  383. // "path": "v1/ampUrls:batchGet",
  384. // "request": {
  385. // "$ref": "BatchGetAmpUrlsRequest"
  386. // },
  387. // "response": {
  388. // "$ref": "BatchGetAmpUrlsResponse"
  389. // }
  390. // }
  391. }