1
// Package urlshortener provides access to the URL Shortener API.
3
// See http://code.google.com/apis/urlshortener/v1/getting_started.html
7
// import "google.golang.org/api/urlshortener/v1"
9
// urlshortenerService, err := urlshortener.New(oauthHttpClient)
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 = "urlshortener:v1"
38
const apiName = "urlshortener"
39
const apiVersion = "v1"
40
const basePath = "https://www.googleapis.com/urlshortener/v1/"
42
// OAuth2 scopes used by this API.
44
// Manage your goo.gl short URLs
45
UrlshortenerScope = "https://www.googleapis.com/auth/urlshortener"
48
func New(client *http.Client) (*Service, error) {
50
return nil, errors.New("client is nil")
52
s := &Service{client: client, BasePath: basePath}
53
s.Url = NewUrlService(s)
59
BasePath string // API endpoint base URL
64
func NewUrlService(s *Service) *UrlService {
65
rs := &UrlService{s: s}
69
type UrlService struct {
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"`
78
// Countries: Top countries (expressed as country codes), e.g. "US" or
79
// "DE"; sorted by (descending) click counts. Only present if this data
81
Countries []*StringCount `json:"countries,omitempty"`
83
// LongUrlClicks: Number of clicks on all goo.gl short URLs pointing to
85
LongUrlClicks int64 `json:"longUrlClicks,omitempty,string"`
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"`
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"`
95
// ShortUrlClicks: Number of clicks on this short URL.
96
ShortUrlClicks int64 `json:"shortUrlClicks,omitempty,string"`
99
type AnalyticsSummary struct {
100
// AllTime: Click analytics over all time.
101
AllTime *AnalyticsSnapshot `json:"allTime,omitempty"`
103
// Day: Click analytics over the last day.
104
Day *AnalyticsSnapshot `json:"day,omitempty"`
106
// Month: Click analytics over the last month.
107
Month *AnalyticsSnapshot `json:"month,omitempty"`
109
// TwoHours: Click analytics over the last two hours.
110
TwoHours *AnalyticsSnapshot `json:"twoHours,omitempty"`
112
// Week: Click analytics over the last week.
113
Week *AnalyticsSnapshot `json:"week,omitempty"`
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"`
121
// Id: Label assigned to this top entry, e.g. "US" or "Chrome".
122
Id string `json:"id,omitempty"`
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"`
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"`
135
// Id: Short URL, e.g. "http://goo.gl/l6MS".
136
Id string `json:"id,omitempty"`
138
// Kind: The fixed string "urlshortener#url".
139
Kind string `json:"kind,omitempty"`
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"`
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"`
151
type UrlHistory struct {
152
// Items: A list of URL resources.
153
Items []*Url `json:"items,omitempty"`
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"`
160
// Kind: The fixed string "urlshortener#urlHistory".
161
Kind string `json:"kind,omitempty"`
163
// NextPageToken: A token to provide to get the next page of results.
164
NextPageToken string `json:"nextPageToken,omitempty"`
166
// TotalItems: Total number of short URLs associated with this user (may
168
TotalItems int64 `json:"totalItems,omitempty"`
171
// method id "urlshortener.url.get":
173
type UrlGetCall struct {
176
opt_ map[string]interface{}
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
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
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)
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))
209
if v, ok := c.opt_["fields"]; ok {
210
params.Set("fields", fmt.Sprintf("%v", v))
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)
221
defer googleapi.CloseBody(res)
222
if err := googleapi.CheckResponse(res); err != nil {
226
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
231
// "description": "Expands a short URL or gets creation time and analytics.",
232
// "httpMethod": "GET",
233
// "id": "urlshortener.url.get",
234
// "parameterOrder": [
239
// "description": "Additional information to return.",
241
// "ANALYTICS_CLICKS",
242
// "ANALYTICS_TOP_STRINGS",
245
// "enumDescriptions": [
246
// "Returns only click counts.",
247
// "Returns only top string counts.",
248
// "Returns the creation timestamp and all available analytics."
250
// "location": "query",
254
// "description": "The short URL, including the protocol.",
255
// "location": "query",
268
// method id "urlshortener.url.insert":
270
type UrlInsertCall struct {
273
opt_ map[string]interface{}
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{})}
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)
291
func (c *UrlInsertCall) Do() (*Url, error) {
292
var body io.Reader = nil
293
body, err := googleapi.WithoutDataWrapper.JSONReader(c.url)
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))
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)
313
defer googleapi.CloseBody(res)
314
if err := googleapi.CheckResponse(res); err != nil {
318
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
323
// "description": "Creates a new short URL.",
324
// "httpMethod": "POST",
325
// "id": "urlshortener.url.insert",
334
// "https://www.googleapis.com/auth/urlshortener"
340
// method id "urlshortener.url.list":
342
type UrlListCall struct {
344
opt_ map[string]interface{}
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{})}
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
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
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)
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))
382
if v, ok := c.opt_["start-token"]; ok {
383
params.Set("start-token", fmt.Sprintf("%v", v))
385
if v, ok := c.opt_["fields"]; ok {
386
params.Set("fields", fmt.Sprintf("%v", v))
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)
397
defer googleapi.CloseBody(res)
398
if err := googleapi.CheckResponse(res); err != nil {
402
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
407
// "description": "Retrieves a list of URLs shortened by a user.",
408
// "httpMethod": "GET",
409
// "id": "urlshortener.url.list",
412
// "description": "Additional information to return.",
414
// "ANALYTICS_CLICKS",
417
// "enumDescriptions": [
418
// "Returns short URL click counts.",
419
// "Returns short URL click counts."
421
// "location": "query",
425
// "description": "Token for requesting successive pages of results.",
426
// "location": "query",
430
// "path": "url/history",
432
// "$ref": "UrlHistory"
435
// "https://www.googleapis.com/auth/urlshortener"