您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

547 行
20 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 searchconsole provides access to the Google Search Console URL Testing Tools API.
  6. //
  7. // For product documentation, see: https://developers.google.com/webmaster-tools/search-console-api/
  8. //
  9. // Creating a client
  10. //
  11. // Usage example:
  12. //
  13. // import "google.golang.org/api/searchconsole/v1"
  14. // ...
  15. // ctx := context.Background()
  16. // searchconsoleService, err := searchconsole.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. // searchconsoleService, err := searchconsole.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. // searchconsoleService, err := searchconsole.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 searchconsole // import "google.golang.org/api/searchconsole/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 = "searchconsole:v1"
  67. const apiName = "searchconsole"
  68. const apiVersion = "v1"
  69. const basePath = "https://searchconsole.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.UrlTestingTools = NewUrlTestingToolsService(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. UrlTestingTools *UrlTestingToolsService
  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 NewUrlTestingToolsService(s *Service) *UrlTestingToolsService {
  111. rs := &UrlTestingToolsService{s: s}
  112. rs.MobileFriendlyTest = NewUrlTestingToolsMobileFriendlyTestService(s)
  113. return rs
  114. }
  115. type UrlTestingToolsService struct {
  116. s *Service
  117. MobileFriendlyTest *UrlTestingToolsMobileFriendlyTestService
  118. }
  119. func NewUrlTestingToolsMobileFriendlyTestService(s *Service) *UrlTestingToolsMobileFriendlyTestService {
  120. rs := &UrlTestingToolsMobileFriendlyTestService{s: s}
  121. return rs
  122. }
  123. type UrlTestingToolsMobileFriendlyTestService struct {
  124. s *Service
  125. }
  126. // BlockedResource: Blocked resource.
  127. type BlockedResource struct {
  128. // Url: URL of the blocked resource.
  129. Url string `json:"url,omitempty"`
  130. // ForceSendFields is a list of field names (e.g. "Url") to
  131. // unconditionally include in API requests. By default, fields with
  132. // empty values are omitted from API requests. However, any non-pointer,
  133. // non-interface field appearing in ForceSendFields will be sent to the
  134. // server regardless of whether the field is empty or not. This may be
  135. // used to include empty fields in Patch requests.
  136. ForceSendFields []string `json:"-"`
  137. // NullFields is a list of field names (e.g. "Url") to include in API
  138. // requests with the JSON null value. By default, fields with empty
  139. // values are omitted from API requests. However, any field with an
  140. // empty value appearing in NullFields will be sent to the server as
  141. // null. It is an error if a field in this list has a non-empty value.
  142. // This may be used to include null fields in Patch requests.
  143. NullFields []string `json:"-"`
  144. }
  145. func (s *BlockedResource) MarshalJSON() ([]byte, error) {
  146. type NoMethod BlockedResource
  147. raw := NoMethod(*s)
  148. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  149. }
  150. // Image: Describe image data.
  151. type Image struct {
  152. // Data: Image data in format determined by the mime type. Currently,
  153. // the format
  154. // will always be "image/png", but this might change in the future.
  155. Data string `json:"data,omitempty"`
  156. // MimeType: The mime-type of the image data.
  157. MimeType string `json:"mimeType,omitempty"`
  158. // ForceSendFields is a list of field names (e.g. "Data") to
  159. // unconditionally include in API requests. By default, fields with
  160. // empty values are omitted from API requests. However, any non-pointer,
  161. // non-interface field appearing in ForceSendFields will be sent to the
  162. // server regardless of whether the field is empty or not. This may be
  163. // used to include empty fields in Patch requests.
  164. ForceSendFields []string `json:"-"`
  165. // NullFields is a list of field names (e.g. "Data") to include in API
  166. // requests with the JSON null value. By default, fields with empty
  167. // values are omitted from API requests. However, any field with an
  168. // empty value appearing in NullFields will be sent to the server as
  169. // null. It is an error if a field in this list has a non-empty value.
  170. // This may be used to include null fields in Patch requests.
  171. NullFields []string `json:"-"`
  172. }
  173. func (s *Image) MarshalJSON() ([]byte, error) {
  174. type NoMethod Image
  175. raw := NoMethod(*s)
  176. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  177. }
  178. // MobileFriendlyIssue: Mobile-friendly issue.
  179. type MobileFriendlyIssue struct {
  180. // Rule: Rule violated.
  181. //
  182. // Possible values:
  183. // "MOBILE_FRIENDLY_RULE_UNSPECIFIED" - Unknown rule. Sorry, we don't
  184. // have any description for the rule that was
  185. // broken.
  186. // "USES_INCOMPATIBLE_PLUGINS" - Plugins incompatible with mobile
  187. // devices are being used. [Learn
  188. // more]
  189. // (https://support.google.com/webmasters/answer/6352293#flash_usag
  190. // e).
  191. // "CONFIGURE_VIEWPORT" - Viewsport is not specified using the meta
  192. // viewport tag. [Learn
  193. // more]
  194. // (https://support.google.com/webmasters/answer/6352293#viewport_n
  195. // ot_configured).
  196. // "FIXED_WIDTH_VIEWPORT" - Viewport defined to a fixed width. [Learn
  197. // more]
  198. // (https://support.google.com/webmasters/answer/6352293#fixed-widt
  199. // h_viewport).
  200. // "SIZE_CONTENT_TO_VIEWPORT" - Content not sized to viewport. [Learn
  201. // more]
  202. // (https://support.google.com/webmasters/answer/6352293#content_no
  203. // t_sized_to_viewport).
  204. // "USE_LEGIBLE_FONT_SIZES" - Font size is too small for easy reading
  205. // on a small screen. [Learn
  206. // More]
  207. // (https://support.google.com/webmasters/answer/6352293#small_font
  208. // _size).
  209. // "TAP_TARGETS_TOO_CLOSE" - Touch elements are too close to each
  210. // other. [Learn
  211. // more]
  212. // (https://support.google.com/webmasters/answer/6352293#touch_elem
  213. // ents_too_close).
  214. Rule string `json:"rule,omitempty"`
  215. // ForceSendFields is a list of field names (e.g. "Rule") to
  216. // unconditionally include in API requests. By default, fields with
  217. // empty values are omitted from API requests. However, any non-pointer,
  218. // non-interface field appearing in ForceSendFields will be sent to the
  219. // server regardless of whether the field is empty or not. This may be
  220. // used to include empty fields in Patch requests.
  221. ForceSendFields []string `json:"-"`
  222. // NullFields is a list of field names (e.g. "Rule") to include in API
  223. // requests with the JSON null value. By default, fields with empty
  224. // values are omitted from API requests. However, any field with an
  225. // empty value appearing in NullFields will be sent to the server as
  226. // null. It is an error if a field in this list has a non-empty value.
  227. // This may be used to include null fields in Patch requests.
  228. NullFields []string `json:"-"`
  229. }
  230. func (s *MobileFriendlyIssue) MarshalJSON() ([]byte, error) {
  231. type NoMethod MobileFriendlyIssue
  232. raw := NoMethod(*s)
  233. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  234. }
  235. // ResourceIssue: Information about a resource with issue.
  236. type ResourceIssue struct {
  237. // BlockedResource: Describes a blocked resource issue.
  238. BlockedResource *BlockedResource `json:"blockedResource,omitempty"`
  239. // ForceSendFields is a list of field names (e.g. "BlockedResource") to
  240. // unconditionally include in API requests. By default, fields with
  241. // empty values are omitted from API requests. However, any non-pointer,
  242. // non-interface field appearing in ForceSendFields will be sent to the
  243. // server regardless of whether the field is empty or not. This may be
  244. // used to include empty fields in Patch requests.
  245. ForceSendFields []string `json:"-"`
  246. // NullFields is a list of field names (e.g. "BlockedResource") to
  247. // include in API requests with the JSON null value. By default, fields
  248. // with empty values are omitted from API requests. However, any field
  249. // with an empty value appearing in NullFields will be sent to the
  250. // server as null. It is an error if a field in this list has a
  251. // non-empty value. This may be used to include null fields in Patch
  252. // requests.
  253. NullFields []string `json:"-"`
  254. }
  255. func (s *ResourceIssue) MarshalJSON() ([]byte, error) {
  256. type NoMethod ResourceIssue
  257. raw := NoMethod(*s)
  258. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  259. }
  260. // RunMobileFriendlyTestRequest: Mobile-friendly test request.
  261. type RunMobileFriendlyTestRequest struct {
  262. // RequestScreenshot: Whether or not screenshot is requested. Default is
  263. // false.
  264. RequestScreenshot bool `json:"requestScreenshot,omitempty"`
  265. // Url: URL for inspection.
  266. Url string `json:"url,omitempty"`
  267. // ForceSendFields is a list of field names (e.g. "RequestScreenshot")
  268. // to unconditionally include in API requests. By default, fields with
  269. // empty values are omitted from API requests. However, any non-pointer,
  270. // non-interface field appearing in ForceSendFields will be sent to the
  271. // server regardless of whether the field is empty or not. This may be
  272. // used to include empty fields in Patch requests.
  273. ForceSendFields []string `json:"-"`
  274. // NullFields is a list of field names (e.g. "RequestScreenshot") to
  275. // include in API requests with the JSON null value. By default, fields
  276. // with empty values are omitted from API requests. However, any field
  277. // with an empty value appearing in NullFields will be sent to the
  278. // server as null. It is an error if a field in this list has a
  279. // non-empty value. This may be used to include null fields in Patch
  280. // requests.
  281. NullFields []string `json:"-"`
  282. }
  283. func (s *RunMobileFriendlyTestRequest) MarshalJSON() ([]byte, error) {
  284. type NoMethod RunMobileFriendlyTestRequest
  285. raw := NoMethod(*s)
  286. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  287. }
  288. // RunMobileFriendlyTestResponse: Mobile-friendly test response,
  289. // including mobile-friendly issues and resource
  290. // issues.
  291. type RunMobileFriendlyTestResponse struct {
  292. // MobileFriendliness: Test verdict, whether the page is mobile friendly
  293. // or not.
  294. //
  295. // Possible values:
  296. // "MOBILE_FRIENDLY_TEST_RESULT_UNSPECIFIED" - Internal error when
  297. // running this test. Please try running the test again.
  298. // "MOBILE_FRIENDLY" - The page is mobile friendly.
  299. // "NOT_MOBILE_FRIENDLY" - The page is not mobile friendly.
  300. MobileFriendliness string `json:"mobileFriendliness,omitempty"`
  301. // MobileFriendlyIssues: List of mobile-usability issues.
  302. MobileFriendlyIssues []*MobileFriendlyIssue `json:"mobileFriendlyIssues,omitempty"`
  303. // ResourceIssues: Information about embedded resources issues.
  304. ResourceIssues []*ResourceIssue `json:"resourceIssues,omitempty"`
  305. // Screenshot: Screenshot of the requested URL.
  306. Screenshot *Image `json:"screenshot,omitempty"`
  307. // TestStatus: Final state of the test, can be either complete or an
  308. // error.
  309. TestStatus *TestStatus `json:"testStatus,omitempty"`
  310. // ServerResponse contains the HTTP response code and headers from the
  311. // server.
  312. googleapi.ServerResponse `json:"-"`
  313. // ForceSendFields is a list of field names (e.g. "MobileFriendliness")
  314. // to unconditionally include in API requests. By default, fields with
  315. // empty values are omitted from API requests. However, any non-pointer,
  316. // non-interface field appearing in ForceSendFields will be sent to the
  317. // server regardless of whether the field is empty or not. This may be
  318. // used to include empty fields in Patch requests.
  319. ForceSendFields []string `json:"-"`
  320. // NullFields is a list of field names (e.g. "MobileFriendliness") to
  321. // include in API requests with the JSON null value. By default, fields
  322. // with empty values are omitted from API requests. However, any field
  323. // with an empty value appearing in NullFields will be sent to the
  324. // server as null. It is an error if a field in this list has a
  325. // non-empty value. This may be used to include null fields in Patch
  326. // requests.
  327. NullFields []string `json:"-"`
  328. }
  329. func (s *RunMobileFriendlyTestResponse) MarshalJSON() ([]byte, error) {
  330. type NoMethod RunMobileFriendlyTestResponse
  331. raw := NoMethod(*s)
  332. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  333. }
  334. // TestStatus: Final state of the test, including error details if
  335. // necessary.
  336. type TestStatus struct {
  337. // Details: Error details if applicable.
  338. Details string `json:"details,omitempty"`
  339. // Status: Status of the test.
  340. //
  341. // Possible values:
  342. // "TEST_STATUS_UNSPECIFIED" - Internal error when running this test.
  343. // Please try running the test again.
  344. // "COMPLETE" - Inspection has completed without errors.
  345. // "INTERNAL_ERROR" - Inspection terminated in an error state. This
  346. // indicates a problem in
  347. // Google's infrastructure, not a user error. Please try again later.
  348. // "PAGE_UNREACHABLE" - Google can not access the URL because of a
  349. // user error such as a robots.txt
  350. // blockage, a 403 or 500 code etc. Please make sure that the URL
  351. // provided is
  352. // accessible by Googlebot and is not password protected.
  353. Status string `json:"status,omitempty"`
  354. // ForceSendFields is a list of field names (e.g. "Details") to
  355. // unconditionally include in API requests. By default, fields with
  356. // empty values are omitted from API requests. However, any non-pointer,
  357. // non-interface field appearing in ForceSendFields will be sent to the
  358. // server regardless of whether the field is empty or not. This may be
  359. // used to include empty fields in Patch requests.
  360. ForceSendFields []string `json:"-"`
  361. // NullFields is a list of field names (e.g. "Details") to include in
  362. // API requests with the JSON null value. By default, fields with empty
  363. // values are omitted from API requests. However, any field with an
  364. // empty value appearing in NullFields will be sent to the server as
  365. // null. It is an error if a field in this list has a non-empty value.
  366. // This may be used to include null fields in Patch requests.
  367. NullFields []string `json:"-"`
  368. }
  369. func (s *TestStatus) MarshalJSON() ([]byte, error) {
  370. type NoMethod TestStatus
  371. raw := NoMethod(*s)
  372. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  373. }
  374. // method id "searchconsole.urlTestingTools.mobileFriendlyTest.run":
  375. type UrlTestingToolsMobileFriendlyTestRunCall struct {
  376. s *Service
  377. runmobilefriendlytestrequest *RunMobileFriendlyTestRequest
  378. urlParams_ gensupport.URLParams
  379. ctx_ context.Context
  380. header_ http.Header
  381. }
  382. // Run: Runs Mobile-Friendly Test for a given URL.
  383. func (r *UrlTestingToolsMobileFriendlyTestService) Run(runmobilefriendlytestrequest *RunMobileFriendlyTestRequest) *UrlTestingToolsMobileFriendlyTestRunCall {
  384. c := &UrlTestingToolsMobileFriendlyTestRunCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  385. c.runmobilefriendlytestrequest = runmobilefriendlytestrequest
  386. return c
  387. }
  388. // Fields allows partial responses to be retrieved. See
  389. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  390. // for more information.
  391. func (c *UrlTestingToolsMobileFriendlyTestRunCall) Fields(s ...googleapi.Field) *UrlTestingToolsMobileFriendlyTestRunCall {
  392. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  393. return c
  394. }
  395. // Context sets the context to be used in this call's Do method. Any
  396. // pending HTTP request will be aborted if the provided context is
  397. // canceled.
  398. func (c *UrlTestingToolsMobileFriendlyTestRunCall) Context(ctx context.Context) *UrlTestingToolsMobileFriendlyTestRunCall {
  399. c.ctx_ = ctx
  400. return c
  401. }
  402. // Header returns an http.Header that can be modified by the caller to
  403. // add HTTP headers to the request.
  404. func (c *UrlTestingToolsMobileFriendlyTestRunCall) Header() http.Header {
  405. if c.header_ == nil {
  406. c.header_ = make(http.Header)
  407. }
  408. return c.header_
  409. }
  410. func (c *UrlTestingToolsMobileFriendlyTestRunCall) doRequest(alt string) (*http.Response, error) {
  411. reqHeaders := make(http.Header)
  412. for k, v := range c.header_ {
  413. reqHeaders[k] = v
  414. }
  415. reqHeaders.Set("User-Agent", c.s.userAgent())
  416. var body io.Reader = nil
  417. body, err := googleapi.WithoutDataWrapper.JSONReader(c.runmobilefriendlytestrequest)
  418. if err != nil {
  419. return nil, err
  420. }
  421. reqHeaders.Set("Content-Type", "application/json")
  422. c.urlParams_.Set("alt", alt)
  423. c.urlParams_.Set("prettyPrint", "false")
  424. urls := googleapi.ResolveRelative(c.s.BasePath, "v1/urlTestingTools/mobileFriendlyTest:run")
  425. urls += "?" + c.urlParams_.Encode()
  426. req, err := http.NewRequest("POST", urls, body)
  427. if err != nil {
  428. return nil, err
  429. }
  430. req.Header = reqHeaders
  431. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  432. }
  433. // Do executes the "searchconsole.urlTestingTools.mobileFriendlyTest.run" call.
  434. // Exactly one of *RunMobileFriendlyTestResponse or error will be
  435. // non-nil. Any non-2xx status code is an error. Response headers are in
  436. // either *RunMobileFriendlyTestResponse.ServerResponse.Header or (if a
  437. // response was returned at all) in error.(*googleapi.Error).Header. Use
  438. // googleapi.IsNotModified to check whether the returned error was
  439. // because http.StatusNotModified was returned.
  440. func (c *UrlTestingToolsMobileFriendlyTestRunCall) Do(opts ...googleapi.CallOption) (*RunMobileFriendlyTestResponse, error) {
  441. gensupport.SetOptions(c.urlParams_, opts...)
  442. res, err := c.doRequest("json")
  443. if res != nil && res.StatusCode == http.StatusNotModified {
  444. if res.Body != nil {
  445. res.Body.Close()
  446. }
  447. return nil, &googleapi.Error{
  448. Code: res.StatusCode,
  449. Header: res.Header,
  450. }
  451. }
  452. if err != nil {
  453. return nil, err
  454. }
  455. defer googleapi.CloseBody(res)
  456. if err := googleapi.CheckResponse(res); err != nil {
  457. return nil, err
  458. }
  459. ret := &RunMobileFriendlyTestResponse{
  460. ServerResponse: googleapi.ServerResponse{
  461. Header: res.Header,
  462. HTTPStatusCode: res.StatusCode,
  463. },
  464. }
  465. target := &ret
  466. if err := gensupport.DecodeResponse(target, res); err != nil {
  467. return nil, err
  468. }
  469. return ret, nil
  470. // {
  471. // "description": "Runs Mobile-Friendly Test for a given URL.",
  472. // "flatPath": "v1/urlTestingTools/mobileFriendlyTest:run",
  473. // "httpMethod": "POST",
  474. // "id": "searchconsole.urlTestingTools.mobileFriendlyTest.run",
  475. // "parameterOrder": [],
  476. // "parameters": {},
  477. // "path": "v1/urlTestingTools/mobileFriendlyTest:run",
  478. // "request": {
  479. // "$ref": "RunMobileFriendlyTestRequest"
  480. // },
  481. // "response": {
  482. // "$ref": "RunMobileFriendlyTestResponse"
  483. // }
  484. // }
  485. }