Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

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