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.
 
 
 

898 lines
35 KiB

  1. // Package pagespeedonline provides access to the PageSpeed Insights API.
  2. //
  3. // See https://developers.google.com/speed/docs/insights/v2/getting-started
  4. //
  5. // Usage example:
  6. //
  7. // import "google.golang.org/api/pagespeedonline/v2"
  8. // ...
  9. // pagespeedonlineService, err := pagespeedonline.New(oauthHttpClient)
  10. package pagespeedonline // import "google.golang.org/api/pagespeedonline/v2"
  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 = "pagespeedonline:v2"
  41. const apiName = "pagespeedonline"
  42. const apiVersion = "v2"
  43. const basePath = "https://www.googleapis.com/pagespeedonline/v2/"
  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.Pagespeedapi = NewPagespeedapiService(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. Pagespeedapi *PagespeedapiService
  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 NewPagespeedapiService(s *Service) *PagespeedapiService {
  65. rs := &PagespeedapiService{s: s}
  66. return rs
  67. }
  68. type PagespeedapiService struct {
  69. s *Service
  70. }
  71. type PagespeedApiFormatStringV2 struct {
  72. // Args: List of arguments for the format string.
  73. Args []*PagespeedApiFormatStringV2Args `json:"args,omitempty"`
  74. // Format: A localized format string with {{FOO}} placeholders, where
  75. // 'FOO' is the key of the argument whose value should be substituted.
  76. // For HYPERLINK arguments, the format string will instead contain
  77. // {{BEGIN_FOO}} and {{END_FOO}} for the argument with key 'FOO'.
  78. Format string `json:"format,omitempty"`
  79. // ForceSendFields is a list of field names (e.g. "Args") to
  80. // unconditionally include in API requests. By default, fields with
  81. // empty values are omitted from API requests. However, any non-pointer,
  82. // non-interface field appearing in ForceSendFields will be sent to the
  83. // server regardless of whether the field is empty or not. This may be
  84. // used to include empty fields in Patch requests.
  85. ForceSendFields []string `json:"-"`
  86. // NullFields is a list of field names (e.g. "Args") to include in API
  87. // requests with the JSON null value. By default, fields with empty
  88. // values are omitted from API requests. However, any field with an
  89. // empty value appearing in NullFields will be sent to the server as
  90. // null. It is an error if a field in this list has a non-empty value.
  91. // This may be used to include null fields in Patch requests.
  92. NullFields []string `json:"-"`
  93. }
  94. func (s *PagespeedApiFormatStringV2) MarshalJSON() ([]byte, error) {
  95. type NoMethod PagespeedApiFormatStringV2
  96. raw := NoMethod(*s)
  97. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  98. }
  99. type PagespeedApiFormatStringV2Args struct {
  100. // Key: The placeholder key for this arg, as a string.
  101. Key string `json:"key,omitempty"`
  102. // Rects: The screen rectangles being referred to, with dimensions
  103. // measured in CSS pixels. This is only ever used for SNAPSHOT_RECT
  104. // arguments. If this is absent for a SNAPSHOT_RECT argument, it means
  105. // that that argument refers to the entire snapshot.
  106. Rects []*PagespeedApiFormatStringV2ArgsRects `json:"rects,omitempty"`
  107. // SecondaryRects: Secondary screen rectangles being referred to, with
  108. // dimensions measured in CSS pixels. This is only ever used for
  109. // SNAPSHOT_RECT arguments.
  110. SecondaryRects []*PagespeedApiFormatStringV2ArgsSecondaryRects `json:"secondary_rects,omitempty"`
  111. // Type: Type of argument. One of URL, STRING_LITERAL, INT_LITERAL,
  112. // BYTES, DURATION, VERBATIM_STRING, PERCENTAGE, HYPERLINK, or
  113. // SNAPSHOT_RECT.
  114. Type string `json:"type,omitempty"`
  115. // Value: Argument value, as a localized string.
  116. Value string `json:"value,omitempty"`
  117. // ForceSendFields is a list of field names (e.g. "Key") to
  118. // unconditionally include in API requests. By default, fields with
  119. // empty values are omitted from API requests. However, any non-pointer,
  120. // non-interface field appearing in ForceSendFields will be sent to the
  121. // server regardless of whether the field is empty or not. This may be
  122. // used to include empty fields in Patch requests.
  123. ForceSendFields []string `json:"-"`
  124. // NullFields is a list of field names (e.g. "Key") to include in API
  125. // requests with the JSON null value. By default, fields with empty
  126. // values are omitted from API requests. However, any field with an
  127. // empty value appearing in NullFields will be sent to the server as
  128. // null. It is an error if a field in this list has a non-empty value.
  129. // This may be used to include null fields in Patch requests.
  130. NullFields []string `json:"-"`
  131. }
  132. func (s *PagespeedApiFormatStringV2Args) MarshalJSON() ([]byte, error) {
  133. type NoMethod PagespeedApiFormatStringV2Args
  134. raw := NoMethod(*s)
  135. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  136. }
  137. type PagespeedApiFormatStringV2ArgsRects struct {
  138. // Height: The height of the rect.
  139. Height int64 `json:"height,omitempty"`
  140. // Left: The left coordinate of the rect, in page coordinates.
  141. Left int64 `json:"left,omitempty"`
  142. // Top: The top coordinate of the rect, in page coordinates.
  143. Top int64 `json:"top,omitempty"`
  144. // Width: The width of the rect.
  145. Width int64 `json:"width,omitempty"`
  146. // ForceSendFields is a list of field names (e.g. "Height") to
  147. // unconditionally include in API requests. By default, fields with
  148. // empty values are omitted from API requests. However, any non-pointer,
  149. // non-interface field appearing in ForceSendFields will be sent to the
  150. // server regardless of whether the field is empty or not. This may be
  151. // used to include empty fields in Patch requests.
  152. ForceSendFields []string `json:"-"`
  153. // NullFields is a list of field names (e.g. "Height") to include in API
  154. // requests with the JSON null value. By default, fields with empty
  155. // values are omitted from API requests. However, any field with an
  156. // empty value appearing in NullFields will be sent to the server as
  157. // null. It is an error if a field in this list has a non-empty value.
  158. // This may be used to include null fields in Patch requests.
  159. NullFields []string `json:"-"`
  160. }
  161. func (s *PagespeedApiFormatStringV2ArgsRects) MarshalJSON() ([]byte, error) {
  162. type NoMethod PagespeedApiFormatStringV2ArgsRects
  163. raw := NoMethod(*s)
  164. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  165. }
  166. type PagespeedApiFormatStringV2ArgsSecondaryRects struct {
  167. // Height: The height of the rect.
  168. Height int64 `json:"height,omitempty"`
  169. // Left: The left coordinate of the rect, in page coordinates.
  170. Left int64 `json:"left,omitempty"`
  171. // Top: The top coordinate of the rect, in page coordinates.
  172. Top int64 `json:"top,omitempty"`
  173. // Width: The width of the rect.
  174. Width int64 `json:"width,omitempty"`
  175. // ForceSendFields is a list of field names (e.g. "Height") to
  176. // unconditionally include in API requests. By default, fields with
  177. // empty values are omitted from API requests. However, any non-pointer,
  178. // non-interface field appearing in ForceSendFields will be sent to the
  179. // server regardless of whether the field is empty or not. This may be
  180. // used to include empty fields in Patch requests.
  181. ForceSendFields []string `json:"-"`
  182. // NullFields is a list of field names (e.g. "Height") to include in API
  183. // requests with the JSON null value. By default, fields with empty
  184. // values are omitted from API requests. However, any field with an
  185. // empty value appearing in NullFields will be sent to the server as
  186. // null. It is an error if a field in this list has a non-empty value.
  187. // This may be used to include null fields in Patch requests.
  188. NullFields []string `json:"-"`
  189. }
  190. func (s *PagespeedApiFormatStringV2ArgsSecondaryRects) MarshalJSON() ([]byte, error) {
  191. type NoMethod PagespeedApiFormatStringV2ArgsSecondaryRects
  192. raw := NoMethod(*s)
  193. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  194. }
  195. type PagespeedApiImageV2 struct {
  196. // Data: Image data base64 encoded.
  197. Data string `json:"data,omitempty"`
  198. // Height: Height of screenshot in pixels.
  199. Height int64 `json:"height,omitempty"`
  200. // Key: Unique string key, if any, identifying this image.
  201. Key string `json:"key,omitempty"`
  202. // MimeType: Mime type of image data (e.g. "image/jpeg").
  203. MimeType string `json:"mime_type,omitempty"`
  204. // PageRect: The region of the page that is captured by this image, with
  205. // dimensions measured in CSS pixels.
  206. PageRect *PagespeedApiImageV2PageRect `json:"page_rect,omitempty"`
  207. // Width: Width of screenshot in pixels.
  208. Width int64 `json:"width,omitempty"`
  209. // ForceSendFields is a list of field names (e.g. "Data") to
  210. // unconditionally include in API requests. By default, fields with
  211. // empty values are omitted from API requests. However, any non-pointer,
  212. // non-interface field appearing in ForceSendFields will be sent to the
  213. // server regardless of whether the field is empty or not. This may be
  214. // used to include empty fields in Patch requests.
  215. ForceSendFields []string `json:"-"`
  216. // NullFields is a list of field names (e.g. "Data") to include in API
  217. // requests with the JSON null value. By default, fields with empty
  218. // values are omitted from API requests. However, any field with an
  219. // empty value appearing in NullFields will be sent to the server as
  220. // null. It is an error if a field in this list has a non-empty value.
  221. // This may be used to include null fields in Patch requests.
  222. NullFields []string `json:"-"`
  223. }
  224. func (s *PagespeedApiImageV2) MarshalJSON() ([]byte, error) {
  225. type NoMethod PagespeedApiImageV2
  226. raw := NoMethod(*s)
  227. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  228. }
  229. // PagespeedApiImageV2PageRect: The region of the page that is captured
  230. // by this image, with dimensions measured in CSS pixels.
  231. type PagespeedApiImageV2PageRect struct {
  232. // Height: The height of the rect.
  233. Height int64 `json:"height,omitempty"`
  234. // Left: The left coordinate of the rect, in page coordinates.
  235. Left int64 `json:"left,omitempty"`
  236. // Top: The top coordinate of the rect, in page coordinates.
  237. Top int64 `json:"top,omitempty"`
  238. // Width: The width of the rect.
  239. Width int64 `json:"width,omitempty"`
  240. // ForceSendFields is a list of field names (e.g. "Height") to
  241. // unconditionally include in API requests. By default, fields with
  242. // empty values are omitted from API requests. However, any non-pointer,
  243. // non-interface field appearing in ForceSendFields will be sent to the
  244. // server regardless of whether the field is empty or not. This may be
  245. // used to include empty fields in Patch requests.
  246. ForceSendFields []string `json:"-"`
  247. // NullFields is a list of field names (e.g. "Height") to include in API
  248. // requests with the JSON null value. By default, fields with empty
  249. // values are omitted from API requests. However, any field with an
  250. // empty value appearing in NullFields will be sent to the server as
  251. // null. It is an error if a field in this list has a non-empty value.
  252. // This may be used to include null fields in Patch requests.
  253. NullFields []string `json:"-"`
  254. }
  255. func (s *PagespeedApiImageV2PageRect) MarshalJSON() ([]byte, error) {
  256. type NoMethod PagespeedApiImageV2PageRect
  257. raw := NoMethod(*s)
  258. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  259. }
  260. type Result struct {
  261. // CaptchaResult: The captcha verify result
  262. CaptchaResult string `json:"captchaResult,omitempty"`
  263. // FormattedResults: Localized PageSpeed results. Contains a ruleResults
  264. // entry for each PageSpeed rule instantiated and run by the server.
  265. FormattedResults *ResultFormattedResults `json:"formattedResults,omitempty"`
  266. // Id: Canonicalized and final URL for the document, after following
  267. // page redirects (if any).
  268. Id string `json:"id,omitempty"`
  269. // InvalidRules: List of rules that were specified in the request, but
  270. // which the server did not know how to instantiate.
  271. InvalidRules []string `json:"invalidRules,omitempty"`
  272. // Kind: Kind of result.
  273. Kind string `json:"kind,omitempty"`
  274. // PageStats: Summary statistics for the page, such as number of
  275. // JavaScript bytes, number of HTML bytes, etc.
  276. PageStats *ResultPageStats `json:"pageStats,omitempty"`
  277. // ResponseCode: Response code for the document. 200 indicates a normal
  278. // page load. 4xx/5xx indicates an error.
  279. ResponseCode int64 `json:"responseCode,omitempty"`
  280. // RuleGroups: A map with one entry for each rule group in these
  281. // results.
  282. RuleGroups map[string]ResultRuleGroups `json:"ruleGroups,omitempty"`
  283. // Screenshot: Base64-encoded screenshot of the page that was analyzed.
  284. Screenshot *PagespeedApiImageV2 `json:"screenshot,omitempty"`
  285. // Title: Title of the page, as displayed in the browser's title bar.
  286. Title string `json:"title,omitempty"`
  287. // Version: The version of PageSpeed used to generate these results.
  288. Version *ResultVersion `json:"version,omitempty"`
  289. // ServerResponse contains the HTTP response code and headers from the
  290. // server.
  291. googleapi.ServerResponse `json:"-"`
  292. // ForceSendFields is a list of field names (e.g. "CaptchaResult") to
  293. // unconditionally include in API requests. By default, fields with
  294. // empty values are omitted from API requests. However, any non-pointer,
  295. // non-interface field appearing in ForceSendFields will be sent to the
  296. // server regardless of whether the field is empty or not. This may be
  297. // used to include empty fields in Patch requests.
  298. ForceSendFields []string `json:"-"`
  299. // NullFields is a list of field names (e.g. "CaptchaResult") to include
  300. // in API requests with the JSON null value. By default, fields with
  301. // empty values are omitted from API requests. However, any field with
  302. // an empty value appearing in NullFields will be sent to the server as
  303. // null. It is an error if a field in this list has a non-empty value.
  304. // This may be used to include null fields in Patch requests.
  305. NullFields []string `json:"-"`
  306. }
  307. func (s *Result) MarshalJSON() ([]byte, error) {
  308. type NoMethod Result
  309. raw := NoMethod(*s)
  310. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  311. }
  312. // ResultFormattedResults: Localized PageSpeed results. Contains a
  313. // ruleResults entry for each PageSpeed rule instantiated and run by the
  314. // server.
  315. type ResultFormattedResults struct {
  316. // Locale: The locale of the formattedResults, e.g. "en_US".
  317. Locale string `json:"locale,omitempty"`
  318. // RuleResults: Dictionary of formatted rule results, with one entry for
  319. // each PageSpeed rule instantiated and run by the server.
  320. RuleResults map[string]ResultFormattedResultsRuleResults `json:"ruleResults,omitempty"`
  321. // ForceSendFields is a list of field names (e.g. "Locale") to
  322. // unconditionally include in API requests. By default, fields with
  323. // empty values are omitted from API requests. However, any non-pointer,
  324. // non-interface field appearing in ForceSendFields will be sent to the
  325. // server regardless of whether the field is empty or not. This may be
  326. // used to include empty fields in Patch requests.
  327. ForceSendFields []string `json:"-"`
  328. // NullFields is a list of field names (e.g. "Locale") to include in API
  329. // requests with the JSON null value. By default, fields with empty
  330. // values are omitted from API requests. However, any field with an
  331. // empty value appearing in NullFields will be sent to the server as
  332. // null. It is an error if a field in this list has a non-empty value.
  333. // This may be used to include null fields in Patch requests.
  334. NullFields []string `json:"-"`
  335. }
  336. func (s *ResultFormattedResults) MarshalJSON() ([]byte, error) {
  337. type NoMethod ResultFormattedResults
  338. raw := NoMethod(*s)
  339. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  340. }
  341. // ResultFormattedResultsRuleResults: The enum-like identifier for this
  342. // rule. For instance "EnableKeepAlive" or "AvoidCssImport". Not
  343. // localized.
  344. type ResultFormattedResultsRuleResults struct {
  345. // Groups: List of rule groups that this rule belongs to. Each entry in
  346. // the list is one of "SPEED" or "USABILITY".
  347. Groups []string `json:"groups,omitempty"`
  348. // LocalizedRuleName: Localized name of the rule, intended for
  349. // presentation to a user.
  350. LocalizedRuleName string `json:"localizedRuleName,omitempty"`
  351. // RuleImpact: The impact (unbounded floating point value) that
  352. // implementing the suggestions for this rule would have on making the
  353. // page faster. Impact is comparable between rules to determine which
  354. // rule's suggestions would have a higher or lower impact on making a
  355. // page faster. For instance, if enabling compression would save 1MB,
  356. // while optimizing images would save 500kB, the enable compression rule
  357. // would have 2x the impact of the image optimization rule, all other
  358. // things being equal.
  359. RuleImpact float64 `json:"ruleImpact,omitempty"`
  360. // Summary: A brief summary description for the rule, indicating at a
  361. // high level what should be done to follow the rule and what benefit
  362. // can be gained by doing so.
  363. Summary *PagespeedApiFormatStringV2 `json:"summary,omitempty"`
  364. // UrlBlocks: List of blocks of URLs. Each block may contain a heading
  365. // and a list of URLs. Each URL may optionally include additional
  366. // details.
  367. UrlBlocks []*ResultFormattedResultsRuleResultsUrlBlocks `json:"urlBlocks,omitempty"`
  368. // ForceSendFields is a list of field names (e.g. "Groups") to
  369. // unconditionally include in API requests. By default, fields with
  370. // empty values are omitted from API requests. However, any non-pointer,
  371. // non-interface field appearing in ForceSendFields will be sent to the
  372. // server regardless of whether the field is empty or not. This may be
  373. // used to include empty fields in Patch requests.
  374. ForceSendFields []string `json:"-"`
  375. // NullFields is a list of field names (e.g. "Groups") to include in API
  376. // requests with the JSON null value. By default, fields with empty
  377. // values are omitted from API requests. However, any field with an
  378. // empty value appearing in NullFields will be sent to the server as
  379. // null. It is an error if a field in this list has a non-empty value.
  380. // This may be used to include null fields in Patch requests.
  381. NullFields []string `json:"-"`
  382. }
  383. func (s *ResultFormattedResultsRuleResults) MarshalJSON() ([]byte, error) {
  384. type NoMethod ResultFormattedResultsRuleResults
  385. raw := NoMethod(*s)
  386. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  387. }
  388. func (s *ResultFormattedResultsRuleResults) UnmarshalJSON(data []byte) error {
  389. type NoMethod ResultFormattedResultsRuleResults
  390. var s1 struct {
  391. RuleImpact gensupport.JSONFloat64 `json:"ruleImpact"`
  392. *NoMethod
  393. }
  394. s1.NoMethod = (*NoMethod)(s)
  395. if err := json.Unmarshal(data, &s1); err != nil {
  396. return err
  397. }
  398. s.RuleImpact = float64(s1.RuleImpact)
  399. return nil
  400. }
  401. type ResultFormattedResultsRuleResultsUrlBlocks struct {
  402. // Header: Heading to be displayed with the list of URLs.
  403. Header *PagespeedApiFormatStringV2 `json:"header,omitempty"`
  404. // Urls: List of entries that provide information about URLs in the url
  405. // block. Optional.
  406. Urls []*ResultFormattedResultsRuleResultsUrlBlocksUrls `json:"urls,omitempty"`
  407. // ForceSendFields is a list of field names (e.g. "Header") to
  408. // unconditionally include in API requests. By default, fields with
  409. // empty values are omitted from API requests. However, any non-pointer,
  410. // non-interface field appearing in ForceSendFields will be sent to the
  411. // server regardless of whether the field is empty or not. This may be
  412. // used to include empty fields in Patch requests.
  413. ForceSendFields []string `json:"-"`
  414. // NullFields is a list of field names (e.g. "Header") to include in API
  415. // requests with the JSON null value. By default, fields with empty
  416. // values are omitted from API requests. However, any field with an
  417. // empty value appearing in NullFields will be sent to the server as
  418. // null. It is an error if a field in this list has a non-empty value.
  419. // This may be used to include null fields in Patch requests.
  420. NullFields []string `json:"-"`
  421. }
  422. func (s *ResultFormattedResultsRuleResultsUrlBlocks) MarshalJSON() ([]byte, error) {
  423. type NoMethod ResultFormattedResultsRuleResultsUrlBlocks
  424. raw := NoMethod(*s)
  425. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  426. }
  427. type ResultFormattedResultsRuleResultsUrlBlocksUrls struct {
  428. // Details: List of entries that provide additional details about a
  429. // single URL. Optional.
  430. Details []*PagespeedApiFormatStringV2 `json:"details,omitempty"`
  431. // Result: A format string that gives information about the URL, and a
  432. // list of arguments for that format string.
  433. Result *PagespeedApiFormatStringV2 `json:"result,omitempty"`
  434. // ForceSendFields is a list of field names (e.g. "Details") to
  435. // unconditionally include in API requests. By default, fields with
  436. // empty values are omitted from API requests. However, any non-pointer,
  437. // non-interface field appearing in ForceSendFields will be sent to the
  438. // server regardless of whether the field is empty or not. This may be
  439. // used to include empty fields in Patch requests.
  440. ForceSendFields []string `json:"-"`
  441. // NullFields is a list of field names (e.g. "Details") to include in
  442. // API requests with the JSON null value. By default, fields with empty
  443. // values are omitted from API requests. However, any field with an
  444. // empty value appearing in NullFields will be sent to the server as
  445. // null. It is an error if a field in this list has a non-empty value.
  446. // This may be used to include null fields in Patch requests.
  447. NullFields []string `json:"-"`
  448. }
  449. func (s *ResultFormattedResultsRuleResultsUrlBlocksUrls) MarshalJSON() ([]byte, error) {
  450. type NoMethod ResultFormattedResultsRuleResultsUrlBlocksUrls
  451. raw := NoMethod(*s)
  452. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  453. }
  454. // ResultPageStats: Summary statistics for the page, such as number of
  455. // JavaScript bytes, number of HTML bytes, etc.
  456. type ResultPageStats struct {
  457. // CssResponseBytes: Number of uncompressed response bytes for CSS
  458. // resources on the page.
  459. CssResponseBytes int64 `json:"cssResponseBytes,omitempty,string"`
  460. // FlashResponseBytes: Number of response bytes for flash resources on
  461. // the page.
  462. FlashResponseBytes int64 `json:"flashResponseBytes,omitempty,string"`
  463. // HtmlResponseBytes: Number of uncompressed response bytes for the main
  464. // HTML document and all iframes on the page.
  465. HtmlResponseBytes int64 `json:"htmlResponseBytes,omitempty,string"`
  466. // ImageResponseBytes: Number of response bytes for image resources on
  467. // the page.
  468. ImageResponseBytes int64 `json:"imageResponseBytes,omitempty,string"`
  469. // JavascriptResponseBytes: Number of uncompressed response bytes for JS
  470. // resources on the page.
  471. JavascriptResponseBytes int64 `json:"javascriptResponseBytes,omitempty,string"`
  472. // NumberCssResources: Number of CSS resources referenced by the page.
  473. NumberCssResources int64 `json:"numberCssResources,omitempty"`
  474. // NumberHosts: Number of unique hosts referenced by the page.
  475. NumberHosts int64 `json:"numberHosts,omitempty"`
  476. // NumberJsResources: Number of JavaScript resources referenced by the
  477. // page.
  478. NumberJsResources int64 `json:"numberJsResources,omitempty"`
  479. // NumberResources: Number of HTTP resources loaded by the page.
  480. NumberResources int64 `json:"numberResources,omitempty"`
  481. // NumberStaticResources: Number of static (i.e. cacheable) resources on
  482. // the page.
  483. NumberStaticResources int64 `json:"numberStaticResources,omitempty"`
  484. // OtherResponseBytes: Number of response bytes for other resources on
  485. // the page.
  486. OtherResponseBytes int64 `json:"otherResponseBytes,omitempty,string"`
  487. // TextResponseBytes: Number of uncompressed response bytes for text
  488. // resources not covered by other statistics (i.e non-HTML, non-script,
  489. // non-CSS resources) on the page.
  490. TextResponseBytes int64 `json:"textResponseBytes,omitempty,string"`
  491. // TotalRequestBytes: Total size of all request bytes sent by the page.
  492. TotalRequestBytes int64 `json:"totalRequestBytes,omitempty,string"`
  493. // ForceSendFields is a list of field names (e.g. "CssResponseBytes") to
  494. // unconditionally include in API requests. By default, fields with
  495. // empty values are omitted from API requests. However, any non-pointer,
  496. // non-interface field appearing in ForceSendFields will be sent to the
  497. // server regardless of whether the field is empty or not. This may be
  498. // used to include empty fields in Patch requests.
  499. ForceSendFields []string `json:"-"`
  500. // NullFields is a list of field names (e.g. "CssResponseBytes") to
  501. // include in API requests with the JSON null value. By default, fields
  502. // with empty values are omitted from API requests. However, any field
  503. // with an empty value appearing in NullFields will be sent to the
  504. // server as null. It is an error if a field in this list has a
  505. // non-empty value. This may be used to include null fields in Patch
  506. // requests.
  507. NullFields []string `json:"-"`
  508. }
  509. func (s *ResultPageStats) MarshalJSON() ([]byte, error) {
  510. type NoMethod ResultPageStats
  511. raw := NoMethod(*s)
  512. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  513. }
  514. // ResultRuleGroups: The name of this rule group: one of "SPEED" or
  515. // "USABILITY".
  516. type ResultRuleGroups struct {
  517. // Score: The score (0-100) for this rule group, which indicates how
  518. // much better a page could be in that category (e.g. how much faster,
  519. // or how much more usable). A high score indicates little room for
  520. // improvement, while a lower score indicates more room for improvement.
  521. Score int64 `json:"score,omitempty"`
  522. // ForceSendFields is a list of field names (e.g. "Score") to
  523. // unconditionally include in API requests. By default, fields with
  524. // empty values are omitted from API requests. However, any non-pointer,
  525. // non-interface field appearing in ForceSendFields will be sent to the
  526. // server regardless of whether the field is empty or not. This may be
  527. // used to include empty fields in Patch requests.
  528. ForceSendFields []string `json:"-"`
  529. // NullFields is a list of field names (e.g. "Score") to include in API
  530. // requests with the JSON null value. By default, fields with empty
  531. // values are omitted from API requests. However, any field with an
  532. // empty value appearing in NullFields will be sent to the server as
  533. // null. It is an error if a field in this list has a non-empty value.
  534. // This may be used to include null fields in Patch requests.
  535. NullFields []string `json:"-"`
  536. }
  537. func (s *ResultRuleGroups) MarshalJSON() ([]byte, error) {
  538. type NoMethod ResultRuleGroups
  539. raw := NoMethod(*s)
  540. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  541. }
  542. // ResultVersion: The version of PageSpeed used to generate these
  543. // results.
  544. type ResultVersion struct {
  545. // Major: The major version number of PageSpeed used to generate these
  546. // results.
  547. Major int64 `json:"major,omitempty"`
  548. // Minor: The minor version number of PageSpeed used to generate these
  549. // results.
  550. Minor int64 `json:"minor,omitempty"`
  551. // ForceSendFields is a list of field names (e.g. "Major") to
  552. // unconditionally include in API requests. By default, fields with
  553. // empty values are omitted from API requests. However, any non-pointer,
  554. // non-interface field appearing in ForceSendFields will be sent to the
  555. // server regardless of whether the field is empty or not. This may be
  556. // used to include empty fields in Patch requests.
  557. ForceSendFields []string `json:"-"`
  558. // NullFields is a list of field names (e.g. "Major") to include in API
  559. // requests with the JSON null value. By default, fields with empty
  560. // values are omitted from API requests. However, any field with an
  561. // empty value appearing in NullFields will be sent to the server as
  562. // null. It is an error if a field in this list has a non-empty value.
  563. // This may be used to include null fields in Patch requests.
  564. NullFields []string `json:"-"`
  565. }
  566. func (s *ResultVersion) MarshalJSON() ([]byte, error) {
  567. type NoMethod ResultVersion
  568. raw := NoMethod(*s)
  569. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  570. }
  571. // method id "pagespeedonline.pagespeedapi.runpagespeed":
  572. type PagespeedapiRunpagespeedCall struct {
  573. s *Service
  574. urlParams_ gensupport.URLParams
  575. ifNoneMatch_ string
  576. ctx_ context.Context
  577. header_ http.Header
  578. }
  579. // Runpagespeed: Runs PageSpeed analysis on the page at the specified
  580. // URL, and returns PageSpeed scores, a list of suggestions to make that
  581. // page faster, and other information.
  582. func (r *PagespeedapiService) Runpagespeed(url string) *PagespeedapiRunpagespeedCall {
  583. c := &PagespeedapiRunpagespeedCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  584. c.urlParams_.Set("url", url)
  585. return c
  586. }
  587. // FilterThirdPartyResources sets the optional parameter
  588. // "filter_third_party_resources": Indicates if third party resources
  589. // should be filtered out before PageSpeed analysis.
  590. func (c *PagespeedapiRunpagespeedCall) FilterThirdPartyResources(filterThirdPartyResources bool) *PagespeedapiRunpagespeedCall {
  591. c.urlParams_.Set("filter_third_party_resources", fmt.Sprint(filterThirdPartyResources))
  592. return c
  593. }
  594. // Locale sets the optional parameter "locale": The locale used to
  595. // localize formatted results
  596. func (c *PagespeedapiRunpagespeedCall) Locale(locale string) *PagespeedapiRunpagespeedCall {
  597. c.urlParams_.Set("locale", locale)
  598. return c
  599. }
  600. // Rule sets the optional parameter "rule": A PageSpeed rule to run; if
  601. // none are given, all rules are run
  602. func (c *PagespeedapiRunpagespeedCall) Rule(rule ...string) *PagespeedapiRunpagespeedCall {
  603. c.urlParams_.SetMulti("rule", append([]string{}, rule...))
  604. return c
  605. }
  606. // Screenshot sets the optional parameter "screenshot": Indicates if
  607. // binary data containing a screenshot should be included
  608. func (c *PagespeedapiRunpagespeedCall) Screenshot(screenshot bool) *PagespeedapiRunpagespeedCall {
  609. c.urlParams_.Set("screenshot", fmt.Sprint(screenshot))
  610. return c
  611. }
  612. // Strategy sets the optional parameter "strategy": The analysis
  613. // strategy to use
  614. //
  615. // Possible values:
  616. // "desktop" - Fetch and analyze the URL for desktop browsers
  617. // "mobile" - Fetch and analyze the URL for mobile devices
  618. func (c *PagespeedapiRunpagespeedCall) Strategy(strategy string) *PagespeedapiRunpagespeedCall {
  619. c.urlParams_.Set("strategy", strategy)
  620. return c
  621. }
  622. // Fields allows partial responses to be retrieved. See
  623. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  624. // for more information.
  625. func (c *PagespeedapiRunpagespeedCall) Fields(s ...googleapi.Field) *PagespeedapiRunpagespeedCall {
  626. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  627. return c
  628. }
  629. // IfNoneMatch sets the optional parameter which makes the operation
  630. // fail if the object's ETag matches the given value. This is useful for
  631. // getting updates only after the object has changed since the last
  632. // request. Use googleapi.IsNotModified to check whether the response
  633. // error from Do is the result of In-None-Match.
  634. func (c *PagespeedapiRunpagespeedCall) IfNoneMatch(entityTag string) *PagespeedapiRunpagespeedCall {
  635. c.ifNoneMatch_ = entityTag
  636. return c
  637. }
  638. // Context sets the context to be used in this call's Do method. Any
  639. // pending HTTP request will be aborted if the provided context is
  640. // canceled.
  641. func (c *PagespeedapiRunpagespeedCall) Context(ctx context.Context) *PagespeedapiRunpagespeedCall {
  642. c.ctx_ = ctx
  643. return c
  644. }
  645. // Header returns an http.Header that can be modified by the caller to
  646. // add HTTP headers to the request.
  647. func (c *PagespeedapiRunpagespeedCall) Header() http.Header {
  648. if c.header_ == nil {
  649. c.header_ = make(http.Header)
  650. }
  651. return c.header_
  652. }
  653. func (c *PagespeedapiRunpagespeedCall) doRequest(alt string) (*http.Response, error) {
  654. reqHeaders := make(http.Header)
  655. for k, v := range c.header_ {
  656. reqHeaders[k] = v
  657. }
  658. reqHeaders.Set("User-Agent", c.s.userAgent())
  659. if c.ifNoneMatch_ != "" {
  660. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  661. }
  662. var body io.Reader = nil
  663. c.urlParams_.Set("alt", alt)
  664. urls := googleapi.ResolveRelative(c.s.BasePath, "runPagespeed")
  665. urls += "?" + c.urlParams_.Encode()
  666. req, _ := http.NewRequest("GET", urls, body)
  667. req.Header = reqHeaders
  668. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  669. }
  670. // Do executes the "pagespeedonline.pagespeedapi.runpagespeed" call.
  671. // Exactly one of *Result or error will be non-nil. Any non-2xx status
  672. // code is an error. Response headers are in either
  673. // *Result.ServerResponse.Header or (if a response was returned at all)
  674. // in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to
  675. // check whether the returned error was because http.StatusNotModified
  676. // was returned.
  677. func (c *PagespeedapiRunpagespeedCall) Do(opts ...googleapi.CallOption) (*Result, error) {
  678. gensupport.SetOptions(c.urlParams_, opts...)
  679. res, err := c.doRequest("json")
  680. if res != nil && res.StatusCode == http.StatusNotModified {
  681. if res.Body != nil {
  682. res.Body.Close()
  683. }
  684. return nil, &googleapi.Error{
  685. Code: res.StatusCode,
  686. Header: res.Header,
  687. }
  688. }
  689. if err != nil {
  690. return nil, err
  691. }
  692. defer googleapi.CloseBody(res)
  693. if err := googleapi.CheckResponse(res); err != nil {
  694. return nil, err
  695. }
  696. ret := &Result{
  697. ServerResponse: googleapi.ServerResponse{
  698. Header: res.Header,
  699. HTTPStatusCode: res.StatusCode,
  700. },
  701. }
  702. target := &ret
  703. if err := gensupport.DecodeResponse(target, res); err != nil {
  704. return nil, err
  705. }
  706. return ret, nil
  707. // {
  708. // "description": "Runs PageSpeed analysis on the page at the specified URL, and returns PageSpeed scores, a list of suggestions to make that page faster, and other information.",
  709. // "httpMethod": "GET",
  710. // "id": "pagespeedonline.pagespeedapi.runpagespeed",
  711. // "parameterOrder": [
  712. // "url"
  713. // ],
  714. // "parameters": {
  715. // "filter_third_party_resources": {
  716. // "default": "false",
  717. // "description": "Indicates if third party resources should be filtered out before PageSpeed analysis.",
  718. // "location": "query",
  719. // "type": "boolean"
  720. // },
  721. // "locale": {
  722. // "description": "The locale used to localize formatted results",
  723. // "location": "query",
  724. // "pattern": "[a-zA-Z]+(_[a-zA-Z]+)?",
  725. // "type": "string"
  726. // },
  727. // "rule": {
  728. // "description": "A PageSpeed rule to run; if none are given, all rules are run",
  729. // "location": "query",
  730. // "pattern": "[a-zA-Z]+",
  731. // "repeated": true,
  732. // "type": "string"
  733. // },
  734. // "screenshot": {
  735. // "default": "false",
  736. // "description": "Indicates if binary data containing a screenshot should be included",
  737. // "location": "query",
  738. // "type": "boolean"
  739. // },
  740. // "strategy": {
  741. // "description": "The analysis strategy to use",
  742. // "enum": [
  743. // "desktop",
  744. // "mobile"
  745. // ],
  746. // "enumDescriptions": [
  747. // "Fetch and analyze the URL for desktop browsers",
  748. // "Fetch and analyze the URL for mobile devices"
  749. // ],
  750. // "location": "query",
  751. // "type": "string"
  752. // },
  753. // "url": {
  754. // "description": "The URL to fetch and analyze",
  755. // "location": "query",
  756. // "pattern": "(?i)http(s)?://.*",
  757. // "required": true,
  758. // "type": "string"
  759. // }
  760. // },
  761. // "path": "runPagespeed",
  762. // "response": {
  763. // "$ref": "Result"
  764. // }
  765. // }
  766. }