Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

920 строки
30 KiB

  1. // Package appstate provides access to the Google App State API.
  2. //
  3. // See https://developers.google.com/games/services/web/api/states
  4. //
  5. // Usage example:
  6. //
  7. // import "google.golang.org/api/appstate/v1"
  8. // ...
  9. // appstateService, err := appstate.New(oauthHttpClient)
  10. package appstate // import "google.golang.org/api/appstate/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 = "appstate:v1"
  41. const apiName = "appstate"
  42. const apiVersion = "v1"
  43. const basePath = "https://www.googleapis.com/appstate/v1/"
  44. // OAuth2 scopes used by this API.
  45. const (
  46. // View and manage your data for this application
  47. AppstateScope = "https://www.googleapis.com/auth/appstate"
  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.States = NewStatesService(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. States *StatesService
  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 NewStatesService(s *Service) *StatesService {
  70. rs := &StatesService{s: s}
  71. return rs
  72. }
  73. type StatesService struct {
  74. s *Service
  75. }
  76. // GetResponse: This is a JSON template for an app state resource.
  77. type GetResponse struct {
  78. // CurrentStateVersion: The current app state version.
  79. CurrentStateVersion string `json:"currentStateVersion,omitempty"`
  80. // Data: The requested data.
  81. Data string `json:"data,omitempty"`
  82. // Kind: Uniquely identifies the type of this resource. Value is always
  83. // the fixed string appstate#getResponse.
  84. Kind string `json:"kind,omitempty"`
  85. // StateKey: The key for the data.
  86. StateKey int64 `json:"stateKey,omitempty"`
  87. // ServerResponse contains the HTTP response code and headers from the
  88. // server.
  89. googleapi.ServerResponse `json:"-"`
  90. // ForceSendFields is a list of field names (e.g. "CurrentStateVersion")
  91. // to unconditionally include in API requests. By default, fields with
  92. // empty values are omitted from API requests. However, any non-pointer,
  93. // non-interface field appearing in ForceSendFields will be sent to the
  94. // server regardless of whether the field is empty or not. This may be
  95. // used to include empty fields in Patch requests.
  96. ForceSendFields []string `json:"-"`
  97. // NullFields is a list of field names (e.g. "CurrentStateVersion") to
  98. // include in API requests with the JSON null value. By default, fields
  99. // with empty values are omitted from API requests. However, any field
  100. // with an empty value appearing in NullFields will be sent to the
  101. // server as null. It is an error if a field in this list has a
  102. // non-empty value. This may be used to include null fields in Patch
  103. // requests.
  104. NullFields []string `json:"-"`
  105. }
  106. func (s *GetResponse) MarshalJSON() ([]byte, error) {
  107. type NoMethod GetResponse
  108. raw := NoMethod(*s)
  109. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  110. }
  111. // ListResponse: This is a JSON template to convert a list-response for
  112. // app state.
  113. type ListResponse struct {
  114. // Items: The app state data.
  115. Items []*GetResponse `json:"items,omitempty"`
  116. // Kind: Uniquely identifies the type of this resource. Value is always
  117. // the fixed string appstate#listResponse.
  118. Kind string `json:"kind,omitempty"`
  119. // MaximumKeyCount: The maximum number of keys allowed for this user.
  120. MaximumKeyCount int64 `json:"maximumKeyCount,omitempty"`
  121. // ServerResponse contains the HTTP response code and headers from the
  122. // server.
  123. googleapi.ServerResponse `json:"-"`
  124. // ForceSendFields is a list of field names (e.g. "Items") to
  125. // unconditionally include in API requests. By default, fields with
  126. // empty values are omitted from API requests. However, any non-pointer,
  127. // non-interface field appearing in ForceSendFields will be sent to the
  128. // server regardless of whether the field is empty or not. This may be
  129. // used to include empty fields in Patch requests.
  130. ForceSendFields []string `json:"-"`
  131. // NullFields is a list of field names (e.g. "Items") to include in API
  132. // requests with the JSON null value. By default, fields with empty
  133. // values are omitted from API requests. However, any field with an
  134. // empty value appearing in NullFields will be sent to the server as
  135. // null. It is an error if a field in this list has a non-empty value.
  136. // This may be used to include null fields in Patch requests.
  137. NullFields []string `json:"-"`
  138. }
  139. func (s *ListResponse) MarshalJSON() ([]byte, error) {
  140. type NoMethod ListResponse
  141. raw := NoMethod(*s)
  142. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  143. }
  144. // UpdateRequest: This is a JSON template for a requests which update
  145. // app state
  146. type UpdateRequest struct {
  147. // Data: The new app state data that your application is trying to
  148. // update with.
  149. Data string `json:"data,omitempty"`
  150. // Kind: Uniquely identifies the type of this resource. Value is always
  151. // the fixed string appstate#updateRequest.
  152. Kind string `json:"kind,omitempty"`
  153. // ForceSendFields is a list of field names (e.g. "Data") to
  154. // unconditionally include in API requests. By default, fields with
  155. // empty values are omitted from API requests. However, any non-pointer,
  156. // non-interface field appearing in ForceSendFields will be sent to the
  157. // server regardless of whether the field is empty or not. This may be
  158. // used to include empty fields in Patch requests.
  159. ForceSendFields []string `json:"-"`
  160. // NullFields is a list of field names (e.g. "Data") to include in API
  161. // requests with the JSON null value. By default, fields with empty
  162. // values are omitted from API requests. However, any field with an
  163. // empty value appearing in NullFields will be sent to the server as
  164. // null. It is an error if a field in this list has a non-empty value.
  165. // This may be used to include null fields in Patch requests.
  166. NullFields []string `json:"-"`
  167. }
  168. func (s *UpdateRequest) MarshalJSON() ([]byte, error) {
  169. type NoMethod UpdateRequest
  170. raw := NoMethod(*s)
  171. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  172. }
  173. // WriteResult: This is a JSON template for an app state write result.
  174. type WriteResult struct {
  175. // CurrentStateVersion: The version of the data for this key on the
  176. // server.
  177. CurrentStateVersion string `json:"currentStateVersion,omitempty"`
  178. // Kind: Uniquely identifies the type of this resource. Value is always
  179. // the fixed string appstate#writeResult.
  180. Kind string `json:"kind,omitempty"`
  181. // StateKey: The written key.
  182. StateKey int64 `json:"stateKey,omitempty"`
  183. // ServerResponse contains the HTTP response code and headers from the
  184. // server.
  185. googleapi.ServerResponse `json:"-"`
  186. // ForceSendFields is a list of field names (e.g. "CurrentStateVersion")
  187. // to unconditionally include in API requests. By default, fields with
  188. // empty values are omitted from API requests. However, any non-pointer,
  189. // non-interface field appearing in ForceSendFields will be sent to the
  190. // server regardless of whether the field is empty or not. This may be
  191. // used to include empty fields in Patch requests.
  192. ForceSendFields []string `json:"-"`
  193. // NullFields is a list of field names (e.g. "CurrentStateVersion") to
  194. // include in API requests with the JSON null value. By default, fields
  195. // with empty values are omitted from API requests. However, any field
  196. // with an empty value appearing in NullFields will be sent to the
  197. // server as null. It is an error if a field in this list has a
  198. // non-empty value. This may be used to include null fields in Patch
  199. // requests.
  200. NullFields []string `json:"-"`
  201. }
  202. func (s *WriteResult) MarshalJSON() ([]byte, error) {
  203. type NoMethod WriteResult
  204. raw := NoMethod(*s)
  205. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  206. }
  207. // method id "appstate.states.clear":
  208. type StatesClearCall struct {
  209. s *Service
  210. stateKey int64
  211. urlParams_ gensupport.URLParams
  212. ctx_ context.Context
  213. header_ http.Header
  214. }
  215. // Clear: Clears (sets to empty) the data for the passed key if and only
  216. // if the passed version matches the currently stored version. This
  217. // method results in a conflict error on version mismatch.
  218. func (r *StatesService) Clear(stateKey int64) *StatesClearCall {
  219. c := &StatesClearCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  220. c.stateKey = stateKey
  221. return c
  222. }
  223. // CurrentDataVersion sets the optional parameter "currentDataVersion":
  224. // The version of the data to be cleared. Version strings are returned
  225. // by the server.
  226. func (c *StatesClearCall) CurrentDataVersion(currentDataVersion string) *StatesClearCall {
  227. c.urlParams_.Set("currentDataVersion", currentDataVersion)
  228. return c
  229. }
  230. // Fields allows partial responses to be retrieved. See
  231. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  232. // for more information.
  233. func (c *StatesClearCall) Fields(s ...googleapi.Field) *StatesClearCall {
  234. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  235. return c
  236. }
  237. // Context sets the context to be used in this call's Do method. Any
  238. // pending HTTP request will be aborted if the provided context is
  239. // canceled.
  240. func (c *StatesClearCall) Context(ctx context.Context) *StatesClearCall {
  241. c.ctx_ = ctx
  242. return c
  243. }
  244. // Header returns an http.Header that can be modified by the caller to
  245. // add HTTP headers to the request.
  246. func (c *StatesClearCall) Header() http.Header {
  247. if c.header_ == nil {
  248. c.header_ = make(http.Header)
  249. }
  250. return c.header_
  251. }
  252. func (c *StatesClearCall) doRequest(alt string) (*http.Response, error) {
  253. reqHeaders := make(http.Header)
  254. for k, v := range c.header_ {
  255. reqHeaders[k] = v
  256. }
  257. reqHeaders.Set("User-Agent", c.s.userAgent())
  258. var body io.Reader = nil
  259. c.urlParams_.Set("alt", alt)
  260. urls := googleapi.ResolveRelative(c.s.BasePath, "states/{stateKey}/clear")
  261. urls += "?" + c.urlParams_.Encode()
  262. req, _ := http.NewRequest("POST", urls, body)
  263. req.Header = reqHeaders
  264. googleapi.Expand(req.URL, map[string]string{
  265. "stateKey": strconv.FormatInt(c.stateKey, 10),
  266. })
  267. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  268. }
  269. // Do executes the "appstate.states.clear" call.
  270. // Exactly one of *WriteResult or error will be non-nil. Any non-2xx
  271. // status code is an error. Response headers are in either
  272. // *WriteResult.ServerResponse.Header or (if a response was returned at
  273. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  274. // to check whether the returned error was because
  275. // http.StatusNotModified was returned.
  276. func (c *StatesClearCall) Do(opts ...googleapi.CallOption) (*WriteResult, error) {
  277. gensupport.SetOptions(c.urlParams_, opts...)
  278. res, err := c.doRequest("json")
  279. if res != nil && res.StatusCode == http.StatusNotModified {
  280. if res.Body != nil {
  281. res.Body.Close()
  282. }
  283. return nil, &googleapi.Error{
  284. Code: res.StatusCode,
  285. Header: res.Header,
  286. }
  287. }
  288. if err != nil {
  289. return nil, err
  290. }
  291. defer googleapi.CloseBody(res)
  292. if err := googleapi.CheckResponse(res); err != nil {
  293. return nil, err
  294. }
  295. ret := &WriteResult{
  296. ServerResponse: googleapi.ServerResponse{
  297. Header: res.Header,
  298. HTTPStatusCode: res.StatusCode,
  299. },
  300. }
  301. target := &ret
  302. if err := gensupport.DecodeResponse(target, res); err != nil {
  303. return nil, err
  304. }
  305. return ret, nil
  306. // {
  307. // "description": "Clears (sets to empty) the data for the passed key if and only if the passed version matches the currently stored version. This method results in a conflict error on version mismatch.",
  308. // "httpMethod": "POST",
  309. // "id": "appstate.states.clear",
  310. // "parameterOrder": [
  311. // "stateKey"
  312. // ],
  313. // "parameters": {
  314. // "currentDataVersion": {
  315. // "description": "The version of the data to be cleared. Version strings are returned by the server.",
  316. // "location": "query",
  317. // "type": "string"
  318. // },
  319. // "stateKey": {
  320. // "description": "The key for the data to be retrieved.",
  321. // "format": "int32",
  322. // "location": "path",
  323. // "maximum": "3",
  324. // "minimum": "0",
  325. // "required": true,
  326. // "type": "integer"
  327. // }
  328. // },
  329. // "path": "states/{stateKey}/clear",
  330. // "response": {
  331. // "$ref": "WriteResult"
  332. // },
  333. // "scopes": [
  334. // "https://www.googleapis.com/auth/appstate"
  335. // ]
  336. // }
  337. }
  338. // method id "appstate.states.delete":
  339. type StatesDeleteCall struct {
  340. s *Service
  341. stateKey int64
  342. urlParams_ gensupport.URLParams
  343. ctx_ context.Context
  344. header_ http.Header
  345. }
  346. // Delete: Deletes a key and the data associated with it. The key is
  347. // removed and no longer counts against the key quota. Note that since
  348. // this method is not safe in the face of concurrent modifications, it
  349. // should only be used for development and testing purposes. Invoking
  350. // this method in shipping code can result in data loss and data
  351. // corruption.
  352. func (r *StatesService) Delete(stateKey int64) *StatesDeleteCall {
  353. c := &StatesDeleteCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  354. c.stateKey = stateKey
  355. return c
  356. }
  357. // Fields allows partial responses to be retrieved. See
  358. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  359. // for more information.
  360. func (c *StatesDeleteCall) Fields(s ...googleapi.Field) *StatesDeleteCall {
  361. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  362. return c
  363. }
  364. // Context sets the context to be used in this call's Do method. Any
  365. // pending HTTP request will be aborted if the provided context is
  366. // canceled.
  367. func (c *StatesDeleteCall) Context(ctx context.Context) *StatesDeleteCall {
  368. c.ctx_ = ctx
  369. return c
  370. }
  371. // Header returns an http.Header that can be modified by the caller to
  372. // add HTTP headers to the request.
  373. func (c *StatesDeleteCall) Header() http.Header {
  374. if c.header_ == nil {
  375. c.header_ = make(http.Header)
  376. }
  377. return c.header_
  378. }
  379. func (c *StatesDeleteCall) doRequest(alt string) (*http.Response, error) {
  380. reqHeaders := make(http.Header)
  381. for k, v := range c.header_ {
  382. reqHeaders[k] = v
  383. }
  384. reqHeaders.Set("User-Agent", c.s.userAgent())
  385. var body io.Reader = nil
  386. c.urlParams_.Set("alt", alt)
  387. urls := googleapi.ResolveRelative(c.s.BasePath, "states/{stateKey}")
  388. urls += "?" + c.urlParams_.Encode()
  389. req, _ := http.NewRequest("DELETE", urls, body)
  390. req.Header = reqHeaders
  391. googleapi.Expand(req.URL, map[string]string{
  392. "stateKey": strconv.FormatInt(c.stateKey, 10),
  393. })
  394. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  395. }
  396. // Do executes the "appstate.states.delete" call.
  397. func (c *StatesDeleteCall) Do(opts ...googleapi.CallOption) error {
  398. gensupport.SetOptions(c.urlParams_, opts...)
  399. res, err := c.doRequest("json")
  400. if err != nil {
  401. return err
  402. }
  403. defer googleapi.CloseBody(res)
  404. if err := googleapi.CheckResponse(res); err != nil {
  405. return err
  406. }
  407. return nil
  408. // {
  409. // "description": "Deletes a key and the data associated with it. The key is removed and no longer counts against the key quota. Note that since this method is not safe in the face of concurrent modifications, it should only be used for development and testing purposes. Invoking this method in shipping code can result in data loss and data corruption.",
  410. // "httpMethod": "DELETE",
  411. // "id": "appstate.states.delete",
  412. // "parameterOrder": [
  413. // "stateKey"
  414. // ],
  415. // "parameters": {
  416. // "stateKey": {
  417. // "description": "The key for the data to be retrieved.",
  418. // "format": "int32",
  419. // "location": "path",
  420. // "maximum": "3",
  421. // "minimum": "0",
  422. // "required": true,
  423. // "type": "integer"
  424. // }
  425. // },
  426. // "path": "states/{stateKey}",
  427. // "scopes": [
  428. // "https://www.googleapis.com/auth/appstate"
  429. // ]
  430. // }
  431. }
  432. // method id "appstate.states.get":
  433. type StatesGetCall struct {
  434. s *Service
  435. stateKey int64
  436. urlParams_ gensupport.URLParams
  437. ifNoneMatch_ string
  438. ctx_ context.Context
  439. header_ http.Header
  440. }
  441. // Get: Retrieves the data corresponding to the passed key. If the key
  442. // does not exist on the server, an HTTP 404 will be returned.
  443. func (r *StatesService) Get(stateKey int64) *StatesGetCall {
  444. c := &StatesGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  445. c.stateKey = stateKey
  446. return c
  447. }
  448. // Fields allows partial responses to be retrieved. See
  449. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  450. // for more information.
  451. func (c *StatesGetCall) Fields(s ...googleapi.Field) *StatesGetCall {
  452. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  453. return c
  454. }
  455. // IfNoneMatch sets the optional parameter which makes the operation
  456. // fail if the object's ETag matches the given value. This is useful for
  457. // getting updates only after the object has changed since the last
  458. // request. Use googleapi.IsNotModified to check whether the response
  459. // error from Do is the result of In-None-Match.
  460. func (c *StatesGetCall) IfNoneMatch(entityTag string) *StatesGetCall {
  461. c.ifNoneMatch_ = entityTag
  462. return c
  463. }
  464. // Context sets the context to be used in this call's Do method. Any
  465. // pending HTTP request will be aborted if the provided context is
  466. // canceled.
  467. func (c *StatesGetCall) Context(ctx context.Context) *StatesGetCall {
  468. c.ctx_ = ctx
  469. return c
  470. }
  471. // Header returns an http.Header that can be modified by the caller to
  472. // add HTTP headers to the request.
  473. func (c *StatesGetCall) Header() http.Header {
  474. if c.header_ == nil {
  475. c.header_ = make(http.Header)
  476. }
  477. return c.header_
  478. }
  479. func (c *StatesGetCall) doRequest(alt string) (*http.Response, error) {
  480. reqHeaders := make(http.Header)
  481. for k, v := range c.header_ {
  482. reqHeaders[k] = v
  483. }
  484. reqHeaders.Set("User-Agent", c.s.userAgent())
  485. if c.ifNoneMatch_ != "" {
  486. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  487. }
  488. var body io.Reader = nil
  489. c.urlParams_.Set("alt", alt)
  490. urls := googleapi.ResolveRelative(c.s.BasePath, "states/{stateKey}")
  491. urls += "?" + c.urlParams_.Encode()
  492. req, _ := http.NewRequest("GET", urls, body)
  493. req.Header = reqHeaders
  494. googleapi.Expand(req.URL, map[string]string{
  495. "stateKey": strconv.FormatInt(c.stateKey, 10),
  496. })
  497. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  498. }
  499. // Do executes the "appstate.states.get" call.
  500. // Exactly one of *GetResponse or error will be non-nil. Any non-2xx
  501. // status code is an error. Response headers are in either
  502. // *GetResponse.ServerResponse.Header or (if a response was returned at
  503. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  504. // to check whether the returned error was because
  505. // http.StatusNotModified was returned.
  506. func (c *StatesGetCall) Do(opts ...googleapi.CallOption) (*GetResponse, error) {
  507. gensupport.SetOptions(c.urlParams_, opts...)
  508. res, err := c.doRequest("json")
  509. if res != nil && res.StatusCode == http.StatusNotModified {
  510. if res.Body != nil {
  511. res.Body.Close()
  512. }
  513. return nil, &googleapi.Error{
  514. Code: res.StatusCode,
  515. Header: res.Header,
  516. }
  517. }
  518. if err != nil {
  519. return nil, err
  520. }
  521. defer googleapi.CloseBody(res)
  522. if err := googleapi.CheckResponse(res); err != nil {
  523. return nil, err
  524. }
  525. ret := &GetResponse{
  526. ServerResponse: googleapi.ServerResponse{
  527. Header: res.Header,
  528. HTTPStatusCode: res.StatusCode,
  529. },
  530. }
  531. target := &ret
  532. if err := gensupport.DecodeResponse(target, res); err != nil {
  533. return nil, err
  534. }
  535. return ret, nil
  536. // {
  537. // "description": "Retrieves the data corresponding to the passed key. If the key does not exist on the server, an HTTP 404 will be returned.",
  538. // "httpMethod": "GET",
  539. // "id": "appstate.states.get",
  540. // "parameterOrder": [
  541. // "stateKey"
  542. // ],
  543. // "parameters": {
  544. // "stateKey": {
  545. // "description": "The key for the data to be retrieved.",
  546. // "format": "int32",
  547. // "location": "path",
  548. // "maximum": "3",
  549. // "minimum": "0",
  550. // "required": true,
  551. // "type": "integer"
  552. // }
  553. // },
  554. // "path": "states/{stateKey}",
  555. // "response": {
  556. // "$ref": "GetResponse"
  557. // },
  558. // "scopes": [
  559. // "https://www.googleapis.com/auth/appstate"
  560. // ]
  561. // }
  562. }
  563. // method id "appstate.states.list":
  564. type StatesListCall struct {
  565. s *Service
  566. urlParams_ gensupport.URLParams
  567. ifNoneMatch_ string
  568. ctx_ context.Context
  569. header_ http.Header
  570. }
  571. // List: Lists all the states keys, and optionally the state data.
  572. func (r *StatesService) List() *StatesListCall {
  573. c := &StatesListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  574. return c
  575. }
  576. // IncludeData sets the optional parameter "includeData": Whether to
  577. // include the full data in addition to the version number
  578. func (c *StatesListCall) IncludeData(includeData bool) *StatesListCall {
  579. c.urlParams_.Set("includeData", fmt.Sprint(includeData))
  580. return c
  581. }
  582. // Fields allows partial responses to be retrieved. See
  583. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  584. // for more information.
  585. func (c *StatesListCall) Fields(s ...googleapi.Field) *StatesListCall {
  586. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  587. return c
  588. }
  589. // IfNoneMatch sets the optional parameter which makes the operation
  590. // fail if the object's ETag matches the given value. This is useful for
  591. // getting updates only after the object has changed since the last
  592. // request. Use googleapi.IsNotModified to check whether the response
  593. // error from Do is the result of In-None-Match.
  594. func (c *StatesListCall) IfNoneMatch(entityTag string) *StatesListCall {
  595. c.ifNoneMatch_ = entityTag
  596. return c
  597. }
  598. // Context sets the context to be used in this call's Do method. Any
  599. // pending HTTP request will be aborted if the provided context is
  600. // canceled.
  601. func (c *StatesListCall) Context(ctx context.Context) *StatesListCall {
  602. c.ctx_ = ctx
  603. return c
  604. }
  605. // Header returns an http.Header that can be modified by the caller to
  606. // add HTTP headers to the request.
  607. func (c *StatesListCall) Header() http.Header {
  608. if c.header_ == nil {
  609. c.header_ = make(http.Header)
  610. }
  611. return c.header_
  612. }
  613. func (c *StatesListCall) doRequest(alt string) (*http.Response, error) {
  614. reqHeaders := make(http.Header)
  615. for k, v := range c.header_ {
  616. reqHeaders[k] = v
  617. }
  618. reqHeaders.Set("User-Agent", c.s.userAgent())
  619. if c.ifNoneMatch_ != "" {
  620. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  621. }
  622. var body io.Reader = nil
  623. c.urlParams_.Set("alt", alt)
  624. urls := googleapi.ResolveRelative(c.s.BasePath, "states")
  625. urls += "?" + c.urlParams_.Encode()
  626. req, _ := http.NewRequest("GET", urls, body)
  627. req.Header = reqHeaders
  628. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  629. }
  630. // Do executes the "appstate.states.list" call.
  631. // Exactly one of *ListResponse or error will be non-nil. Any non-2xx
  632. // status code is an error. Response headers are in either
  633. // *ListResponse.ServerResponse.Header or (if a response was returned at
  634. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  635. // to check whether the returned error was because
  636. // http.StatusNotModified was returned.
  637. func (c *StatesListCall) Do(opts ...googleapi.CallOption) (*ListResponse, error) {
  638. gensupport.SetOptions(c.urlParams_, opts...)
  639. res, err := c.doRequest("json")
  640. if res != nil && res.StatusCode == http.StatusNotModified {
  641. if res.Body != nil {
  642. res.Body.Close()
  643. }
  644. return nil, &googleapi.Error{
  645. Code: res.StatusCode,
  646. Header: res.Header,
  647. }
  648. }
  649. if err != nil {
  650. return nil, err
  651. }
  652. defer googleapi.CloseBody(res)
  653. if err := googleapi.CheckResponse(res); err != nil {
  654. return nil, err
  655. }
  656. ret := &ListResponse{
  657. ServerResponse: googleapi.ServerResponse{
  658. Header: res.Header,
  659. HTTPStatusCode: res.StatusCode,
  660. },
  661. }
  662. target := &ret
  663. if err := gensupport.DecodeResponse(target, res); err != nil {
  664. return nil, err
  665. }
  666. return ret, nil
  667. // {
  668. // "description": "Lists all the states keys, and optionally the state data.",
  669. // "httpMethod": "GET",
  670. // "id": "appstate.states.list",
  671. // "parameters": {
  672. // "includeData": {
  673. // "default": "false",
  674. // "description": "Whether to include the full data in addition to the version number",
  675. // "location": "query",
  676. // "type": "boolean"
  677. // }
  678. // },
  679. // "path": "states",
  680. // "response": {
  681. // "$ref": "ListResponse"
  682. // },
  683. // "scopes": [
  684. // "https://www.googleapis.com/auth/appstate"
  685. // ]
  686. // }
  687. }
  688. // method id "appstate.states.update":
  689. type StatesUpdateCall struct {
  690. s *Service
  691. stateKey int64
  692. updaterequest *UpdateRequest
  693. urlParams_ gensupport.URLParams
  694. ctx_ context.Context
  695. header_ http.Header
  696. }
  697. // Update: Update the data associated with the input key if and only if
  698. // the passed version matches the currently stored version. This method
  699. // is safe in the face of concurrent writes. Maximum per-key size is
  700. // 128KB.
  701. func (r *StatesService) Update(stateKey int64, updaterequest *UpdateRequest) *StatesUpdateCall {
  702. c := &StatesUpdateCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  703. c.stateKey = stateKey
  704. c.updaterequest = updaterequest
  705. return c
  706. }
  707. // CurrentStateVersion sets the optional parameter
  708. // "currentStateVersion": The version of the app state your application
  709. // is attempting to update. If this does not match the current version,
  710. // this method will return a conflict error. If there is no data stored
  711. // on the server for this key, the update will succeed irrespective of
  712. // the value of this parameter.
  713. func (c *StatesUpdateCall) CurrentStateVersion(currentStateVersion string) *StatesUpdateCall {
  714. c.urlParams_.Set("currentStateVersion", currentStateVersion)
  715. return c
  716. }
  717. // Fields allows partial responses to be retrieved. See
  718. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  719. // for more information.
  720. func (c *StatesUpdateCall) Fields(s ...googleapi.Field) *StatesUpdateCall {
  721. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  722. return c
  723. }
  724. // Context sets the context to be used in this call's Do method. Any
  725. // pending HTTP request will be aborted if the provided context is
  726. // canceled.
  727. func (c *StatesUpdateCall) Context(ctx context.Context) *StatesUpdateCall {
  728. c.ctx_ = ctx
  729. return c
  730. }
  731. // Header returns an http.Header that can be modified by the caller to
  732. // add HTTP headers to the request.
  733. func (c *StatesUpdateCall) Header() http.Header {
  734. if c.header_ == nil {
  735. c.header_ = make(http.Header)
  736. }
  737. return c.header_
  738. }
  739. func (c *StatesUpdateCall) doRequest(alt string) (*http.Response, error) {
  740. reqHeaders := make(http.Header)
  741. for k, v := range c.header_ {
  742. reqHeaders[k] = v
  743. }
  744. reqHeaders.Set("User-Agent", c.s.userAgent())
  745. var body io.Reader = nil
  746. body, err := googleapi.WithoutDataWrapper.JSONReader(c.updaterequest)
  747. if err != nil {
  748. return nil, err
  749. }
  750. reqHeaders.Set("Content-Type", "application/json")
  751. c.urlParams_.Set("alt", alt)
  752. urls := googleapi.ResolveRelative(c.s.BasePath, "states/{stateKey}")
  753. urls += "?" + c.urlParams_.Encode()
  754. req, _ := http.NewRequest("PUT", urls, body)
  755. req.Header = reqHeaders
  756. googleapi.Expand(req.URL, map[string]string{
  757. "stateKey": strconv.FormatInt(c.stateKey, 10),
  758. })
  759. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  760. }
  761. // Do executes the "appstate.states.update" call.
  762. // Exactly one of *WriteResult or error will be non-nil. Any non-2xx
  763. // status code is an error. Response headers are in either
  764. // *WriteResult.ServerResponse.Header or (if a response was returned at
  765. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  766. // to check whether the returned error was because
  767. // http.StatusNotModified was returned.
  768. func (c *StatesUpdateCall) Do(opts ...googleapi.CallOption) (*WriteResult, error) {
  769. gensupport.SetOptions(c.urlParams_, opts...)
  770. res, err := c.doRequest("json")
  771. if res != nil && res.StatusCode == http.StatusNotModified {
  772. if res.Body != nil {
  773. res.Body.Close()
  774. }
  775. return nil, &googleapi.Error{
  776. Code: res.StatusCode,
  777. Header: res.Header,
  778. }
  779. }
  780. if err != nil {
  781. return nil, err
  782. }
  783. defer googleapi.CloseBody(res)
  784. if err := googleapi.CheckResponse(res); err != nil {
  785. return nil, err
  786. }
  787. ret := &WriteResult{
  788. ServerResponse: googleapi.ServerResponse{
  789. Header: res.Header,
  790. HTTPStatusCode: res.StatusCode,
  791. },
  792. }
  793. target := &ret
  794. if err := gensupport.DecodeResponse(target, res); err != nil {
  795. return nil, err
  796. }
  797. return ret, nil
  798. // {
  799. // "description": "Update the data associated with the input key if and only if the passed version matches the currently stored version. This method is safe in the face of concurrent writes. Maximum per-key size is 128KB.",
  800. // "httpMethod": "PUT",
  801. // "id": "appstate.states.update",
  802. // "parameterOrder": [
  803. // "stateKey"
  804. // ],
  805. // "parameters": {
  806. // "currentStateVersion": {
  807. // "description": "The version of the app state your application is attempting to update. If this does not match the current version, this method will return a conflict error. If there is no data stored on the server for this key, the update will succeed irrespective of the value of this parameter.",
  808. // "location": "query",
  809. // "type": "string"
  810. // },
  811. // "stateKey": {
  812. // "description": "The key for the data to be retrieved.",
  813. // "format": "int32",
  814. // "location": "path",
  815. // "maximum": "3",
  816. // "minimum": "0",
  817. // "required": true,
  818. // "type": "integer"
  819. // }
  820. // },
  821. // "path": "states/{stateKey}",
  822. // "request": {
  823. // "$ref": "UpdateRequest"
  824. // },
  825. // "response": {
  826. // "$ref": "WriteResult"
  827. // },
  828. // "scopes": [
  829. // "https://www.googleapis.com/auth/appstate"
  830. // ]
  831. // }
  832. }