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.
 
 
 

308 lines
9.2 KiB

  1. // Copyright YEAR 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 repeated provides access to the Example API.
  6. //
  7. // Creating a client
  8. //
  9. // Usage example:
  10. //
  11. // import "google.golang.org/api/repeated/v1"
  12. // ...
  13. // ctx := context.Background()
  14. // repeatedService, err := repeated.NewService(ctx)
  15. //
  16. // In this example, Google Application Default Credentials are used for authentication.
  17. //
  18. // For information on how to create and obtain Application Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.
  19. //
  20. // Other authentication options
  21. //
  22. // To use an API key for authentication (note: some APIs do not support API keys), use option.WithAPIKey:
  23. //
  24. // repeatedService, err := repeated.NewService(ctx, option.WithAPIKey("AIza..."))
  25. //
  26. // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth flow), use option.WithTokenSource:
  27. //
  28. // config := &oauth2.Config{...}
  29. // // ...
  30. // token, err := config.Exchange(ctx, ...)
  31. // repeatedService, err := repeated.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
  32. //
  33. // See https://godoc.org/google.golang.org/api/option/ for details on options.
  34. package repeated // import "google.golang.org/api/repeated/v1"
  35. import (
  36. "bytes"
  37. "context"
  38. "encoding/json"
  39. "errors"
  40. "fmt"
  41. "io"
  42. "net/http"
  43. "net/url"
  44. "strconv"
  45. "strings"
  46. gensupport "google.golang.org/api/gensupport"
  47. googleapi "google.golang.org/api/googleapi"
  48. option "google.golang.org/api/option"
  49. htransport "google.golang.org/api/transport/http"
  50. )
  51. // Always reference these packages, just in case the auto-generated code
  52. // below doesn't.
  53. var _ = bytes.NewBuffer
  54. var _ = strconv.Itoa
  55. var _ = fmt.Sprintf
  56. var _ = json.NewDecoder
  57. var _ = io.Copy
  58. var _ = url.Parse
  59. var _ = gensupport.MarshalJSON
  60. var _ = googleapi.Version
  61. var _ = errors.New
  62. var _ = strings.Replace
  63. var _ = context.Canceled
  64. const apiId = "repeated:v1"
  65. const apiName = "repeated"
  66. const apiVersion = "v1"
  67. const basePath = "https://www.googleapis.com/discovery/v1/apis"
  68. // NewService creates a new Service.
  69. func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
  70. client, endpoint, err := htransport.NewClient(ctx, opts...)
  71. if err != nil {
  72. return nil, err
  73. }
  74. s, err := New(client)
  75. if err != nil {
  76. return nil, err
  77. }
  78. if endpoint != "" {
  79. s.BasePath = endpoint
  80. }
  81. return s, nil
  82. }
  83. // New creates a new Service. It uses the provided http.Client for requests.
  84. //
  85. // Deprecated: please use NewService instead.
  86. // To provide a custom HTTP client, use option.WithHTTPClient.
  87. // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
  88. func New(client *http.Client) (*Service, error) {
  89. if client == nil {
  90. return nil, errors.New("client is nil")
  91. }
  92. s := &Service{client: client, BasePath: basePath}
  93. s.Accounts = NewAccountsService(s)
  94. return s, nil
  95. }
  96. type Service struct {
  97. client *http.Client
  98. BasePath string // API endpoint base URL
  99. UserAgent string // optional additional User-Agent fragment
  100. Accounts *AccountsService
  101. }
  102. func (s *Service) userAgent() string {
  103. if s.UserAgent == "" {
  104. return googleapi.UserAgent
  105. }
  106. return googleapi.UserAgent + " " + s.UserAgent
  107. }
  108. func NewAccountsService(s *Service) *AccountsService {
  109. rs := &AccountsService{s: s}
  110. rs.Reports = NewAccountsReportsService(s)
  111. return rs
  112. }
  113. type AccountsService struct {
  114. s *Service
  115. Reports *AccountsReportsService
  116. }
  117. func NewAccountsReportsService(s *Service) *AccountsReportsService {
  118. rs := &AccountsReportsService{s: s}
  119. return rs
  120. }
  121. type AccountsReportsService struct {
  122. s *Service
  123. }
  124. // method id "adsense.accounts.reports.generate":
  125. type AccountsReportsGenerateCall struct {
  126. s *Service
  127. accountId string
  128. urlParams_ gensupport.URLParams
  129. ifNoneMatch_ string
  130. ctx_ context.Context
  131. header_ http.Header
  132. }
  133. // Generate: Generate an AdSense report based on the report request sent
  134. // in the query parameters. Returns the result as JSON; to retrieve
  135. // output in CSV format specify "alt=csv" as a query parameter.
  136. func (r *AccountsReportsService) Generate(ids []int64, currency string, accountId string, dimension []string) *AccountsReportsGenerateCall {
  137. c := &AccountsReportsGenerateCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  138. var ids_ []string
  139. for _, v := range ids {
  140. ids_ = append(ids_, fmt.Sprint(v))
  141. }
  142. c.urlParams_.SetMulti("ids", ids_)
  143. c.urlParams_.Set("currency", currency)
  144. c.accountId = accountId
  145. c.urlParams_.SetMulti("dimension", append([]string{}, dimension...))
  146. return c
  147. }
  148. // Currency sets the optional parameter "currency": Optional currency to
  149. // use when reporting on monetary metrics. Defaults to the account's
  150. // currency if not set.
  151. func (c *AccountsReportsGenerateCall) Currency(currency string) *AccountsReportsGenerateCall {
  152. c.urlParams_.Set("currency", currency)
  153. return c
  154. }
  155. // Dimension sets the optional parameter "dimension": Dimensions to base
  156. // the report on.
  157. func (c *AccountsReportsGenerateCall) Dimension(dimension ...string) *AccountsReportsGenerateCall {
  158. c.urlParams_.SetMulti("dimension", append([]string{}, dimension...))
  159. return c
  160. }
  161. // Ids sets the optional parameter "ids": Select only user profiles with
  162. // these IDs.
  163. func (c *AccountsReportsGenerateCall) Ids(ids ...int64) *AccountsReportsGenerateCall {
  164. var ids_ []string
  165. for _, v := range ids {
  166. ids_ = append(ids_, fmt.Sprint(v))
  167. }
  168. c.urlParams_.SetMulti("ids", ids_)
  169. return c
  170. }
  171. // Fields allows partial responses to be retrieved. See
  172. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  173. // for more information.
  174. func (c *AccountsReportsGenerateCall) Fields(s ...googleapi.Field) *AccountsReportsGenerateCall {
  175. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  176. return c
  177. }
  178. // IfNoneMatch sets the optional parameter which makes the operation
  179. // fail if the object's ETag matches the given value. This is useful for
  180. // getting updates only after the object has changed since the last
  181. // request. Use googleapi.IsNotModified to check whether the response
  182. // error from Do is the result of In-None-Match.
  183. func (c *AccountsReportsGenerateCall) IfNoneMatch(entityTag string) *AccountsReportsGenerateCall {
  184. c.ifNoneMatch_ = entityTag
  185. return c
  186. }
  187. // Context sets the context to be used in this call's Do method. Any
  188. // pending HTTP request will be aborted if the provided context is
  189. // canceled.
  190. func (c *AccountsReportsGenerateCall) Context(ctx context.Context) *AccountsReportsGenerateCall {
  191. c.ctx_ = ctx
  192. return c
  193. }
  194. // Header returns an http.Header that can be modified by the caller to
  195. // add HTTP headers to the request.
  196. func (c *AccountsReportsGenerateCall) Header() http.Header {
  197. if c.header_ == nil {
  198. c.header_ = make(http.Header)
  199. }
  200. return c.header_
  201. }
  202. func (c *AccountsReportsGenerateCall) doRequest(alt string) (*http.Response, error) {
  203. reqHeaders := make(http.Header)
  204. for k, v := range c.header_ {
  205. reqHeaders[k] = v
  206. }
  207. reqHeaders.Set("User-Agent", c.s.userAgent())
  208. if c.ifNoneMatch_ != "" {
  209. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  210. }
  211. var body io.Reader = nil
  212. c.urlParams_.Set("alt", alt)
  213. c.urlParams_.Set("prettyPrint", "false")
  214. urls := googleapi.ResolveRelative(c.s.BasePath, "accounts/{accountId}/reports")
  215. urls += "?" + c.urlParams_.Encode()
  216. req, err := http.NewRequest("GET", urls, body)
  217. if err != nil {
  218. return nil, err
  219. }
  220. req.Header = reqHeaders
  221. googleapi.Expand(req.URL, map[string]string{
  222. "accountId": c.accountId,
  223. })
  224. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  225. }
  226. // Do executes the "adsense.accounts.reports.generate" call.
  227. func (c *AccountsReportsGenerateCall) Do(opts ...googleapi.CallOption) error {
  228. gensupport.SetOptions(c.urlParams_, opts...)
  229. res, err := c.doRequest("json")
  230. if err != nil {
  231. return err
  232. }
  233. defer googleapi.CloseBody(res)
  234. if err := googleapi.CheckResponse(res); err != nil {
  235. return err
  236. }
  237. return nil
  238. // {
  239. // "description": "Generate an AdSense report based on the report request sent in the query parameters. Returns the result as JSON; to retrieve output in CSV format specify \"alt=csv\" as a query parameter.",
  240. // "httpMethod": "GET",
  241. // "id": "adsense.accounts.reports.generate",
  242. // "parameterOrder": [
  243. // "ids",
  244. // "currency",
  245. // "accountId",
  246. // "dimension"
  247. // ],
  248. // "parameters": {
  249. // "accountId": {
  250. // "description": "Account upon which to report.",
  251. // "location": "path",
  252. // "required": true,
  253. // "type": "string"
  254. // },
  255. // "currency": {
  256. // "description": "Optional currency to use when reporting on monetary metrics. Defaults to the account's currency if not set.",
  257. // "location": "query",
  258. // "pattern": "[a-zA-Z]+",
  259. // "type": "string"
  260. // },
  261. // "dimension": {
  262. // "description": "Dimensions to base the report on.",
  263. // "location": "query",
  264. // "pattern": "[a-zA-Z_]+",
  265. // "repeated": true,
  266. // "type": "string"
  267. // },
  268. // "ids": {
  269. // "description": "Select only user profiles with these IDs.",
  270. // "format": "int64",
  271. // "location": "query",
  272. // "repeated": true,
  273. // "type": "string"
  274. // }
  275. // },
  276. // "path": "accounts/{accountId}/reports"
  277. // }
  278. }