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.
 
 
 

641 lines
20 KiB

  1. // Package androidpublisher provides access to the Google Play Developer API.
  2. //
  3. // See https://developers.google.com/android-publisher
  4. //
  5. // Usage example:
  6. //
  7. // import "google.golang.org/api/androidpublisher/v1.1"
  8. // ...
  9. // androidpublisherService, err := androidpublisher.New(oauthHttpClient)
  10. package androidpublisher // import "google.golang.org/api/androidpublisher/v1.1"
  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 = "androidpublisher:v1.1"
  41. const apiName = "androidpublisher"
  42. const apiVersion = "v1.1"
  43. const basePath = "https://www.googleapis.com/androidpublisher/v1.1/applications/"
  44. // OAuth2 scopes used by this API.
  45. const (
  46. // View and manage your Google Play Developer account
  47. AndroidpublisherScope = "https://www.googleapis.com/auth/androidpublisher"
  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.Inapppurchases = NewInapppurchasesService(s)
  55. s.Purchases = NewPurchasesService(s)
  56. return s, nil
  57. }
  58. type Service struct {
  59. client *http.Client
  60. BasePath string // API endpoint base URL
  61. UserAgent string // optional additional User-Agent fragment
  62. Inapppurchases *InapppurchasesService
  63. Purchases *PurchasesService
  64. }
  65. func (s *Service) userAgent() string {
  66. if s.UserAgent == "" {
  67. return googleapi.UserAgent
  68. }
  69. return googleapi.UserAgent + " " + s.UserAgent
  70. }
  71. func NewInapppurchasesService(s *Service) *InapppurchasesService {
  72. rs := &InapppurchasesService{s: s}
  73. return rs
  74. }
  75. type InapppurchasesService struct {
  76. s *Service
  77. }
  78. func NewPurchasesService(s *Service) *PurchasesService {
  79. rs := &PurchasesService{s: s}
  80. return rs
  81. }
  82. type PurchasesService struct {
  83. s *Service
  84. }
  85. // InappPurchase: An InappPurchase resource indicates the status of a
  86. // user's inapp product purchase.
  87. type InappPurchase struct {
  88. // ConsumptionState: The consumption state of the inapp product.
  89. // Possible values are:
  90. // - Yet to be consumed
  91. // - Consumed
  92. ConsumptionState int64 `json:"consumptionState,omitempty"`
  93. // DeveloperPayload: A developer-specified string that contains
  94. // supplemental information about an order.
  95. DeveloperPayload string `json:"developerPayload,omitempty"`
  96. // Kind: This kind represents an inappPurchase object in the
  97. // androidpublisher service.
  98. Kind string `json:"kind,omitempty"`
  99. // OrderId: The order id associated with the purchase of the inapp
  100. // product.
  101. OrderId string `json:"orderId,omitempty"`
  102. // PurchaseState: The purchase state of the order. Possible values are:
  103. //
  104. // - Purchased
  105. // - Canceled
  106. PurchaseState int64 `json:"purchaseState,omitempty"`
  107. // PurchaseTime: The time the product was purchased, in milliseconds
  108. // since the epoch (Jan 1, 1970).
  109. PurchaseTime int64 `json:"purchaseTime,omitempty,string"`
  110. // PurchaseType: The type of purchase of the inapp product. This field
  111. // is only set if this purchase was not made using the standard in-app
  112. // billing flow. Possible values are:
  113. // - Test (i.e. purchased from a license testing account)
  114. // - Promo (i.e. purchased using a promo code)
  115. PurchaseType int64 `json:"purchaseType,omitempty"`
  116. // ServerResponse contains the HTTP response code and headers from the
  117. // server.
  118. googleapi.ServerResponse `json:"-"`
  119. // ForceSendFields is a list of field names (e.g. "ConsumptionState") to
  120. // unconditionally include in API requests. By default, fields with
  121. // empty values are omitted from API requests. However, any non-pointer,
  122. // non-interface field appearing in ForceSendFields will be sent to the
  123. // server regardless of whether the field is empty or not. This may be
  124. // used to include empty fields in Patch requests.
  125. ForceSendFields []string `json:"-"`
  126. // NullFields is a list of field names (e.g. "ConsumptionState") to
  127. // include in API requests with the JSON null value. By default, fields
  128. // with empty values are omitted from API requests. However, any field
  129. // with an empty value appearing in NullFields will be sent to the
  130. // server as null. It is an error if a field in this list has a
  131. // non-empty value. This may be used to include null fields in Patch
  132. // requests.
  133. NullFields []string `json:"-"`
  134. }
  135. func (s *InappPurchase) MarshalJSON() ([]byte, error) {
  136. type NoMethod InappPurchase
  137. raw := NoMethod(*s)
  138. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  139. }
  140. // SubscriptionPurchase: A SubscriptionPurchase resource indicates the
  141. // status of a user's subscription purchase.
  142. type SubscriptionPurchase struct {
  143. // AutoRenewing: Whether the subscription will automatically be renewed
  144. // when it reaches its current expiry time.
  145. AutoRenewing bool `json:"autoRenewing,omitempty"`
  146. // InitiationTimestampMsec: Time at which the subscription was granted,
  147. // in milliseconds since the Epoch.
  148. InitiationTimestampMsec int64 `json:"initiationTimestampMsec,omitempty,string"`
  149. // Kind: This kind represents a subscriptionPurchase object in the
  150. // androidpublisher service.
  151. Kind string `json:"kind,omitempty"`
  152. // ValidUntilTimestampMsec: Time at which the subscription will expire,
  153. // in milliseconds since the Epoch.
  154. ValidUntilTimestampMsec int64 `json:"validUntilTimestampMsec,omitempty,string"`
  155. // ServerResponse contains the HTTP response code and headers from the
  156. // server.
  157. googleapi.ServerResponse `json:"-"`
  158. // ForceSendFields is a list of field names (e.g. "AutoRenewing") to
  159. // unconditionally include in API requests. By default, fields with
  160. // empty values are omitted from API requests. However, any non-pointer,
  161. // non-interface field appearing in ForceSendFields will be sent to the
  162. // server regardless of whether the field is empty or not. This may be
  163. // used to include empty fields in Patch requests.
  164. ForceSendFields []string `json:"-"`
  165. // NullFields is a list of field names (e.g. "AutoRenewing") to include
  166. // in API requests with the JSON null value. By default, fields with
  167. // empty values are omitted from API requests. However, any field with
  168. // an empty value appearing in NullFields will be sent to the server as
  169. // null. It is an error if a field in this list has a non-empty value.
  170. // This may be used to include null fields in Patch requests.
  171. NullFields []string `json:"-"`
  172. }
  173. func (s *SubscriptionPurchase) MarshalJSON() ([]byte, error) {
  174. type NoMethod SubscriptionPurchase
  175. raw := NoMethod(*s)
  176. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  177. }
  178. // method id "androidpublisher.inapppurchases.get":
  179. type InapppurchasesGetCall struct {
  180. s *Service
  181. packageName string
  182. productId string
  183. token string
  184. urlParams_ gensupport.URLParams
  185. ifNoneMatch_ string
  186. ctx_ context.Context
  187. header_ http.Header
  188. }
  189. // Get: Checks the purchase and consumption status of an inapp item.
  190. func (r *InapppurchasesService) Get(packageName string, productId string, token string) *InapppurchasesGetCall {
  191. c := &InapppurchasesGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  192. c.packageName = packageName
  193. c.productId = productId
  194. c.token = token
  195. return c
  196. }
  197. // Fields allows partial responses to be retrieved. See
  198. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  199. // for more information.
  200. func (c *InapppurchasesGetCall) Fields(s ...googleapi.Field) *InapppurchasesGetCall {
  201. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  202. return c
  203. }
  204. // IfNoneMatch sets the optional parameter which makes the operation
  205. // fail if the object's ETag matches the given value. This is useful for
  206. // getting updates only after the object has changed since the last
  207. // request. Use googleapi.IsNotModified to check whether the response
  208. // error from Do is the result of In-None-Match.
  209. func (c *InapppurchasesGetCall) IfNoneMatch(entityTag string) *InapppurchasesGetCall {
  210. c.ifNoneMatch_ = entityTag
  211. return c
  212. }
  213. // Context sets the context to be used in this call's Do method. Any
  214. // pending HTTP request will be aborted if the provided context is
  215. // canceled.
  216. func (c *InapppurchasesGetCall) Context(ctx context.Context) *InapppurchasesGetCall {
  217. c.ctx_ = ctx
  218. return c
  219. }
  220. // Header returns an http.Header that can be modified by the caller to
  221. // add HTTP headers to the request.
  222. func (c *InapppurchasesGetCall) Header() http.Header {
  223. if c.header_ == nil {
  224. c.header_ = make(http.Header)
  225. }
  226. return c.header_
  227. }
  228. func (c *InapppurchasesGetCall) doRequest(alt string) (*http.Response, error) {
  229. reqHeaders := make(http.Header)
  230. for k, v := range c.header_ {
  231. reqHeaders[k] = v
  232. }
  233. reqHeaders.Set("User-Agent", c.s.userAgent())
  234. if c.ifNoneMatch_ != "" {
  235. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  236. }
  237. var body io.Reader = nil
  238. c.urlParams_.Set("alt", alt)
  239. urls := googleapi.ResolveRelative(c.s.BasePath, "{packageName}/inapp/{productId}/purchases/{token}")
  240. urls += "?" + c.urlParams_.Encode()
  241. req, _ := http.NewRequest("GET", urls, body)
  242. req.Header = reqHeaders
  243. googleapi.Expand(req.URL, map[string]string{
  244. "packageName": c.packageName,
  245. "productId": c.productId,
  246. "token": c.token,
  247. })
  248. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  249. }
  250. // Do executes the "androidpublisher.inapppurchases.get" call.
  251. // Exactly one of *InappPurchase or error will be non-nil. Any non-2xx
  252. // status code is an error. Response headers are in either
  253. // *InappPurchase.ServerResponse.Header or (if a response was returned
  254. // at all) in error.(*googleapi.Error).Header. Use
  255. // googleapi.IsNotModified to check whether the returned error was
  256. // because http.StatusNotModified was returned.
  257. func (c *InapppurchasesGetCall) Do(opts ...googleapi.CallOption) (*InappPurchase, error) {
  258. gensupport.SetOptions(c.urlParams_, opts...)
  259. res, err := c.doRequest("json")
  260. if res != nil && res.StatusCode == http.StatusNotModified {
  261. if res.Body != nil {
  262. res.Body.Close()
  263. }
  264. return nil, &googleapi.Error{
  265. Code: res.StatusCode,
  266. Header: res.Header,
  267. }
  268. }
  269. if err != nil {
  270. return nil, err
  271. }
  272. defer googleapi.CloseBody(res)
  273. if err := googleapi.CheckResponse(res); err != nil {
  274. return nil, err
  275. }
  276. ret := &InappPurchase{
  277. ServerResponse: googleapi.ServerResponse{
  278. Header: res.Header,
  279. HTTPStatusCode: res.StatusCode,
  280. },
  281. }
  282. target := &ret
  283. if err := gensupport.DecodeResponse(target, res); err != nil {
  284. return nil, err
  285. }
  286. return ret, nil
  287. // {
  288. // "description": "Checks the purchase and consumption status of an inapp item.",
  289. // "httpMethod": "GET",
  290. // "id": "androidpublisher.inapppurchases.get",
  291. // "parameterOrder": [
  292. // "packageName",
  293. // "productId",
  294. // "token"
  295. // ],
  296. // "parameters": {
  297. // "packageName": {
  298. // "description": "The package name of the application the inapp product was sold in (for example, 'com.some.thing').",
  299. // "location": "path",
  300. // "required": true,
  301. // "type": "string"
  302. // },
  303. // "productId": {
  304. // "description": "The inapp product SKU (for example, 'com.some.thing.inapp1').",
  305. // "location": "path",
  306. // "required": true,
  307. // "type": "string"
  308. // },
  309. // "token": {
  310. // "description": "The token provided to the user's device when the inapp product was purchased.",
  311. // "location": "path",
  312. // "required": true,
  313. // "type": "string"
  314. // }
  315. // },
  316. // "path": "{packageName}/inapp/{productId}/purchases/{token}",
  317. // "response": {
  318. // "$ref": "InappPurchase"
  319. // },
  320. // "scopes": [
  321. // "https://www.googleapis.com/auth/androidpublisher"
  322. // ]
  323. // }
  324. }
  325. // method id "androidpublisher.purchases.cancel":
  326. type PurchasesCancelCall struct {
  327. s *Service
  328. packageName string
  329. subscriptionId string
  330. token string
  331. urlParams_ gensupport.URLParams
  332. ctx_ context.Context
  333. header_ http.Header
  334. }
  335. // Cancel: Cancels a user's subscription purchase. The subscription
  336. // remains valid until its expiration time.
  337. func (r *PurchasesService) Cancel(packageName string, subscriptionId string, token string) *PurchasesCancelCall {
  338. c := &PurchasesCancelCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  339. c.packageName = packageName
  340. c.subscriptionId = subscriptionId
  341. c.token = token
  342. return c
  343. }
  344. // Fields allows partial responses to be retrieved. See
  345. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  346. // for more information.
  347. func (c *PurchasesCancelCall) Fields(s ...googleapi.Field) *PurchasesCancelCall {
  348. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  349. return c
  350. }
  351. // Context sets the context to be used in this call's Do method. Any
  352. // pending HTTP request will be aborted if the provided context is
  353. // canceled.
  354. func (c *PurchasesCancelCall) Context(ctx context.Context) *PurchasesCancelCall {
  355. c.ctx_ = ctx
  356. return c
  357. }
  358. // Header returns an http.Header that can be modified by the caller to
  359. // add HTTP headers to the request.
  360. func (c *PurchasesCancelCall) Header() http.Header {
  361. if c.header_ == nil {
  362. c.header_ = make(http.Header)
  363. }
  364. return c.header_
  365. }
  366. func (c *PurchasesCancelCall) doRequest(alt string) (*http.Response, error) {
  367. reqHeaders := make(http.Header)
  368. for k, v := range c.header_ {
  369. reqHeaders[k] = v
  370. }
  371. reqHeaders.Set("User-Agent", c.s.userAgent())
  372. var body io.Reader = nil
  373. c.urlParams_.Set("alt", alt)
  374. urls := googleapi.ResolveRelative(c.s.BasePath, "{packageName}/subscriptions/{subscriptionId}/purchases/{token}/cancel")
  375. urls += "?" + c.urlParams_.Encode()
  376. req, _ := http.NewRequest("POST", urls, body)
  377. req.Header = reqHeaders
  378. googleapi.Expand(req.URL, map[string]string{
  379. "packageName": c.packageName,
  380. "subscriptionId": c.subscriptionId,
  381. "token": c.token,
  382. })
  383. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  384. }
  385. // Do executes the "androidpublisher.purchases.cancel" call.
  386. func (c *PurchasesCancelCall) Do(opts ...googleapi.CallOption) error {
  387. gensupport.SetOptions(c.urlParams_, opts...)
  388. res, err := c.doRequest("json")
  389. if err != nil {
  390. return err
  391. }
  392. defer googleapi.CloseBody(res)
  393. if err := googleapi.CheckResponse(res); err != nil {
  394. return err
  395. }
  396. return nil
  397. // {
  398. // "description": "Cancels a user's subscription purchase. The subscription remains valid until its expiration time.",
  399. // "httpMethod": "POST",
  400. // "id": "androidpublisher.purchases.cancel",
  401. // "parameterOrder": [
  402. // "packageName",
  403. // "subscriptionId",
  404. // "token"
  405. // ],
  406. // "parameters": {
  407. // "packageName": {
  408. // "description": "The package name of the application for which this subscription was purchased (for example, 'com.some.thing').",
  409. // "location": "path",
  410. // "required": true,
  411. // "type": "string"
  412. // },
  413. // "subscriptionId": {
  414. // "description": "The purchased subscription ID (for example, 'monthly001').",
  415. // "location": "path",
  416. // "required": true,
  417. // "type": "string"
  418. // },
  419. // "token": {
  420. // "description": "The token provided to the user's device when the subscription was purchased.",
  421. // "location": "path",
  422. // "required": true,
  423. // "type": "string"
  424. // }
  425. // },
  426. // "path": "{packageName}/subscriptions/{subscriptionId}/purchases/{token}/cancel",
  427. // "scopes": [
  428. // "https://www.googleapis.com/auth/androidpublisher"
  429. // ]
  430. // }
  431. }
  432. // method id "androidpublisher.purchases.get":
  433. type PurchasesGetCall struct {
  434. s *Service
  435. packageName string
  436. subscriptionId string
  437. token string
  438. urlParams_ gensupport.URLParams
  439. ifNoneMatch_ string
  440. ctx_ context.Context
  441. header_ http.Header
  442. }
  443. // Get: Checks whether a user's subscription purchase is valid and
  444. // returns its expiry time.
  445. func (r *PurchasesService) Get(packageName string, subscriptionId string, token string) *PurchasesGetCall {
  446. c := &PurchasesGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  447. c.packageName = packageName
  448. c.subscriptionId = subscriptionId
  449. c.token = token
  450. return c
  451. }
  452. // Fields allows partial responses to be retrieved. See
  453. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  454. // for more information.
  455. func (c *PurchasesGetCall) Fields(s ...googleapi.Field) *PurchasesGetCall {
  456. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  457. return c
  458. }
  459. // IfNoneMatch sets the optional parameter which makes the operation
  460. // fail if the object's ETag matches the given value. This is useful for
  461. // getting updates only after the object has changed since the last
  462. // request. Use googleapi.IsNotModified to check whether the response
  463. // error from Do is the result of In-None-Match.
  464. func (c *PurchasesGetCall) IfNoneMatch(entityTag string) *PurchasesGetCall {
  465. c.ifNoneMatch_ = entityTag
  466. return c
  467. }
  468. // Context sets the context to be used in this call's Do method. Any
  469. // pending HTTP request will be aborted if the provided context is
  470. // canceled.
  471. func (c *PurchasesGetCall) Context(ctx context.Context) *PurchasesGetCall {
  472. c.ctx_ = ctx
  473. return c
  474. }
  475. // Header returns an http.Header that can be modified by the caller to
  476. // add HTTP headers to the request.
  477. func (c *PurchasesGetCall) Header() http.Header {
  478. if c.header_ == nil {
  479. c.header_ = make(http.Header)
  480. }
  481. return c.header_
  482. }
  483. func (c *PurchasesGetCall) doRequest(alt string) (*http.Response, error) {
  484. reqHeaders := make(http.Header)
  485. for k, v := range c.header_ {
  486. reqHeaders[k] = v
  487. }
  488. reqHeaders.Set("User-Agent", c.s.userAgent())
  489. if c.ifNoneMatch_ != "" {
  490. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  491. }
  492. var body io.Reader = nil
  493. c.urlParams_.Set("alt", alt)
  494. urls := googleapi.ResolveRelative(c.s.BasePath, "{packageName}/subscriptions/{subscriptionId}/purchases/{token}")
  495. urls += "?" + c.urlParams_.Encode()
  496. req, _ := http.NewRequest("GET", urls, body)
  497. req.Header = reqHeaders
  498. googleapi.Expand(req.URL, map[string]string{
  499. "packageName": c.packageName,
  500. "subscriptionId": c.subscriptionId,
  501. "token": c.token,
  502. })
  503. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  504. }
  505. // Do executes the "androidpublisher.purchases.get" call.
  506. // Exactly one of *SubscriptionPurchase or error will be non-nil. Any
  507. // non-2xx status code is an error. Response headers are in either
  508. // *SubscriptionPurchase.ServerResponse.Header or (if a response was
  509. // returned at all) in error.(*googleapi.Error).Header. Use
  510. // googleapi.IsNotModified to check whether the returned error was
  511. // because http.StatusNotModified was returned.
  512. func (c *PurchasesGetCall) Do(opts ...googleapi.CallOption) (*SubscriptionPurchase, error) {
  513. gensupport.SetOptions(c.urlParams_, opts...)
  514. res, err := c.doRequest("json")
  515. if res != nil && res.StatusCode == http.StatusNotModified {
  516. if res.Body != nil {
  517. res.Body.Close()
  518. }
  519. return nil, &googleapi.Error{
  520. Code: res.StatusCode,
  521. Header: res.Header,
  522. }
  523. }
  524. if err != nil {
  525. return nil, err
  526. }
  527. defer googleapi.CloseBody(res)
  528. if err := googleapi.CheckResponse(res); err != nil {
  529. return nil, err
  530. }
  531. ret := &SubscriptionPurchase{
  532. ServerResponse: googleapi.ServerResponse{
  533. Header: res.Header,
  534. HTTPStatusCode: res.StatusCode,
  535. },
  536. }
  537. target := &ret
  538. if err := gensupport.DecodeResponse(target, res); err != nil {
  539. return nil, err
  540. }
  541. return ret, nil
  542. // {
  543. // "description": "Checks whether a user's subscription purchase is valid and returns its expiry time.",
  544. // "httpMethod": "GET",
  545. // "id": "androidpublisher.purchases.get",
  546. // "parameterOrder": [
  547. // "packageName",
  548. // "subscriptionId",
  549. // "token"
  550. // ],
  551. // "parameters": {
  552. // "packageName": {
  553. // "description": "The package name of the application for which this subscription was purchased (for example, 'com.some.thing').",
  554. // "location": "path",
  555. // "required": true,
  556. // "type": "string"
  557. // },
  558. // "subscriptionId": {
  559. // "description": "The purchased subscription ID (for example, 'monthly001').",
  560. // "location": "path",
  561. // "required": true,
  562. // "type": "string"
  563. // },
  564. // "token": {
  565. // "description": "The token provided to the user's device when the subscription was purchased.",
  566. // "location": "path",
  567. // "required": true,
  568. // "type": "string"
  569. // }
  570. // },
  571. // "path": "{packageName}/subscriptions/{subscriptionId}/purchases/{token}",
  572. // "response": {
  573. // "$ref": "SubscriptionPurchase"
  574. // },
  575. // "scopes": [
  576. // "https://www.googleapis.com/auth/androidpublisher"
  577. // ]
  578. // }
  579. }