1 // Copyright 2020 Google LLC. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Code generated file. DO NOT EDIT. 6 7 // Package urlshortener provides access to the URL Shortener API. 8 // 9 // For product documentation, see: https://developers.google.com/url-shortener/v1/getting_started 10 // 11 // # Creating a client 12 // 13 // Usage example: 14 // 15 // import "google.golang.org/api/urlshortener/v1" 16 // ... 17 // ctx := context.Background() 18 // urlshortenerService, err := urlshortener.NewService(ctx) 19 // 20 // In this example, Google Application Default Credentials are used for authentication. 21 // 22 // For information on how to create and obtain Application Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials. 23 // 24 // # Other authentication options 25 // 26 // To use an API key for authentication (note: some APIs do not support API keys), use option.WithAPIKey: 27 // 28 // urlshortenerService, err := urlshortener.NewService(ctx, option.WithAPIKey("AIza...")) 29 // 30 // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth flow), use option.WithTokenSource: 31 // 32 // config := &oauth2.Config{...} 33 // // ... 34 // token, err := config.Exchange(ctx, ...) 35 // urlshortenerService, err := urlshortener.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token))) 36 // 37 // See https://godoc.org/google.golang.org/api/option/ for details on options. 38 package urlshortener // import "google.golang.org/api/urlshortener/v1" 39 40 import ( 41 "bytes" 42 "context" 43 "encoding/json" 44 "errors" 45 "fmt" 46 "io" 47 "net/http" 48 "net/url" 49 "strconv" 50 "strings" 51 52 googleapi "google.golang.org/api/googleapi" 53 gensupport "google.golang.org/api/internal/gensupport" 54 option "google.golang.org/api/option" 55 htransport "google.golang.org/api/transport/http" 56 ) 57 58 // Always reference these packages, just in case the auto-generated code 59 // below doesn't. 60 var _ = bytes.NewBuffer 61 var _ = strconv.Itoa 62 var _ = fmt.Sprintf 63 var _ = json.NewDecoder 64 var _ = io.Copy 65 var _ = url.Parse 66 var _ = gensupport.MarshalJSON 67 var _ = googleapi.Version 68 var _ = errors.New 69 var _ = strings.Replace 70 var _ = context.Canceled 71 72 const apiId = "urlshortener:v1" 73 const apiName = "urlshortener" 74 const apiVersion = "v1" 75 const basePath = "https://www.googleapis.com/urlshortener/v1/" 76 77 // OAuth2 scopes used by this API. 78 const ( 79 // Manage your goo.gl short URLs 80 UrlshortenerScope = "https://www.googleapis.com/auth/urlshortener" 81 ) 82 83 // NewService creates a new Service. 84 func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) { 85 scopesOption := option.WithScopes( 86 "https://www.googleapis.com/auth/urlshortener", 87 ) 88 // NOTE: prepend, so we don't override user-specified scopes. 89 opts = append([]option.ClientOption{scopesOption}, opts...) 90 client, endpoint, err := htransport.NewClient(ctx, opts...) 91 if err != nil { 92 return nil, err 93 } 94 s, err := New(client) 95 if err != nil { 96 return nil, err 97 } 98 if endpoint != "" { 99 s.BasePath = endpoint 100 } 101 return s, nil 102 } 103 104 // New creates a new Service. It uses the provided http.Client for requests. 105 // 106 // Deprecated: please use NewService instead. 107 // To provide a custom HTTP client, use option.WithHTTPClient. 108 // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead. 109 func New(client *http.Client) (*Service, error) { 110 if client == nil { 111 return nil, errors.New("client is nil") 112 } 113 s := &Service{client: client, BasePath: basePath} 114 s.Url = NewUrlService(s) 115 return s, nil 116 } 117 118 type Service struct { 119 client *http.Client 120 BasePath string // API endpoint base URL 121 UserAgent string // optional additional User-Agent fragment 122 123 Url *UrlService 124 } 125 126 func (s *Service) userAgent() string { 127 if s.UserAgent == "" { 128 return googleapi.UserAgent 129 } 130 return googleapi.UserAgent + " " + s.UserAgent 131 } 132 133 func NewUrlService(s *Service) *UrlService { 134 rs := &UrlService{s: s} 135 return rs 136 } 137 138 type UrlService struct { 139 s *Service 140 } 141 142 type AnalyticsSnapshot struct { 143 // Browsers: Top browsers, e.g. "Chrome"; sorted by (descending) click 144 // counts. Only present if this data is available. 145 Browsers []*StringCount `json:"browsers,omitempty"` 146 147 // Countries: Top countries (expressed as country codes), e.g. "US" or 148 // "DE"; sorted by (descending) click counts. Only present if this data 149 // is available. 150 Countries []*StringCount `json:"countries,omitempty"` 151 152 // LongUrlClicks: Number of clicks on all goo.gl short URLs pointing to 153 // this long URL. 154 LongUrlClicks int64 `json:"longUrlClicks,omitempty,string"` 155 156 // Platforms: Top platforms or OSes, e.g. "Windows"; sorted by 157 // (descending) click counts. Only present if this data is available. 158 Platforms []*StringCount `json:"platforms,omitempty"` 159 160 // Referrers: Top referring hosts, e.g. "www.google.com"; sorted by 161 // (descending) click counts. Only present if this data is available. 162 Referrers []*StringCount `json:"referrers,omitempty"` 163 164 // ShortUrlClicks: Number of clicks on this short URL. 165 ShortUrlClicks int64 `json:"shortUrlClicks,omitempty,string"` 166 167 // ForceSendFields is a list of field names (e.g. "Browsers") to 168 // unconditionally include in API requests. By default, fields with 169 // empty values are omitted from API requests. However, any non-pointer, 170 // non-interface field appearing in ForceSendFields will be sent to the 171 // server regardless of whether the field is empty or not. This may be 172 // used to include empty fields in Patch requests. 173 ForceSendFields []string `json:"-"` 174 175 // NullFields is a list of field names (e.g. "Browsers") to include in 176 // API requests with the JSON null value. By default, fields with empty 177 // values are omitted from API requests. However, any field with an 178 // empty value appearing in NullFields will be sent to the server as 179 // null. It is an error if a field in this list has a non-empty value. 180 // This may be used to include null fields in Patch requests. 181 NullFields []string `json:"-"` 182 } 183 184 func (s *AnalyticsSnapshot) MarshalJSON() ([]byte, error) { 185 type NoMethod AnalyticsSnapshot 186 raw := NoMethod(*s) 187 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 188 } 189 190 type AnalyticsSummary struct { 191 // AllTime: Click analytics over all time. 192 AllTime *AnalyticsSnapshot `json:"allTime,omitempty"` 193 194 // Day: Click analytics over the last day. 195 Day *AnalyticsSnapshot `json:"day,omitempty"` 196 197 // Month: Click analytics over the last month. 198 Month *AnalyticsSnapshot `json:"month,omitempty"` 199 200 // TwoHours: Click analytics over the last two hours. 201 TwoHours *AnalyticsSnapshot `json:"twoHours,omitempty"` 202 203 // Week: Click analytics over the last week. 204 Week *AnalyticsSnapshot `json:"week,omitempty"` 205 206 // ForceSendFields is a list of field names (e.g. "AllTime") to 207 // unconditionally include in API requests. By default, fields with 208 // empty values are omitted from API requests. However, any non-pointer, 209 // non-interface field appearing in ForceSendFields will be sent to the 210 // server regardless of whether the field is empty or not. This may be 211 // used to include empty fields in Patch requests. 212 ForceSendFields []string `json:"-"` 213 214 // NullFields is a list of field names (e.g. "AllTime") to include in 215 // API requests with the JSON null value. By default, fields with empty 216 // values are omitted from API requests. However, any field with an 217 // empty value appearing in NullFields will be sent to the server as 218 // null. It is an error if a field in this list has a non-empty value. 219 // This may be used to include null fields in Patch requests. 220 NullFields []string `json:"-"` 221 } 222 223 func (s *AnalyticsSummary) MarshalJSON() ([]byte, error) { 224 type NoMethod AnalyticsSummary 225 raw := NoMethod(*s) 226 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 227 } 228 229 type StringCount struct { 230 // Count: Number of clicks for this top entry, e.g. for this particular 231 // country or browser. 232 Count int64 `json:"count,omitempty,string"` 233 234 // Id: Label assigned to this top entry, e.g. "US" or "Chrome". 235 Id string `json:"id,omitempty"` 236 237 // ForceSendFields is a list of field names (e.g. "Count") to 238 // unconditionally include in API requests. By default, fields with 239 // empty values are omitted from API requests. However, any non-pointer, 240 // non-interface field appearing in ForceSendFields will be sent to the 241 // server regardless of whether the field is empty or not. This may be 242 // used to include empty fields in Patch requests. 243 ForceSendFields []string `json:"-"` 244 245 // NullFields is a list of field names (e.g. "Count") to include in API 246 // requests with the JSON null value. By default, fields with empty 247 // values are omitted from API requests. However, any field with an 248 // empty value appearing in NullFields will be sent to the server as 249 // null. It is an error if a field in this list has a non-empty value. 250 // This may be used to include null fields in Patch requests. 251 NullFields []string `json:"-"` 252 } 253 254 func (s *StringCount) MarshalJSON() ([]byte, error) { 255 type NoMethod StringCount 256 raw := NoMethod(*s) 257 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 258 } 259 260 type Url struct { 261 // Analytics: A summary of the click analytics for the short and long 262 // URL. Might not be present if not requested or currently unavailable. 263 Analytics *AnalyticsSummary `json:"analytics,omitempty"` 264 265 // Created: Time the short URL was created; ISO 8601 representation 266 // using the yyyy-MM-dd'T'HH:mm:ss.SSSZZ format, e.g. 267 // "2010-10-14T19:01:24.944+00:00". 268 Created string `json:"created,omitempty"` 269 270 // Id: Short URL, e.g. "http://goo.gl/l6MS". 271 Id string `json:"id,omitempty"` 272 273 // Kind: The fixed string "urlshortener#url". 274 Kind string `json:"kind,omitempty"` 275 276 // LongUrl: Long URL, e.g. "http://www.google.com/". Might not be 277 // present if the status is "REMOVED". 278 LongUrl string `json:"longUrl,omitempty"` 279 280 // Status: Status of the target URL. Possible values: "OK", "MALWARE", 281 // "PHISHING", or "REMOVED". A URL might be marked "REMOVED" if it was 282 // flagged as spam, for example. 283 Status string `json:"status,omitempty"` 284 285 // ServerResponse contains the HTTP response code and headers from the 286 // server. 287 googleapi.ServerResponse `json:"-"` 288 289 // ForceSendFields is a list of field names (e.g. "Analytics") to 290 // unconditionally include in API requests. By default, fields with 291 // empty values are omitted from API requests. However, any non-pointer, 292 // non-interface field appearing in ForceSendFields will be sent to the 293 // server regardless of whether the field is empty or not. This may be 294 // used to include empty fields in Patch requests. 295 ForceSendFields []string `json:"-"` 296 297 // NullFields is a list of field names (e.g. "Analytics") to include in 298 // API requests with the JSON null value. By default, fields with empty 299 // values are omitted from API requests. However, any field with an 300 // empty value appearing in NullFields will be sent to the server as 301 // null. It is an error if a field in this list has a non-empty value. 302 // This may be used to include null fields in Patch requests. 303 NullFields []string `json:"-"` 304 } 305 306 func (s *Url) MarshalJSON() ([]byte, error) { 307 type NoMethod Url 308 raw := NoMethod(*s) 309 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 310 } 311 312 type UrlHistory struct { 313 // Items: A list of URL resources. 314 Items []*Url `json:"items,omitempty"` 315 316 // ItemsPerPage: Number of items returned with each full "page" of 317 // results. Note that the last page could have fewer items than the 318 // "itemsPerPage" value. 319 ItemsPerPage int64 `json:"itemsPerPage,omitempty"` 320 321 // Kind: The fixed string "urlshortener#urlHistory". 322 Kind string `json:"kind,omitempty"` 323 324 // NextPageToken: A token to provide to get the next page of results. 325 NextPageToken string `json:"nextPageToken,omitempty"` 326 327 // TotalItems: Total number of short URLs associated with this user (may 328 // be approximate). 329 TotalItems int64 `json:"totalItems,omitempty"` 330 331 // ServerResponse contains the HTTP response code and headers from the 332 // server. 333 googleapi.ServerResponse `json:"-"` 334 335 // ForceSendFields is a list of field names (e.g. "Items") to 336 // unconditionally include in API requests. By default, fields with 337 // empty values are omitted from API requests. However, any non-pointer, 338 // non-interface field appearing in ForceSendFields will be sent to the 339 // server regardless of whether the field is empty or not. This may be 340 // used to include empty fields in Patch requests. 341 ForceSendFields []string `json:"-"` 342 343 // NullFields is a list of field names (e.g. "Items") to include in API 344 // requests with the JSON null value. By default, fields with empty 345 // values are omitted from API requests. However, any field with an 346 // empty value appearing in NullFields will be sent to the server as 347 // null. It is an error if a field in this list has a non-empty value. 348 // This may be used to include null fields in Patch requests. 349 NullFields []string `json:"-"` 350 } 351 352 func (s *UrlHistory) MarshalJSON() ([]byte, error) { 353 type NoMethod UrlHistory 354 raw := NoMethod(*s) 355 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 356 } 357 358 // method id "urlshortener.url.get": 359 360 type UrlGetCall struct { 361 s *Service 362 urlParams_ gensupport.URLParams 363 ifNoneMatch_ string 364 ctx_ context.Context 365 header_ http.Header 366 } 367 368 // Get: Expands a short URL or gets creation time and analytics. 369 func (r *UrlService) Get(shortUrl string) *UrlGetCall { 370 c := &UrlGetCall{s: r.s, urlParams_: make(gensupport.URLParams)} 371 c.urlParams_.Set("shortUrl", shortUrl) 372 return c 373 } 374 375 // Projection sets the optional parameter "projection": Additional 376 // information to return. 377 // 378 // Possible values: 379 // 380 // "ANALYTICS_CLICKS" - Returns only click counts. 381 // "ANALYTICS_TOP_STRINGS" - Returns only top string counts. 382 // "FULL" - Returns the creation timestamp and all available 383 // 384 // analytics. 385 func (c *UrlGetCall) Projection(projection string) *UrlGetCall { 386 c.urlParams_.Set("projection", projection) 387 return c 388 } 389 390 // Fields allows partial responses to be retrieved. See 391 // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse 392 // for more information. 393 func (c *UrlGetCall) Fields(s ...googleapi.Field) *UrlGetCall { 394 c.urlParams_.Set("fields", googleapi.CombineFields(s)) 395 return c 396 } 397 398 // IfNoneMatch sets the optional parameter which makes the operation 399 // fail if the object's ETag matches the given value. This is useful for 400 // getting updates only after the object has changed since the last 401 // request. Use googleapi.IsNotModified to check whether the response 402 // error from Do is the result of In-None-Match. 403 func (c *UrlGetCall) IfNoneMatch(entityTag string) *UrlGetCall { 404 c.ifNoneMatch_ = entityTag 405 return c 406 } 407 408 // Context sets the context to be used in this call's Do method. Any 409 // pending HTTP request will be aborted if the provided context is 410 // canceled. 411 func (c *UrlGetCall) Context(ctx context.Context) *UrlGetCall { 412 c.ctx_ = ctx 413 return c 414 } 415 416 // Header returns an http.Header that can be modified by the caller to 417 // add HTTP headers to the request. 418 func (c *UrlGetCall) Header() http.Header { 419 if c.header_ == nil { 420 c.header_ = make(http.Header) 421 } 422 return c.header_ 423 } 424 425 func (c *UrlGetCall) doRequest(alt string) (*http.Response, error) { 426 reqHeaders := make(http.Header) 427 reqHeaders.Set("x-goog-api-client", "gl-go/1.13.7 gdcl/20200203") 428 for k, v := range c.header_ { 429 reqHeaders[k] = v 430 } 431 reqHeaders.Set("User-Agent", c.s.userAgent()) 432 if c.ifNoneMatch_ != "" { 433 reqHeaders.Set("If-None-Match", c.ifNoneMatch_) 434 } 435 var body io.Reader = nil 436 c.urlParams_.Set("alt", alt) 437 c.urlParams_.Set("prettyPrint", "false") 438 urls := googleapi.ResolveRelative(c.s.BasePath, "url") 439 urls += "?" + c.urlParams_.Encode() 440 req, err := http.NewRequest("GET", urls, body) 441 if err != nil { 442 return nil, err 443 } 444 req.Header = reqHeaders 445 return gensupport.SendRequest(c.ctx_, c.s.client, req) 446 } 447 448 // Do executes the "urlshortener.url.get" call. 449 // Exactly one of *Url or error will be non-nil. Any non-2xx status code 450 // is an error. Response headers are in either 451 // *Url.ServerResponse.Header or (if a response was returned at all) in 452 // error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check 453 // whether the returned error was because http.StatusNotModified was 454 // returned. 455 func (c *UrlGetCall) Do(opts ...googleapi.CallOption) (*Url, error) { 456 gensupport.SetOptions(c.urlParams_, opts...) 457 res, err := c.doRequest("json") 458 if res != nil && res.StatusCode == http.StatusNotModified { 459 if res.Body != nil { 460 res.Body.Close() 461 } 462 return nil, &googleapi.Error{ 463 Code: res.StatusCode, 464 Header: res.Header, 465 } 466 } 467 if err != nil { 468 return nil, err 469 } 470 defer googleapi.CloseBody(res) 471 if err := googleapi.CheckResponse(res); err != nil { 472 return nil, err 473 } 474 ret := &Url{ 475 ServerResponse: googleapi.ServerResponse{ 476 Header: res.Header, 477 HTTPStatusCode: res.StatusCode, 478 }, 479 } 480 target := &ret 481 if err := gensupport.DecodeResponse(target, res); err != nil { 482 return nil, err 483 } 484 return ret, nil 485 // { 486 // "description": "Expands a short URL or gets creation time and analytics.", 487 // "httpMethod": "GET", 488 // "id": "urlshortener.url.get", 489 // "parameterOrder": [ 490 // "shortUrl" 491 // ], 492 // "parameters": { 493 // "projection": { 494 // "description": "Additional information to return.", 495 // "enum": [ 496 // "ANALYTICS_CLICKS", 497 // "ANALYTICS_TOP_STRINGS", 498 // "FULL" 499 // ], 500 // "enumDescriptions": [ 501 // "Returns only click counts.", 502 // "Returns only top string counts.", 503 // "Returns the creation timestamp and all available analytics." 504 // ], 505 // "location": "query", 506 // "type": "string" 507 // }, 508 // "shortUrl": { 509 // "description": "The short URL, including the protocol.", 510 // "location": "query", 511 // "required": true, 512 // "type": "string" 513 // } 514 // }, 515 // "path": "url", 516 // "response": { 517 // "$ref": "Url" 518 // }, 519 // "scopes": [ 520 // "https://www.googleapis.com/auth/urlshortener" 521 // ] 522 // } 523 524 } 525 526 // method id "urlshortener.url.insert": 527 528 type UrlInsertCall struct { 529 s *Service 530 url *Url 531 urlParams_ gensupport.URLParams 532 ctx_ context.Context 533 header_ http.Header 534 } 535 536 // Insert: Creates a new short URL. 537 func (r *UrlService) Insert(url *Url) *UrlInsertCall { 538 c := &UrlInsertCall{s: r.s, urlParams_: make(gensupport.URLParams)} 539 c.url = url 540 return c 541 } 542 543 // Fields allows partial responses to be retrieved. See 544 // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse 545 // for more information. 546 func (c *UrlInsertCall) Fields(s ...googleapi.Field) *UrlInsertCall { 547 c.urlParams_.Set("fields", googleapi.CombineFields(s)) 548 return c 549 } 550 551 // Context sets the context to be used in this call's Do method. Any 552 // pending HTTP request will be aborted if the provided context is 553 // canceled. 554 func (c *UrlInsertCall) Context(ctx context.Context) *UrlInsertCall { 555 c.ctx_ = ctx 556 return c 557 } 558 559 // Header returns an http.Header that can be modified by the caller to 560 // add HTTP headers to the request. 561 func (c *UrlInsertCall) Header() http.Header { 562 if c.header_ == nil { 563 c.header_ = make(http.Header) 564 } 565 return c.header_ 566 } 567 568 func (c *UrlInsertCall) doRequest(alt string) (*http.Response, error) { 569 reqHeaders := make(http.Header) 570 reqHeaders.Set("x-goog-api-client", "gl-go/1.13.7 gdcl/20200203") 571 for k, v := range c.header_ { 572 reqHeaders[k] = v 573 } 574 reqHeaders.Set("User-Agent", c.s.userAgent()) 575 var body io.Reader = nil 576 body, err := googleapi.WithoutDataWrapper.JSONReader(c.url) 577 if err != nil { 578 return nil, err 579 } 580 reqHeaders.Set("Content-Type", "application/json") 581 c.urlParams_.Set("alt", alt) 582 c.urlParams_.Set("prettyPrint", "false") 583 urls := googleapi.ResolveRelative(c.s.BasePath, "url") 584 urls += "?" + c.urlParams_.Encode() 585 req, err := http.NewRequest("POST", urls, body) 586 if err != nil { 587 return nil, err 588 } 589 req.Header = reqHeaders 590 return gensupport.SendRequest(c.ctx_, c.s.client, req) 591 } 592 593 // Do executes the "urlshortener.url.insert" call. 594 // Exactly one of *Url or error will be non-nil. Any non-2xx status code 595 // is an error. Response headers are in either 596 // *Url.ServerResponse.Header or (if a response was returned at all) in 597 // error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check 598 // whether the returned error was because http.StatusNotModified was 599 // returned. 600 func (c *UrlInsertCall) Do(opts ...googleapi.CallOption) (*Url, error) { 601 gensupport.SetOptions(c.urlParams_, opts...) 602 res, err := c.doRequest("json") 603 if res != nil && res.StatusCode == http.StatusNotModified { 604 if res.Body != nil { 605 res.Body.Close() 606 } 607 return nil, &googleapi.Error{ 608 Code: res.StatusCode, 609 Header: res.Header, 610 } 611 } 612 if err != nil { 613 return nil, err 614 } 615 defer googleapi.CloseBody(res) 616 if err := googleapi.CheckResponse(res); err != nil { 617 return nil, err 618 } 619 ret := &Url{ 620 ServerResponse: googleapi.ServerResponse{ 621 Header: res.Header, 622 HTTPStatusCode: res.StatusCode, 623 }, 624 } 625 target := &ret 626 if err := gensupport.DecodeResponse(target, res); err != nil { 627 return nil, err 628 } 629 return ret, nil 630 // { 631 // "description": "Creates a new short URL.", 632 // "httpMethod": "POST", 633 // "id": "urlshortener.url.insert", 634 // "path": "url", 635 // "request": { 636 // "$ref": "Url" 637 // }, 638 // "response": { 639 // "$ref": "Url" 640 // }, 641 // "scopes": [ 642 // "https://www.googleapis.com/auth/urlshortener" 643 // ] 644 // } 645 646 } 647 648 // method id "urlshortener.url.list": 649 650 type UrlListCall struct { 651 s *Service 652 urlParams_ gensupport.URLParams 653 ifNoneMatch_ string 654 ctx_ context.Context 655 header_ http.Header 656 } 657 658 // List: Retrieves a list of URLs shortened by a user. 659 func (r *UrlService) List() *UrlListCall { 660 c := &UrlListCall{s: r.s, urlParams_: make(gensupport.URLParams)} 661 return c 662 } 663 664 // Projection sets the optional parameter "projection": Additional 665 // information to return. 666 // 667 // Possible values: 668 // 669 // "ANALYTICS_CLICKS" - Returns short URL click counts. 670 // "FULL" - Returns short URL click counts. 671 func (c *UrlListCall) Projection(projection string) *UrlListCall { 672 c.urlParams_.Set("projection", projection) 673 return c 674 } 675 676 // StartToken sets the optional parameter "start-token": Token for 677 // requesting successive pages of results. 678 func (c *UrlListCall) StartToken(startToken string) *UrlListCall { 679 c.urlParams_.Set("start-token", startToken) 680 return c 681 } 682 683 // Fields allows partial responses to be retrieved. See 684 // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse 685 // for more information. 686 func (c *UrlListCall) Fields(s ...googleapi.Field) *UrlListCall { 687 c.urlParams_.Set("fields", googleapi.CombineFields(s)) 688 return c 689 } 690 691 // IfNoneMatch sets the optional parameter which makes the operation 692 // fail if the object's ETag matches the given value. This is useful for 693 // getting updates only after the object has changed since the last 694 // request. Use googleapi.IsNotModified to check whether the response 695 // error from Do is the result of In-None-Match. 696 func (c *UrlListCall) IfNoneMatch(entityTag string) *UrlListCall { 697 c.ifNoneMatch_ = entityTag 698 return c 699 } 700 701 // Context sets the context to be used in this call's Do method. Any 702 // pending HTTP request will be aborted if the provided context is 703 // canceled. 704 func (c *UrlListCall) Context(ctx context.Context) *UrlListCall { 705 c.ctx_ = ctx 706 return c 707 } 708 709 // Header returns an http.Header that can be modified by the caller to 710 // add HTTP headers to the request. 711 func (c *UrlListCall) Header() http.Header { 712 if c.header_ == nil { 713 c.header_ = make(http.Header) 714 } 715 return c.header_ 716 } 717 718 func (c *UrlListCall) doRequest(alt string) (*http.Response, error) { 719 reqHeaders := make(http.Header) 720 reqHeaders.Set("x-goog-api-client", "gl-go/1.13.7 gdcl/20200203") 721 for k, v := range c.header_ { 722 reqHeaders[k] = v 723 } 724 reqHeaders.Set("User-Agent", c.s.userAgent()) 725 if c.ifNoneMatch_ != "" { 726 reqHeaders.Set("If-None-Match", c.ifNoneMatch_) 727 } 728 var body io.Reader = nil 729 c.urlParams_.Set("alt", alt) 730 c.urlParams_.Set("prettyPrint", "false") 731 urls := googleapi.ResolveRelative(c.s.BasePath, "url/history") 732 urls += "?" + c.urlParams_.Encode() 733 req, err := http.NewRequest("GET", urls, body) 734 if err != nil { 735 return nil, err 736 } 737 req.Header = reqHeaders 738 return gensupport.SendRequest(c.ctx_, c.s.client, req) 739 } 740 741 // Do executes the "urlshortener.url.list" call. 742 // Exactly one of *UrlHistory or error will be non-nil. Any non-2xx 743 // status code is an error. Response headers are in either 744 // *UrlHistory.ServerResponse.Header or (if a response was returned at 745 // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified 746 // to check whether the returned error was because 747 // http.StatusNotModified was returned. 748 func (c *UrlListCall) Do(opts ...googleapi.CallOption) (*UrlHistory, error) { 749 gensupport.SetOptions(c.urlParams_, opts...) 750 res, err := c.doRequest("json") 751 if res != nil && res.StatusCode == http.StatusNotModified { 752 if res.Body != nil { 753 res.Body.Close() 754 } 755 return nil, &googleapi.Error{ 756 Code: res.StatusCode, 757 Header: res.Header, 758 } 759 } 760 if err != nil { 761 return nil, err 762 } 763 defer googleapi.CloseBody(res) 764 if err := googleapi.CheckResponse(res); err != nil { 765 return nil, err 766 } 767 ret := &UrlHistory{ 768 ServerResponse: googleapi.ServerResponse{ 769 Header: res.Header, 770 HTTPStatusCode: res.StatusCode, 771 }, 772 } 773 target := &ret 774 if err := gensupport.DecodeResponse(target, res); err != nil { 775 return nil, err 776 } 777 return ret, nil 778 // { 779 // "description": "Retrieves a list of URLs shortened by a user.", 780 // "httpMethod": "GET", 781 // "id": "urlshortener.url.list", 782 // "parameters": { 783 // "projection": { 784 // "description": "Additional information to return.", 785 // "enum": [ 786 // "ANALYTICS_CLICKS", 787 // "FULL" 788 // ], 789 // "enumDescriptions": [ 790 // "Returns short URL click counts.", 791 // "Returns short URL click counts." 792 // ], 793 // "location": "query", 794 // "type": "string" 795 // }, 796 // "start-token": { 797 // "description": "Token for requesting successive pages of results.", 798 // "location": "query", 799 // "type": "string" 800 // } 801 // }, 802 // "path": "url/history", 803 // "response": { 804 // "$ref": "UrlHistory" 805 // }, 806 // "scopes": [ 807 // "https://www.googleapis.com/auth/urlshortener" 808 // ] 809 // } 810 811 } 812