~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/google.golang.org/api/urlshortener/v1/urlshortener-gen.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Package urlshortener provides access to the URL Shortener API.
 
2
//
 
3
// See http://code.google.com/apis/urlshortener/v1/getting_started.html
 
4
//
 
5
// Usage example:
 
6
//
 
7
//   import "google.golang.org/api/urlshortener/v1"
 
8
//   ...
 
9
//   urlshortenerService, err := urlshortener.New(oauthHttpClient)
 
10
package urlshortener
 
11
 
 
12
import (
 
13
        "bytes"
 
14
        "encoding/json"
 
15
        "errors"
 
16
        "fmt"
 
17
        "google.golang.org/api/googleapi"
 
18
        "io"
 
19
        "net/http"
 
20
        "net/url"
 
21
        "strconv"
 
22
        "strings"
 
23
)
 
24
 
 
25
// Always reference these packages, just in case the auto-generated code
 
26
// below doesn't.
 
27
var _ = bytes.NewBuffer
 
28
var _ = strconv.Itoa
 
29
var _ = fmt.Sprintf
 
30
var _ = json.NewDecoder
 
31
var _ = io.Copy
 
32
var _ = url.Parse
 
33
var _ = googleapi.Version
 
34
var _ = errors.New
 
35
var _ = strings.Replace
 
36
 
 
37
const apiId = "urlshortener:v1"
 
38
const apiName = "urlshortener"
 
39
const apiVersion = "v1"
 
40
const basePath = "https://www.googleapis.com/urlshortener/v1/"
 
41
 
 
42
// OAuth2 scopes used by this API.
 
43
const (
 
44
        // Manage your goo.gl short URLs
 
45
        UrlshortenerScope = "https://www.googleapis.com/auth/urlshortener"
 
46
)
 
47
 
 
48
func New(client *http.Client) (*Service, error) {
 
49
        if client == nil {
 
50
                return nil, errors.New("client is nil")
 
51
        }
 
52
        s := &Service{client: client, BasePath: basePath}
 
53
        s.Url = NewUrlService(s)
 
54
        return s, nil
 
55
}
 
56
 
 
57
type Service struct {
 
58
        client   *http.Client
 
59
        BasePath string // API endpoint base URL
 
60
 
 
61
        Url *UrlService
 
62
}
 
63
 
 
64
func NewUrlService(s *Service) *UrlService {
 
65
        rs := &UrlService{s: s}
 
66
        return rs
 
67
}
 
68
 
 
69
type UrlService struct {
 
70
        s *Service
 
71
}
 
72
 
 
73
type AnalyticsSnapshot struct {
 
74
        // Browsers: Top browsers, e.g. "Chrome"; sorted by (descending) click
 
75
        // counts. Only present if this data is available.
 
76
        Browsers []*StringCount `json:"browsers,omitempty"`
 
77
 
 
78
        // Countries: Top countries (expressed as country codes), e.g. "US" or
 
79
        // "DE"; sorted by (descending) click counts. Only present if this data
 
80
        // is available.
 
81
        Countries []*StringCount `json:"countries,omitempty"`
 
82
 
 
83
        // LongUrlClicks: Number of clicks on all goo.gl short URLs pointing to
 
84
        // this long URL.
 
85
        LongUrlClicks int64 `json:"longUrlClicks,omitempty,string"`
 
86
 
 
87
        // Platforms: Top platforms or OSes, e.g. "Windows"; sorted by
 
88
        // (descending) click counts. Only present if this data is available.
 
89
        Platforms []*StringCount `json:"platforms,omitempty"`
 
90
 
 
91
        // Referrers: Top referring hosts, e.g. "www.google.com"; sorted by
 
92
        // (descending) click counts. Only present if this data is available.
 
93
        Referrers []*StringCount `json:"referrers,omitempty"`
 
94
 
 
95
        // ShortUrlClicks: Number of clicks on this short URL.
 
96
        ShortUrlClicks int64 `json:"shortUrlClicks,omitempty,string"`
 
97
}
 
98
 
 
99
type AnalyticsSummary struct {
 
100
        // AllTime: Click analytics over all time.
 
101
        AllTime *AnalyticsSnapshot `json:"allTime,omitempty"`
 
102
 
 
103
        // Day: Click analytics over the last day.
 
104
        Day *AnalyticsSnapshot `json:"day,omitempty"`
 
105
 
 
106
        // Month: Click analytics over the last month.
 
107
        Month *AnalyticsSnapshot `json:"month,omitempty"`
 
108
 
 
109
        // TwoHours: Click analytics over the last two hours.
 
110
        TwoHours *AnalyticsSnapshot `json:"twoHours,omitempty"`
 
111
 
 
112
        // Week: Click analytics over the last week.
 
113
        Week *AnalyticsSnapshot `json:"week,omitempty"`
 
114
}
 
