You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

739 lines
23 KiB

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