Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

806 linhas
26 KiB

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