115
 
 
116
type StringCount struct {
 
117
        // Count: Number of clicks for this top entry, e.g. for this particular
 
118
        // country or browser.
 
119
        Count int64 `json:"count,omitempty,string"`
 
120
 
 
121
        // Id: Label assigned to this top entry, e.g. "US" or "Chrome".
 
122
        Id string `json:"id,omitempty"`
 
123
}
 
124
 
 
125
type Url struct {
 
126
        // Analytics: A summary of the click analytics for the short and long
 
127
        // URL. Might not be present if not requested or currently unavailable.
 
128
        Analytics *AnalyticsSummary `json:"analytics,omitempty"`
 
129
 
 
130
        // Created: Time the short URL was created; ISO 8601 representation
 
131
        // using the yyyy-MM-dd'T'HH:mm:ss.SSSZZ format, e.g.
 
132
        // "2010-10-14T19:01:24.944+00:00".
 
133
        Created string `json:"created,omitempty"`
 
134
 
 
135
        // Id: Short URL, e.g. "http://goo.gl/l6MS".
 
136
        Id string `json:"id,omitempty"`
 
137
 
 
138
        // Kind: The fixed string "urlshortener#url".
 
139
        Kind string `json:"kind,omitempty"`
 
140
 
 
141
        // LongUrl: Long URL, e.g. "http://www.google.com/". Might not be
 
142
        // present if the status is "REMOVED".
 
143
        LongUrl string `json:"longUrl,omitempty"`
 
144
 
 
145
        // Status: Status of the target URL. Possible values: "OK", "MALWARE",
 
146
        // "PHISHING", or "REMOVED". A URL might be marked "REMOVED" if it was
 
147
        // flagged as spam, for example.
 
148
        Status string `json:"status,omitempty"`
 
149
}
 
150
 
 
151
type UrlHistory struct {
 
152
        // Items: A list of URL resources.
 
153
        Items []*Url `json:"items,omitempty"`
 
154
 
 
155
        // ItemsPerPage: Number of items returned with each full "page" of
 
156
        // results. Note that the last page could have fewer items than the
 
157
        // "itemsPerPage" value.
 
158
        ItemsPerPage int64 `json:"itemsPerPage,omitempty"`
 
159
 
 
160
        // Kind: The fixed string "urlshortener#urlHistory".
 
161
        Kind string `json:"kind,omitempty"`
 
162
 
 
163
        // NextPageToken: A token to provide to get the next page of results.
 
164
        NextPageToken string `json:"nextPageToken,omitempty"`
 
165
 
 
166
        // TotalItems: Total number of short URLs associated with this user (may
 
167
        // be approximate).
 
168
        TotalItems int64 `json:"totalItems,omitempty"`
 
169
}
 
170
 
 
171
// method id "urlshortener.url.get":
 
172
 
 
173
type UrlGetCall struct {
 
174
        s        *Service
 
175
        shortUrl string
 
176
        opt_     map[string]interface{}
 
177
}
 
178
 
 
179
// Get: Expands a short URL or gets creation time and analytics.
 
180
func (r *UrlService) Get(shortUrl string) *UrlGetCall {
 
181
        c := &UrlGetCall{s: r.s, opt_: make(map[string]interface{})}
 
182
        c.shortUrl = shortUrl
 
183
        return c
 
184
}
 
185
 
 
186
// Projection sets the optional parameter "projection": Additional
 
187
// information to return.
 
188
func (c *UrlGetCall) Projection(projection string) *UrlGetCall {
 
189
        c.opt_["projection"] = projection
 
190
        return c
 
191
}
 
192
 
 
193
// Fields allows partial responses to be retrieved.
 
194
// See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
 
195
// for more information.
 
196
func (c *UrlGetCall) Fields(s ...googleapi.Field) *UrlGetCall {
 
197
        c.opt_["fields"] = googleapi.CombineFields(s)
 
198
        return c
 
199
}
 
