1
// Package pagespeedonline provides access to the PageSpeed Insights API.
3
// See https://developers.google.com/speed/docs/insights/v1/getting_started
7
// import "google.golang.org/api/pagespeedonline/v1"
9
// pagespeedonlineService, err := pagespeedonline.New(oauthHttpClient)
10
package pagespeedonline
17
"google.golang.org/api/googleapi"
25
// Always reference these packages, just in case the auto-generated code
27
var _ = bytes.NewBuffer
30
var _ = json.NewDecoder
33
var _ = googleapi.Version
35
var _ = strings.Replace
37
const apiId = "pagespeedonline:v1"
38
const apiName = "pagespeedonline"
39
const apiVersion = "v1"
40
const basePath = "https://www.googleapis.com/pagespeedonline/v1/"
42
func New(client *http.Client) (*Service, error) {
44
return nil, errors.New("client is nil")
46
s := &Service{client: client, BasePath: basePath}
47
s.Pagespeedapi = NewPagespeedapiService(s)
53
BasePath string // API endpoint base URL
55
Pagespeedapi *PagespeedapiService
58
func NewPagespeedapiService(s *Service) *PagespeedapiService {
59
rs := &PagespeedapiService{s: s}
63
type PagespeedapiService struct {
68
// FormattedResults: Localized Page Speed results. Contains a
69
// ruleResults entry for each Page Speed rule instantiated and run by
71
FormattedResults *ResultFormattedResults `json:"formattedResults,omitempty"`
73
// Id: Canonicalized and final URL for the document, after following
74
// page redirects (if any).
75
Id string `json:"id,omitempty"`
77
// InvalidRules: List of rules that were specified in the request, but
78
// which the server did not know how to instantiate.
79
InvalidRules []string `json:"invalidRules,omitempty"`
81
// Kind: Kind of result.
82
Kind string `json:"kind,omitempty"`
84
// PageStats: Summary statistics for the page, such as number of
85
// JavaScript bytes, number of HTML bytes, etc.
86
PageStats *ResultPageStats `json:"pageStats,omitempty"`
88
// ResponseCode: Response code for the document. 200 indicates a normal
89
// page load. 4xx/5xx indicates an error.
90
ResponseCode int64 `json:"responseCode,omitempty"`
92
// Score: The Page Speed Score (0-100), which indicates how much faster
93
// a page could be. A high score indicates little room for improvement,
94
// while a lower score indicates more room for improvement.
95
Score int64 `json:"score,omitempty"`
97
// Screenshot: Base64 encoded screenshot of the page that was analyzed.
98
Screenshot *ResultScreenshot `json:"screenshot,omitempty"`
100
// Title: Title of the page, as displayed in the browser's title bar.
101
Title string `json:"title,omitempty"`
103
// Version: The version of the Page Speed SDK used to generate these
105
Version *ResultVersion `json:"version,omitempty"`
108
type ResultFormattedResults struct {
109
// Locale: The locale of the formattedResults, e.g. "en_US".
110
Locale string `json:"locale,omitempty"`
112
// RuleResults: Dictionary of formatted rule results, with one entry for
113
// each Page Speed rule instantiated and run by the server.
114
RuleResults *ResultFormattedResultsRuleResults `json:"ruleResults,omitempty"`
117
type ResultFormattedResultsRuleResults struct {
120
type ResultPageStats struct {
121
// CssResponseBytes: Number of uncompressed response bytes for CSS
122
// resources on the page.
123
CssResponseBytes int64 `json:"cssResponseBytes,omitempty,string"`
125
// FlashResponseBytes: Number of response bytes for flash resources on
127
FlashResponseBytes int64 `json:"flashResponseBytes,omitempty,string"`
129
// HtmlResponseBytes: Number of uncompressed response bytes for the main
130
// HTML document and all iframes on the page.
131
HtmlResponseBytes int64 `json:"htmlResponseBytes,omitempty,string"`
133
// ImageResponseBytes: Number of response bytes for image resources on
135
ImageResponseBytes int64 `json:"imageResponseBytes,omitempty,string"`
137
// JavascriptResponseBytes: Number of uncompressed response bytes for JS
138
// resources on the page.
139
JavascriptResponseBytes int64 `json:"javascriptResponseBytes,omitempty,string"`
141
// NumberCssResources: Number of CSS resources referenced by the page.
142
NumberCssResources int64 `json:"numberCssResources,omitempty"`
144
// NumberHosts: Number of unique hosts referenced by the page.
145
NumberHosts int64 `json:"numberHosts,omitempty"`
147
// NumberJsResources: Number of JavaScript resources referenced by the
149
NumberJsResources int64 `json:"numberJsResources,omitempty"`
151
// NumberResources: Number of HTTP resources loaded by the page.
152
NumberResources int64 `json:"numberResources,omitempty"`
154
// NumberStaticResources: Number of static (i.e. cacheable) resources on
156
NumberStaticResources int64 `json:"numberStaticResources,omitempty"`
158
// OtherResponseBytes: Number of response bytes for other resources on
160
OtherResponseBytes int64 `json:"otherResponseBytes,omitempty,string"`
162
// TextResponseBytes: Number of uncompressed response bytes for text
163
// resources not covered by other statistics (i.e non-HTML, non-script,
164
// non-CSS resources) on the page.
165
TextResponseBytes int64 `json:"textResponseBytes,omitempty,string"`
167
// TotalRequestBytes: Total size of all request bytes sent by the page.
168
TotalRequestBytes int64 `json:"totalRequestBytes,omitempty,string"`
171
type ResultScreenshot struct {
172
// Data: Image data base64 encoded.
173
Data string `json:"data,omitempty"`
175
// Height: Height of screenshot in pixels.
176
Height int64 `json:"height,omitempty"`
178
// Mime_type: Mime type of image data. E.g. "image/jpeg".
179
Mime_type string `json:"mime_type,omitempty"`
181
// Width: Width of screenshot in pixels.
182
Width int64 `json:"width,omitempty"`
185
type ResultVersion struct {
186
// Major: The major version number of the Page Speed SDK used to
187
// generate these results.
188
Major int64 `json:"major,omitempty"`
190
// Minor: The minor version number of the Page Speed SDK used to
191
// generate these results.
192
Minor int64 `json:"minor,omitempty"`
195
// method id "pagespeedonline.pagespeedapi.runpagespeed":
197
type PagespeedapiRunpagespeedCall struct {
200
opt_ map[string]interface{}
203
// Runpagespeed: Runs Page Speed analysis on the page at the specified
204
// URL, and returns a Page Speed score, a list of suggestions to make
205
// that page faster, and other information.
206
func (r *PagespeedapiService) Runpagespeed(url string) *PagespeedapiRunpagespeedCall {
207
c := &PagespeedapiRunpagespeedCall{s: r.s, opt_: make(map[string]interface{})}
212
// Filter_third_party_resources sets the optional parameter
213
// "filter_third_party_resources": Indicates if third party resources
214
// should be filtered out before PageSpeed analysis.
215
func (c *PagespeedapiRunpagespeedCall) Filter_third_party_resources(filter_third_party_resources bool) *PagespeedapiRunpagespeedCall {
216
c.opt_["filter_third_party_resources"] = filter_third_party_resources
220
// Locale sets the optional parameter "locale": The locale used to
221
// localize formatted results
222
func (c *PagespeedapiRunpagespeedCall) Locale(locale string) *PagespeedapiRunpagespeedCall {
223
c.opt_["locale"] = locale
227
// Rule sets the optional parameter "rule": A Page Speed rule to run; if
228
// none are given, all rules are run
229
func (c *PagespeedapiRunpagespeedCall) Rule(rule string) *PagespeedapiRunpagespeedCall {
230
c.opt_["rule"] = rule
234
// Screenshot sets the optional parameter "screenshot": Indicates if
235
// binary data containing a screenshot should be included
236
func (c *PagespeedapiRunpagespeedCall) Screenshot(screenshot bool) *PagespeedapiRunpagespeedCall {
237
c.opt_["screenshot"] = screenshot
241
// Strategy sets the optional parameter "strategy": The analysis
243
func (c *PagespeedapiRunpagespeedCall) Strategy(strategy string) *PagespeedapiRunpagespeedCall {
244
c.opt_["strategy"] = strategy
248
// Fields allows partial responses to be retrieved.
249
// See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
250
// for more information.
251
func (c *PagespeedapiRunpagespeedCall) Fields(s ...googleapi.Field) *PagespeedapiRunpagespeedCall {
252
c.opt_["fields"] = googleapi.CombineFields(s)
256
func (c *PagespeedapiRunpagespeedCall) Do() (*Result, error) {
257
var body io.Reader = nil
258
params := make(url.Values)
259
params.Set("alt", "json")
260
params.Set("url", fmt.Sprintf("%v", c.url))
261
if v, ok := c.opt_["filter_third_party_resources"]; ok {
262
params.Set("filter_third_party_resources", fmt.Sprintf("%v", v))
264
if v, ok := c.opt_["locale"]; ok {
265
params.Set("locale", fmt.Sprintf("%v", v))
267
if v, ok := c.opt_["rule"]; ok {
268
params.Set("rule", fmt.Sprintf("%v", v))
270
if v, ok := c.opt_["screenshot"]; ok {
271
params.Set("screenshot", fmt.Sprintf("%v", v))
273
if v, ok := c.opt_["strategy"]; ok {
274
params.Set("strategy", fmt.Sprintf("%v", v))
276
if v, ok := c.opt_["fields"]; ok {
277
params.Set("fields", fmt.Sprintf("%v", v))
279
urls := googleapi.ResolveRelative(c.s.BasePath, "runPagespeed")
280
urls += "?" + params.Encode()
281
req, _ := http.NewRequest("GET", urls, body)
282
googleapi.SetOpaque(req.URL)
283
req.Header.Set("User-Agent", "google-api-go-client/0.5")
284
res, err := c.s.client.Do(req)
288
defer googleapi.CloseBody(res)
289
if err := googleapi.CheckResponse(res); err != nil {
293
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
298
// "description": "Runs Page Speed analysis on the page at the specified URL, and returns a Page Speed score, a list of suggestions to make that page faster, and other information.",
299
// "httpMethod": "GET",
300
// "id": "pagespeedonline.pagespeedapi.runpagespeed",
301
// "parameterOrder": [
305
// "filter_third_party_resources": {
306
// "default": "false",
307
// "description": "Indicates if third party resources should be filtered out before PageSpeed analysis.",
308
// "location": "query",
312
// "description": "The locale used to localize formatted results",
313
// "location": "query",
314
// "pattern": "[a-zA-Z]+(_[a-zA-Z]+)?",
318
// "description": "A Page Speed rule to run; if none are given, all rules are run",
319
// "location": "query",
320
// "pattern": "[a-zA-Z]+",
325
// "default": "false",
326
// "description": "Indicates if binary data containing a screenshot should be included",
327
// "location": "query",
331
// "description": "The analysis strategy to use",
336
// "enumDescriptions": [
337
// "Fetch and analyze the URL for desktop browsers",
338
// "Fetch and analyze the URL for mobile devices"
340
// "location": "query",
344
// "description": "The URL to fetch and analyze",
345
// "location": "query",
346
// "pattern": "http(s)?://.*",
351
// "path": "runPagespeed",