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.
 
 
 

352 lines
11 KiB

  1. // Package playcustomapp provides access to the Google Play Custom App Publishing API.
  2. //
  3. // See https://developers.google.com/android/work/play/custom-app-api
  4. //
  5. // Usage example:
  6. //
  7. // import "google.golang.org/api/playcustomapp/v1"
  8. // ...
  9. // playcustomappService, err := playcustomapp.New(oauthHttpClient)
  10. package playcustomapp // import "google.golang.org/api/playcustomapp/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 = "playcustomapp:v1"
  41. const apiName = "playcustomapp"
  42. const apiVersion = "v1"
  43. const basePath = "https://www.googleapis.com/playcustomapp/v1/accounts/"
  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.Accounts = NewAccountsService(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. Accounts *AccountsService
  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 NewAccountsService(s *Service) *AccountsService {
  70. rs := &AccountsService{s: s}
  71. rs.CustomApps = NewAccountsCustomAppsService(s)
  72. return rs
  73. }
  74. type AccountsService struct {
  75. s *Service
  76. CustomApps *AccountsCustomAppsService
  77. }
  78. func NewAccountsCustomAppsService(s *Service) *AccountsCustomAppsService {
  79. rs := &AccountsCustomAppsService{s: s}
  80. return rs
  81. }
  82. type AccountsCustomAppsService struct {
  83. s *Service
  84. }
  85. // CustomApp: This resource represents a custom app.
  86. type CustomApp struct {
  87. // LanguageCode: Default listing language in BCP 47 format.
  88. LanguageCode string `json:"languageCode,omitempty"`
  89. // Title: Title for the Android app.
  90. Title string `json:"title,omitempty"`
  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. "LanguageCode") 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. "LanguageCode") 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 *CustomApp) MarshalJSON() ([]byte, error) {
  110. type NoMethod CustomApp
  111. raw := NoMethod(*s)
  112. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  113. }
  114. // method id "playcustomapp.accounts.customApps.create":
  115. type AccountsCustomAppsCreateCall struct {
  116. s *Service
  117. account int64
  118. customapp *CustomApp
  119. urlParams_ gensupport.URLParams
  120. mediaInfo_ *gensupport.MediaInfo
  121. ctx_ context.Context
  122. header_ http.Header
  123. }
  124. // Create: Create and publish a new custom app.
  125. func (r *AccountsCustomAppsService) Create(account int64, customapp *CustomApp) *AccountsCustomAppsCreateCall {
  126. c := &AccountsCustomAppsCreateCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  127. c.account = account
  128. c.customapp = customapp
  129. return c
  130. }
  131. // Media specifies the media to upload in one or more chunks. The chunk
  132. // size may be controlled by supplying a MediaOption generated by
  133. // googleapi.ChunkSize. The chunk size defaults to
  134. // googleapi.DefaultUploadChunkSize.The Content-Type header used in the
  135. // upload request will be determined by sniffing the contents of r,
  136. // unless a MediaOption generated by googleapi.ContentType is
  137. // supplied.
  138. // At most one of Media and ResumableMedia may be set.
  139. func (c *AccountsCustomAppsCreateCall) Media(r io.Reader, options ...googleapi.MediaOption) *AccountsCustomAppsCreateCall {
  140. c.mediaInfo_ = gensupport.NewInfoFromMedia(r, options)
  141. return c
  142. }
  143. // ResumableMedia specifies the media to upload in chunks and can be
  144. // canceled with ctx.
  145. //
  146. // Deprecated: use Media instead.
  147. //
  148. // At most one of Media and ResumableMedia may be set. mediaType
  149. // identifies the MIME media type of the upload, such as "image/png". If
  150. // mediaType is "", it will be auto-detected. The provided ctx will
  151. // supersede any context previously provided to the Context method.
  152. func (c *AccountsCustomAppsCreateCall) ResumableMedia(ctx context.Context, r io.ReaderAt, size int64, mediaType string) *AccountsCustomAppsCreateCall {
  153. c.ctx_ = ctx
  154. c.mediaInfo_ = gensupport.NewInfoFromResumableMedia(r, size, mediaType)
  155. return c
  156. }
  157. // ProgressUpdater provides a callback function that will be called
  158. // after every chunk. It should be a low-latency function in order to
  159. // not slow down the upload operation. This should only be called when
  160. // using ResumableMedia (as opposed to Media).
  161. func (c *AccountsCustomAppsCreateCall) ProgressUpdater(pu googleapi.ProgressUpdater) *AccountsCustomAppsCreateCall {
  162. c.mediaInfo_.SetProgressUpdater(pu)
  163. return c
  164. }
  165. // Fields allows partial responses to be retrieved. See
  166. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  167. // for more information.
  168. func (c *AccountsCustomAppsCreateCall) Fields(s ...googleapi.Field) *AccountsCustomAppsCreateCall {
  169. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  170. return c
  171. }
  172. // Context sets the context to be used in this call's Do method. Any
  173. // pending HTTP request will be aborted if the provided context is
  174. // canceled.
  175. // This context will supersede any context previously provided to the
  176. // ResumableMedia method.
  177. func (c *AccountsCustomAppsCreateCall) Context(ctx context.Context) *AccountsCustomAppsCreateCall {
  178. c.ctx_ = ctx
  179. return c
  180. }
  181. // Header returns an http.Header that can be modified by the caller to
  182. // add HTTP headers to the request.
  183. func (c *AccountsCustomAppsCreateCall) Header() http.Header {
  184. if c.header_ == nil {
  185. c.header_ = make(http.Header)
  186. }
  187. return c.header_
  188. }
  189. func (c *AccountsCustomAppsCreateCall) doRequest(alt string) (*http.Response, error) {
  190. reqHeaders := make(http.Header)
  191. for k, v := range c.header_ {
  192. reqHeaders[k] = v
  193. }
  194. reqHeaders.Set("User-Agent", c.s.userAgent())
  195. var body io.Reader = nil
  196. body, err := googleapi.WithoutDataWrapper.JSONReader(c.customapp)
  197. if err != nil {
  198. return nil, err
  199. }
  200. reqHeaders.Set("Content-Type", "application/json")
  201. c.urlParams_.Set("alt", alt)
  202. urls := googleapi.ResolveRelative(c.s.BasePath, "{account}/customApps")
  203. if c.mediaInfo_ != nil {
  204. urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
  205. c.urlParams_.Set("uploadType", c.mediaInfo_.UploadType())
  206. }
  207. if body == nil {
  208. body = new(bytes.Buffer)
  209. reqHeaders.Set("Content-Type", "application/json")
  210. }
  211. body, getBody, cleanup := c.mediaInfo_.UploadRequest(reqHeaders, body)
  212. defer cleanup()
  213. urls += "?" + c.urlParams_.Encode()
  214. req, _ := http.NewRequest("POST", urls, body)
  215. req.Header = reqHeaders
  216. gensupport.SetGetBody(req, getBody)
  217. googleapi.Expand(req.URL, map[string]string{
  218. "account": strconv.FormatInt(c.account, 10),
  219. })
  220. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  221. }
  222. // Do executes the "playcustomapp.accounts.customApps.create" call.
  223. // Exactly one of *CustomApp or error will be non-nil. Any non-2xx
  224. // status code is an error. Response headers are in either
  225. // *CustomApp.ServerResponse.Header or (if a response was returned at
  226. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  227. // to check whether the returned error was because
  228. // http.StatusNotModified was returned.
  229. func (c *AccountsCustomAppsCreateCall) Do(opts ...googleapi.CallOption) (*CustomApp, error) {
  230. gensupport.SetOptions(c.urlParams_, opts...)
  231. res, err := c.doRequest("json")
  232. if res != nil && res.StatusCode == http.StatusNotModified {
  233. if res.Body != nil {
  234. res.Body.Close()
  235. }
  236. return nil, &googleapi.Error{
  237. Code: res.StatusCode,
  238. Header: res.Header,
  239. }
  240. }
  241. if err != nil {
  242. return nil, err
  243. }
  244. defer googleapi.CloseBody(res)
  245. if err := googleapi.CheckResponse(res); err != nil {
  246. return nil, err
  247. }
  248. rx := c.mediaInfo_.ResumableUpload(res.Header.Get("Location"))
  249. if rx != nil {
  250. rx.Client = c.s.client
  251. rx.UserAgent = c.s.userAgent()
  252. ctx := c.ctx_
  253. if ctx == nil {
  254. ctx = context.TODO()
  255. }
  256. res, err = rx.Upload(ctx)
  257. if err != nil {
  258. return nil, err
  259. }
  260. defer res.Body.Close()
  261. if err := googleapi.CheckResponse(res); err != nil {
  262. return nil, err
  263. }
  264. }
  265. ret := &CustomApp{
  266. ServerResponse: googleapi.ServerResponse{
  267. Header: res.Header,
  268. HTTPStatusCode: res.StatusCode,
  269. },
  270. }
  271. target := &ret
  272. if err := gensupport.DecodeResponse(target, res); err != nil {
  273. return nil, err
  274. }
  275. return ret, nil
  276. // {
  277. // "description": "Create and publish a new custom app.",
  278. // "httpMethod": "POST",
  279. // "id": "playcustomapp.accounts.customApps.create",
  280. // "mediaUpload": {
  281. // "accept": [
  282. // "*/*"
  283. // ],
  284. // "maxSize": "100MB",
  285. // "protocols": {
  286. // "resumable": {
  287. // "multipart": true,
  288. // "path": "/resumable/upload/playcustomapp/v1/accounts/{account}/customApps"
  289. // },
  290. // "simple": {
  291. // "multipart": true,
  292. // "path": "/upload/playcustomapp/v1/accounts/{account}/customApps"
  293. // }
  294. // }
  295. // },
  296. // "parameterOrder": [
  297. // "account"
  298. // ],
  299. // "parameters": {
  300. // "account": {
  301. // "description": "Developer account ID.",
  302. // "format": "int64",
  303. // "location": "path",
  304. // "required": true,
  305. // "type": "string"
  306. // }
  307. // },
  308. // "path": "{account}/customApps",
  309. // "request": {
  310. // "$ref": "CustomApp"
  311. // },
  312. // "response": {
  313. // "$ref": "CustomApp"
  314. // },
  315. // "scopes": [
  316. // "https://www.googleapis.com/auth/androidpublisher"
  317. // ],
  318. // "supportsMediaUpload": true
  319. // }
  320. }