200
 
 
201
func (c *UrlGetCall) Do() (*Url, error) {
 
202
        var body io.Reader = nil
 
203
        params := make(url.Values)
 
204
        params.Set("alt", "json")
 
205
        params.Set("shortUrl", fmt.Sprintf("%v", c.shortUrl))
 
206
        if v, ok := c.opt_["projection"]; ok {
 
207
                params.Set("projection", fmt.Sprintf("%v", v))
 
208
        }
 
209
        if v, ok := c.opt_["fields"]; ok {
 
210
                params.Set("fields", fmt.Sprintf("%v", v))
 
211
        }
 
212
        urls := googleapi.ResolveRelative(c.s.BasePath, "url")
 
213
        urls += "?" + params.Encode()
 
214
        req, _ := http.NewRequest("GET", urls, body)
 
215
        googleapi.SetOpaque(req.URL)
 
216
        req.Header.Set("User-Agent", "google-api-go-client/0.5")
 
217
        res, err := c.s.client.Do(req)
 
218
        if err != nil {
 
219
                return nil, err
 
220
        }
 
221
        defer googleapi.CloseBody(res)
 
222
        if err := googleapi.CheckResponse(res); err != nil {
 
223
                return nil, err
 
224
        }
 
225
        var ret *Url
 
226
        if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
 
227
                return nil, err
 
228
        }
 
229
        return ret, nil
 
230
        // {
 
231
        //   "description": "Expands a short URL or gets creation time and analytics.",
 
232
        //   "httpMethod": "GET",
 
233
        //   "id": "urlshortener.url.get",
 
234
        //   "parameterOrder": [
 
235
        //     "shortUrl"
 
236
        //   ],
 
237
        //   "parameters": {
 
238
        //     "projection": {
 
239
        //       "description": "Additional information to return.",
 
240
        //       "enum": [
 
241
        //         "ANALYTICS_CLICKS",
 
242
        //         "ANALYTICS_TOP_STRINGS",
 
243
        //         "FULL"
 
244
        //       ],
 
245
        //       "enumDescriptions": [
 
246
        //         "Returns only click counts.",
 
247
        //         "Returns only top string counts.",
 
248
        //         "Returns the creation timestamp and all available analytics."
 
249
        //       ],
 
250
        //       "location": "query",
 
251
        //       "type": "string"
 
252
        //     },
 
253
        //     "shortUrl": {
 
254
        //       "description": "The short URL, including the protocol.",
 
255
        //       "location": "query",
 
256
        //       "required": true,
 
257
        //       "type": "string"
 
258
        //     }
 
259
        //   },
 
260
        //   "path": "url",
 
261
        //   "response": {
 
262
        //     "$ref": "Url"
 
263
        //   }
 
264
        // }
 
265
 
 
266
}
 
267
 
 
268
// method id "urlshortener.url.insert":
 
269
 
 
270
type UrlInsertCall struct {
 
271
        s    *Service
 
272
        url  *Url
 
273
        opt_ map[string]interface{}
 
274
}
 
275
 
 
276
// Insert: Creates a new short URL.
 
277
func (r *UrlService) Insert(url *Url) *UrlInsertCall {
 
278
        c := &UrlInsertCall{s: r.s, opt_: make(map[string]interface{})}
 
279
        c.url = url
 
280
        return c
 
281
}
 
282
 
 
283
// Fields allows partial responses to be retrieved.
 
284
// See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
 
285
// for more information.
 
286
func (c *UrlInsertCall) Fields(s ...googleapi.Field) *UrlInsertCall {
 
287
        c.opt_["fields"] = googleapi.CombineFields(s)
 
288
        return c
 
289
}
 
290
 
 
291
func (c *UrlInsertCall) Do() (*Url, error) {
 
292
        var body io.Reader = nil
 
293
        body, err := googleapi.WithoutDataWrapper.JSONReader(c.url)
 
294
        if err != nil {
 
295
                return nil, err
 
296
        }
 
297
        ctype := "application/json"
 
298
        params := make(url.Values)
 
299
        params.Set("alt", "json")
 
300
        if v, ok := c.opt_["fields"]; ok {
 
301
                params.Set("fields", fmt.Sprintf("%v", v))
 
302
        }
 
303
        urls := googleapi.ResolveRelative(c.s.BasePath, "url")
 
304
        urls += "?" + params.Encode()
 
305
        req, _ := http.NewRequest("POST", urls, body)
 
306
        googleapi.SetOpaque(req.URL)
 
307
        req.Header.Set("Content-Type", ctype)
 
308
        req.Header.Set("User-Agent", "google-api-go-client/0.5")
 
309
        res, err := c.s.client.Do(req)
 
310
        if err != nil {
 
311
                return nil, err
 
312
        }
 
313
        defer googleapi.CloseBody(res)
 
314
        if err := googleapi.CheckResponse(res); err != nil {
 
315
                return nil, err
 
316
        }
 
317
        var ret *Url
 
318
        if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
 
319
                return nil, err
 
320
        }
 
321
        return ret, nil
 
322
        // {
 
323
        //   "description": "Creates a new short URL.",
 
