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.
 
 
 

383 lines
13 KiB

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