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.
 
 
 

469 lines
15 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 androidpublisher provides access to the Google Play Developer API.
  6. //
  7. // For product documentation, see: https://developers.google.com/android-publisher
  8. //
  9. // Creating a client
  10. //
  11. // Usage example:
  12. //
  13. // import "google.golang.org/api/androidpublisher/v1"
  14. // ...
  15. // ctx := context.Background()
  16. // androidpublisherService, err := androidpublisher.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. // androidpublisherService, err := androidpublisher.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. // androidpublisherService, err := androidpublisher.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 androidpublisher // import "google.golang.org/api/androidpublisher/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 = "androidpublisher:v1"
  67. const apiName = "androidpublisher"
  68. const apiVersion = "v1"
  69. const basePath = "https://www.googleapis.com/androidpublisher/v1/applications/"
  70. // OAuth2 scopes used by this API.
  71. const (
  72. // View and manage your Google Play Developer account
  73. AndroidpublisherScope = "https://www.googleapis.com/auth/androidpublisher"
  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/androidpublisher",
  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.Purchases = NewPurchasesService(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. Purchases *PurchasesService
  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 NewPurchasesService(s *Service) *PurchasesService {
  121. rs := &PurchasesService{s: s}
  122. return rs
  123. }
  124. type PurchasesService struct {
  125. s *Service
  126. }
  127. // SubscriptionPurchase: A SubscriptionPurchase resource indicates the
  128. // status of a user's subscription purchase.
  129. type SubscriptionPurchase struct {
  130. // AutoRenewing: Whether the subscription will automatically be renewed
  131. // when it reaches its current expiry time.
  132. AutoRenewing bool `json:"autoRenewing,omitempty"`
  133. // InitiationTimestampMsec: Time at which the subscription was granted,
  134. // in milliseconds since the Epoch.
  135. InitiationTimestampMsec int64 `json:"initiationTimestampMsec,omitempty,string"`
  136. // Kind: This kind represents a subscriptionPurchase object in the
  137. // androidpublisher service.
  138. Kind string `json:"kind,omitempty"`
  139. // ValidUntilTimestampMsec: Time at which the subscription will expire,
  140. // in milliseconds since the Epoch.
  141. ValidUntilTimestampMsec int64 `json:"validUntilTimestampMsec,omitempty,string"`
  142. // ServerResponse contains the HTTP response code and headers from the
  143. // server.
  144. googleapi.ServerResponse `json:"-"`
  145. // ForceSendFields is a list of field names (e.g. "AutoRenewing") to
  146. // unconditionally include in API requests. By default, fields with
  147. // empty values are omitted from API requests. However, any non-pointer,
  148. // non-interface field appearing in ForceSendFields will be sent to the
  149. // server regardless of whether the field is empty or not. This may be
  150. // used to include empty fields in Patch requests.
  151. ForceSendFields []string `json:"-"`
  152. // NullFields is a list of field names (e.g. "AutoRenewing") to include
  153. // in API requests with the JSON null value. By default, fields with
  154. // empty values are omitted from API requests. However, any field with
  155. // an empty value appearing in NullFields will be sent to the server as
  156. // null. It is an error if a field in this list has a non-empty value.
  157. // This may be used to include null fields in Patch requests.
  158. NullFields []string `json:"-"`
  159. }
  160. func (s *SubscriptionPurchase) MarshalJSON() ([]byte, error) {
  161. type NoMethod SubscriptionPurchase
  162. raw := NoMethod(*s)
  163. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  164. }
  165. // method id "androidpublisher.purchases.cancel":
  166. type PurchasesCancelCall struct {
  167. s *Service
  168. packageName string
  169. subscriptionId string
  170. token string
  171. urlParams_ gensupport.URLParams
  172. ctx_ context.Context
  173. header_ http.Header
  174. }
  175. // Cancel: Cancels a user's subscription purchase. The subscription
  176. // remains valid until its expiration time.
  177. func (r *PurchasesService) Cancel(packageName string, subscriptionId string, token string) *PurchasesCancelCall {
  178. c := &PurchasesCancelCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  179. c.packageName = packageName
  180. c.subscriptionId = subscriptionId
  181. c.token = token
  182. return c
  183. }
  184. // Fields allows partial responses to be retrieved. See
  185. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  186. // for more information.
  187. func (c *PurchasesCancelCall) Fields(s ...googleapi.Field) *PurchasesCancelCall {
  188. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  189. return c
  190. }
  191. // Context sets the context to be used in this call's Do method. Any
  192. // pending HTTP request will be aborted if the provided context is
  193. // canceled.
  194. func (c *PurchasesCancelCall) Context(ctx context.Context) *PurchasesCancelCall {
  195. c.ctx_ = ctx
  196. return c
  197. }
  198. // Header returns an http.Header that can be modified by the caller to
  199. // add HTTP headers to the request.
  200. func (c *PurchasesCancelCall) Header() http.Header {
  201. if c.header_ == nil {
  202. c.header_ = make(http.Header)
  203. }
  204. return c.header_
  205. }
  206. func (c *PurchasesCancelCall) doRequest(alt string) (*http.Response, error) {
  207. reqHeaders := make(http.Header)
  208. for k, v := range c.header_ {
  209. reqHeaders[k] = v
  210. }
  211. reqHeaders.Set("User-Agent", c.s.userAgent())
  212. var body io.Reader = nil
  213. c.urlParams_.Set("alt", alt)
  214. c.urlParams_.Set("prettyPrint", "false")
  215. urls := googleapi.ResolveRelative(c.s.BasePath, "{packageName}/subscriptions/{subscriptionId}/purchases/{token}/cancel")
  216. urls += "?" + c.urlParams_.Encode()
  217. req, err := http.NewRequest("POST", urls, body)
  218. if err != nil {
  219. return nil, err
  220. }
  221. req.Header = reqHeaders
  222. googleapi.Expand(req.URL, map[string]string{
  223. "packageName": c.packageName,
  224. "subscriptionId": c.subscriptionId,
  225. "token": c.token,
  226. })
  227. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  228. }
  229. // Do executes the "androidpublisher.purchases.cancel" call.
  230. func (c *PurchasesCancelCall) Do(opts ...googleapi.CallOption) error {
  231. gensupport.SetOptions(c.urlParams_, opts...)
  232. res, err := c.doRequest("json")
  233. if err != nil {
  234. return err
  235. }
  236. defer googleapi.CloseBody(res)
  237. if err := googleapi.CheckResponse(res); err != nil {
  238. return err
  239. }
  240. return nil
  241. // {
  242. // "description": "Cancels a user's subscription purchase. The subscription remains valid until its expiration time.",
  243. // "httpMethod": "POST",
  244. // "id": "androidpublisher.purchases.cancel",
  245. // "parameterOrder": [
  246. // "packageName",
  247. // "subscriptionId",
  248. // "token"
  249. // ],
  250. // "parameters": {
  251. // "packageName": {
  252. // "description": "The package name of the application for which this subscription was purchased (for example, 'com.some.thing').",
  253. // "location": "path",
  254. // "required": true,
  255. // "type": "string"
  256. // },
  257. // "subscriptionId": {
  258. // "description": "The purchased subscription ID (for example, 'monthly001').",
  259. // "location": "path",
  260. // "required": true,
  261. // "type": "string"
  262. // },
  263. // "token": {
  264. // "description": "The token provided to the user's device when the subscription was purchased.",
  265. // "location": "path",
  266. // "required": true,
  267. // "type": "string"
  268. // }
  269. // },
  270. // "path": "{packageName}/subscriptions/{subscriptionId}/purchases/{token}/cancel",
  271. // "scopes": [
  272. // "https://www.googleapis.com/auth/androidpublisher"
  273. // ]
  274. // }
  275. }
  276. // method id "androidpublisher.purchases.get":
  277. type PurchasesGetCall struct {
  278. s *Service
  279. packageName string
  280. subscriptionId string
  281. token string
  282. urlParams_ gensupport.URLParams
  283. ifNoneMatch_ string
  284. ctx_ context.Context
  285. header_ http.Header
  286. }
  287. // Get: Checks whether a user's subscription purchase is valid and
  288. // returns its expiry time.
  289. func (r *PurchasesService) Get(packageName string, subscriptionId string, token string) *PurchasesGetCall {
  290. c := &PurchasesGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  291. c.packageName = packageName
  292. c.subscriptionId = subscriptionId
  293. c.token = token
  294. return c
  295. }
  296. // Fields allows partial responses to be retrieved. See
  297. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  298. // for more information.
  299. func (c *PurchasesGetCall) Fields(s ...googleapi.Field) *PurchasesGetCall {
  300. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  301. return c
  302. }
  303. // IfNoneMatch sets the optional parameter which makes the operation
  304. // fail if the object's ETag matches the given value. This is useful for
  305. // getting updates only after the object has changed since the last
  306. // request. Use googleapi.IsNotModified to check whether the response
  307. // error from Do is the result of In-None-Match.
  308. func (c *PurchasesGetCall) IfNoneMatch(entityTag string) *PurchasesGetCall {
  309. c.ifNoneMatch_ = entityTag
  310. return c
  311. }
  312. // Context sets the context to be used in this call's Do method. Any
  313. // pending HTTP request will be aborted if the provided context is
  314. // canceled.
  315. func (c *PurchasesGetCall) Context(ctx context.Context) *PurchasesGetCall {
  316. c.ctx_ = ctx
  317. return c
  318. }
  319. // Header returns an http.Header that can be modified by the caller to
  320. // add HTTP headers to the request.
  321. func (c *PurchasesGetCall) Header() http.Header {
  322. if c.header_ == nil {
  323. c.header_ = make(http.Header)
  324. }
  325. return c.header_
  326. }
  327. func (c *PurchasesGetCall) doRequest(alt string) (*http.Response, error) {
  328. reqHeaders := make(http.Header)
  329. for k, v := range c.header_ {
  330. reqHeaders[k] = v
  331. }
  332. reqHeaders.Set("User-Agent", c.s.userAgent())
  333. if c.ifNoneMatch_ != "" {
  334. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  335. }
  336. var body io.Reader = nil
  337. c.urlParams_.Set("alt", alt)
  338. c.urlParams_.Set("prettyPrint", "false")
  339. urls := googleapi.ResolveRelative(c.s.BasePath, "{packageName}/subscriptions/{subscriptionId}/purchases/{token}")
  340. urls += "?" + c.urlParams_.Encode()
  341. req, err := http.NewRequest("GET", urls, body)
  342. if err != nil {
  343. return nil, err
  344. }
  345. req.Header = reqHeaders
  346. googleapi.Expand(req.URL, map[string]string{
  347. "packageName": c.packageName,
  348. "subscriptionId": c.subscriptionId,
  349. "token": c.token,
  350. })
  351. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  352. }
  353. // Do executes the "androidpublisher.purchases.get" call.
  354. // Exactly one of *SubscriptionPurchase or error will be non-nil. Any
  355. // non-2xx status code is an error. Response headers are in either
  356. // *SubscriptionPurchase.ServerResponse.Header or (if a response was
  357. // returned at all) in error.(*googleapi.Error).Header. Use
  358. // googleapi.IsNotModified to check whether the returned error was
  359. // because http.StatusNotModified was returned.
  360. func (c *PurchasesGetCall) Do(opts ...googleapi.CallOption) (*SubscriptionPurchase, error) {
  361. gensupport.SetOptions(c.urlParams_, opts...)
  362. res, err := c.doRequest("json")
  363. if res != nil && res.StatusCode == http.StatusNotModified {
  364. if res.Body != nil {
  365. res.Body.Close()
  366. }
  367. return nil, &googleapi.Error{
  368. Code: res.StatusCode,
  369. Header: res.Header,
  370. }
  371. }
  372. if err != nil {
  373. return nil, err
  374. }
  375. defer googleapi.CloseBody(res)
  376. if err := googleapi.CheckResponse(res); err != nil {
  377. return nil, err
  378. }
  379. ret := &SubscriptionPurchase{
  380. ServerResponse: googleapi.ServerResponse{
  381. Header: res.Header,
  382. HTTPStatusCode: res.StatusCode,
  383. },
  384. }
  385. target := &ret
  386. if err := gensupport.DecodeResponse(target, res); err != nil {
  387. return nil, err
  388. }
  389. return ret, nil
  390. // {
  391. // "description": "Checks whether a user's subscription purchase is valid and returns its expiry time.",
  392. // "httpMethod": "GET",
  393. // "id": "androidpublisher.purchases.get",
  394. // "parameterOrder": [
  395. // "packageName",
  396. // "subscriptionId",
  397. // "token"
  398. // ],
  399. // "parameters": {
  400. // "packageName": {
  401. // "description": "The package name of the application for which this subscription was purchased (for example, 'com.some.thing').",
  402. // "location": "path",
  403. // "required": true,
  404. // "type": "string"
  405. // },
  406. // "subscriptionId": {
  407. // "description": "The purchased subscription ID (for example, 'monthly001').",
  408. // "location": "path",
  409. // "required": true,
  410. // "type": "string"
  411. // },
  412. // "token": {
  413. // "description": "The token provided to the user's device when the subscription was purchased.",
  414. // "location": "path",
  415. // "required": true,
  416. // "type": "string"
  417. // }
  418. // },
  419. // "path": "{packageName}/subscriptions/{subscriptionId}/purchases/{token}",
  420. // "response": {
  421. // "$ref": "SubscriptionPurchase"
  422. // },
  423. // "scopes": [
  424. // "https://www.googleapis.com/auth/androidpublisher"
  425. // ]
  426. // }
  427. }