324
        //   "httpMethod": "POST",
 
325
        //   "id": "urlshortener.url.insert",
 
326
        //   "path": "url",
 
327
        //   "request": {
 
328
        //     "$ref": "Url"
 
329
        //   },
 
330
        //   "response": {
 
331
        //     "$ref": "Url"
 
332
        //   },
 
333
        //   "scopes": [
 
334
        //     "https://www.googleapis.com/auth/urlshortener"
 
335
        //   ]
 
336
        // }
 
337
 
 
338
}
 
339
 
 
340
// method id "urlshortener.url.list":
 
341
 
 
342
type UrlListCall struct {
 
343
        s    *Service
 
344
        opt_ map[string]interface{}
 
345
}
 
346
 
 
347
// List: Retrieves a list of URLs shortened by a user.
 
348
func (r *UrlService) List() *UrlListCall {
 
349
        c := &UrlListCall{s: r.s, opt_: make(map[string]interface{})}
 
350
        return c
 
351
}
 
352
 
 
353
// Projection sets the optional parameter "projection": Additional
 
354
// information to return.
 
355
func (c *UrlListCall) Projection(projection string) *UrlListCall {
 
356
        c.opt_["projection"] = projection
 
357
        return c
 
358
}
 
359
 
 
360
// StartToken sets the optional parameter "start-token": Token for
 
361
// requesting successive pages of results.
 
362
func (c *UrlListCall) StartToken(startToken string) *UrlListCall {
 
363
        c.opt_["start-token"] = startToken
 
364
        return c
 
365
}
 
366
 
 
367
// Fields allows partial responses to be retrieved.
 
368
// See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
 
369
// for more information.
 
370
func (c *UrlListCall) Fields(s ...googleapi.Field) *UrlListCall {
 
371
        c.opt_["fields"] = googleapi.CombineFields(s)
 
372
        return c
 
373
}
 
374
 
 
375
func (c *UrlListCall) Do() (*UrlHistory, error) {
 
376
        var body io.Reader = nil
 
377
        params := make(url.Values)
 
378
        params.Set("alt", "json")
 
379
        if v, ok := c.opt_["projection"]; ok {
 
380
                params.Set("projection", fmt.Sprintf("%v", v))
 
381
        }
 
382
        if v, ok := c.opt_["start-token"]; ok {
 
383
                params.Set("start-token", fmt.Sprintf("%v", v))
 
384
        }
 
385
        if v, ok := c.opt_["fields"]; ok {
 
386
                params.Set("fields", fmt.Sprintf("%v", v))
 
387
        }
 
388
        urls := googleapi.ResolveRelative(c.s.BasePath, "url/history")
 
389
        urls += "?" + params.Encode()
 
390
        req, _ := http.NewRequest("GET", urls, body)
 
391
        googleapi.SetOpaque(req.URL)
 
392
        req.Header.Set("User-Agent", "google-api-go-client/0.5")
 
393
        res, err := c.s.client.Do(req)
 
394
        if err != nil {
 
395
                return nil, err
 
396
        }
 
397
        defer googleapi.CloseBody(res)
 
398
        if err := googleapi.CheckResponse(res); err != nil {
 
399
                return nil, err
 
400
        }
 
401
        var ret *UrlHistory
 
402
        if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
 
403
                return nil, err
 
404
        }
 
405
        return ret, nil
 
406
        // {
 
407
        //   "description": "Retrieves a list of URLs shortened by a user.",
 
408
        //   "httpMethod": "GET",
 
409
        //   "id": "urlshortener.url.list",
 
410
        //   "parameters": {
 
411
        //     "projection": {
 
412
        //       "description": "Additional information to return.",
 
413
        //       "enum": [
 
414
        //         "ANALYTICS_CLICKS",
 
415
        //         "FULL"
 
416
        //       ],
 
417
        //       "enumDescriptions": [
 
418
        //         "Returns short URL click counts.",
 
419
        //         "Returns short URL click counts."
 
420
        //       ],
 
421
        //       "location": "query",
 
422
        //       "type": "string"
 
423
        //     },
 
424
        //     "start-token": {
 
425
        //       "description": "Token for requesting successive pages of results.",
 
426
        //       "location": "query",
 
427
        //       "type": "string"
 
428
        //     }
 
429
        //   },
 
430
        //   "path": "url/history",
 
431
        //   "response": {
 
432
        //     "$ref": "UrlHistory"
 
433
        //   },
 
434
        //   "scopes": [
 
435
        //     "https://www.googleapis.com/auth/urlshortener"
 
436
        //   ]
 
437
        // }
 
438
 
 
439
}