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.
 
 
 

493 lines
18 KiB

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