prediction-gen.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  1. // Package prediction provides access to the Prediction API.
  2. //
  3. // See https://developers.google.com/prediction/docs/developer-guide
  4. //
  5. // Usage example:
  6. //
  7. // import "google.golang.org/api/prediction/v1.2"
  8. // ...
  9. // predictionService, err := prediction.New(oauthHttpClient)
  10. package prediction // import "google.golang.org/api/prediction/v1.2"
  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 = "prediction:v1.2"
  41. const apiName = "prediction"
  42. const apiVersion = "v1.2"
  43. const basePath = "https://www.googleapis.com/prediction/v1.2/"
  44. // OAuth2 scopes used by this API.
  45. const (
  46. // Manage your data and permissions in Google Cloud Storage
  47. DevstorageFullControlScope = "https://www.googleapis.com/auth/devstorage.full_control"
  48. // View your data in Google Cloud Storage
  49. DevstorageReadOnlyScope = "https://www.googleapis.com/auth/devstorage.read_only"
  50. // Manage your data in Google Cloud Storage
  51. DevstorageReadWriteScope = "https://www.googleapis.com/auth/devstorage.read_write"
  52. // Manage your data in the Google Prediction API
  53. PredictionScope = "https://www.googleapis.com/auth/prediction"
  54. )
  55. func New(client *http.Client) (*Service, error) {
  56. if client == nil {
  57. return nil, errors.New("client is nil")
  58. }
  59. s := &Service{client: client, BasePath: basePath}
  60. s.Hostedmodels = NewHostedmodelsService(s)
  61. s.Training = NewTrainingService(s)
  62. return s, nil
  63. }
  64. type Service struct {
  65. client *http.Client
  66. BasePath string // API endpoint base URL
  67. UserAgent string // optional additional User-Agent fragment
  68. Hostedmodels *HostedmodelsService
  69. Training *TrainingService
  70. }
  71. func (s *Service) userAgent() string {
  72. if s.UserAgent == "" {
  73. return googleapi.UserAgent
  74. }
  75. return googleapi.UserAgent + " " + s.UserAgent
  76. }
  77. func NewHostedmodelsService(s *Service) *HostedmodelsService {
  78. rs := &HostedmodelsService{s: s}
  79. return rs
  80. }
  81. type HostedmodelsService struct {
  82. s *Service
  83. }
  84. func NewTrainingService(s *Service) *TrainingService {
  85. rs := &TrainingService{s: s}
  86. return rs
  87. }
  88. type TrainingService struct {
  89. s *Service
  90. }
  91. type Input struct {
  92. Input *InputInput `json:"input,omitempty"`
  93. // ForceSendFields is a list of field names (e.g. "Input") to
  94. // unconditionally include in API requests. By default, fields with
  95. // empty values are omitted from API requests. However, any non-pointer,
  96. // non-interface field appearing in ForceSendFields will be sent to the
  97. // server regardless of whether the field is empty or not. This may be
  98. // used to include empty fields in Patch requests.
  99. ForceSendFields []string `json:"-"`
  100. }
  101. func (s *Input) MarshalJSON() ([]byte, error) {
  102. type noMethod Input
  103. raw := noMethod(*s)
  104. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  105. }
  106. type InputInput struct {
  107. CsvInstance []interface{} `json:"csvInstance,omitempty"`
  108. // ForceSendFields is a list of field names (e.g. "CsvInstance") to
  109. // unconditionally include in API requests. By default, fields with
  110. // empty values are omitted from API requests. However, any non-pointer,
  111. // non-interface field appearing in ForceSendFields will be sent to the
  112. // server regardless of whether the field is empty or not. This may be
  113. // used to include empty fields in Patch requests.
  114. ForceSendFields []string `json:"-"`
  115. }
  116. func (s *InputInput) MarshalJSON() ([]byte, error) {
  117. type noMethod InputInput
  118. raw := noMethod(*s)
  119. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  120. }
  121. type Output struct {
  122. Id string `json:"id,omitempty"`
  123. Kind string `json:"kind,omitempty"`
  124. OutputLabel string `json:"outputLabel,omitempty"`
  125. OutputMulti []*OutputOutputMulti `json:"outputMulti,omitempty"`
  126. OutputValue float64 `json:"outputValue,omitempty"`
  127. SelfLink string `json:"selfLink,omitempty"`
  128. // ServerResponse contains the HTTP response code and headers from the
  129. // server.
  130. googleapi.ServerResponse `json:"-"`
  131. // ForceSendFields is a list of field names (e.g. "Id") to
  132. // unconditionally include in API requests. By default, fields with
  133. // empty values are omitted from API requests. However, any non-pointer,
  134. // non-interface field appearing in ForceSendFields will be sent to the
  135. // server regardless of whether the field is empty or not. This may be
  136. // used to include empty fields in Patch requests.
  137. ForceSendFields []string `json:"-"`
  138. }
  139. func (s *Output) MarshalJSON() ([]byte, error) {
  140. type noMethod Output
  141. raw := noMethod(*s)
  142. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  143. }
  144. type OutputOutputMulti struct {
  145. Label string `json:"label,omitempty"`
  146. Score float64 `json:"score,omitempty"`
  147. // ForceSendFields is a list of field names (e.g. "Label") to
  148. // unconditionally include in API requests. By default, fields with
  149. // empty values are omitted from API requests. However, any non-pointer,
  150. // non-interface field appearing in ForceSendFields will be sent to the
  151. // server regardless of whether the field is empty or not. This may be
  152. // used to include empty fields in Patch requests.
  153. ForceSendFields []string `json:"-"`
  154. }
  155. func (s *OutputOutputMulti) MarshalJSON() ([]byte, error) {
  156. type noMethod OutputOutputMulti
  157. raw := noMethod(*s)
  158. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  159. }
  160. type Training struct {
  161. Id string `json:"id,omitempty"`
  162. Kind string `json:"kind,omitempty"`
  163. ModelInfo *TrainingModelInfo `json:"modelInfo,omitempty"`
  164. SelfLink string `json:"selfLink,omitempty"`
  165. TrainingStatus string `json:"trainingStatus,omitempty"`
  166. // ServerResponse contains the HTTP response code and headers from the
  167. // server.
  168. googleapi.ServerResponse `json:"-"`
  169. // ForceSendFields is a list of field names (e.g. "Id") to
  170. // unconditionally include in API requests. By default, fields with
  171. // empty values are omitted from API requests. However, any non-pointer,
  172. // non-interface field appearing in ForceSendFields will be sent to the
  173. // server regardless of whether the field is empty or not. This may be
  174. // used to include empty fields in Patch requests.
  175. ForceSendFields []string `json:"-"`
  176. }
  177. func (s *Training) MarshalJSON() ([]byte, error) {
  178. type noMethod Training
  179. raw := noMethod(*s)
  180. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  181. }
  182. type TrainingModelInfo struct {
  183. ClassificationAccuracy float64 `json:"classificationAccuracy,omitempty"`
  184. MeanSquaredError float64 `json:"meanSquaredError,omitempty"`
  185. ModelType string `json:"modelType,omitempty"`
  186. // ForceSendFields is a list of field names (e.g.
  187. // "ClassificationAccuracy") to unconditionally include in API requests.
  188. // By default, fields with empty values are omitted from API requests.
  189. // However, any non-pointer, non-interface field appearing in
  190. // ForceSendFields will be sent to the server regardless of whether the
  191. // field is empty or not. This may be used to include empty fields in
  192. // Patch requests.
  193. ForceSendFields []string `json:"-"`
  194. }
  195. func (s *TrainingModelInfo) MarshalJSON() ([]byte, error) {
  196. type noMethod TrainingModelInfo
  197. raw := noMethod(*s)
  198. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  199. }
  200. type Update struct {
  201. // ClassLabel: The true class label of this instance
  202. ClassLabel string `json:"classLabel,omitempty"`
  203. // CsvInstance: The input features for this instance
  204. CsvInstance []interface{} `json:"csvInstance,omitempty"`
  205. // ForceSendFields is a list of field names (e.g. "ClassLabel") to
  206. // unconditionally include in API requests. By default, fields with
  207. // empty values are omitted from API requests. However, any non-pointer,
  208. // non-interface field appearing in ForceSendFields will be sent to the
  209. // server regardless of whether the field is empty or not. This may be
  210. // used to include empty fields in Patch requests.
  211. ForceSendFields []string `json:"-"`
  212. }
  213. func (s *Update) MarshalJSON() ([]byte, error) {
  214. type noMethod Update
  215. raw := noMethod(*s)
  216. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  217. }
  218. // method id "prediction.predict":
  219. type PredictCall struct {
  220. s *Service
  221. data string
  222. input *Input
  223. urlParams_ gensupport.URLParams
  224. ctx_ context.Context
  225. }
  226. // Predict: Submit data and request a prediction
  227. func (s *Service) Predict(data string, input *Input) *PredictCall {
  228. c := &PredictCall{s: s, urlParams_: make(gensupport.URLParams)}
  229. c.data = data
  230. c.input = input
  231. return c
  232. }
  233. // Fields allows partial responses to be retrieved. See
  234. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  235. // for more information.
  236. func (c *PredictCall) Fields(s ...googleapi.Field) *PredictCall {
  237. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  238. return c
  239. }
  240. // Context sets the context to be used in this call's Do method. Any
  241. // pending HTTP request will be aborted if the provided context is
  242. // canceled.
  243. func (c *PredictCall) Context(ctx context.Context) *PredictCall {
  244. c.ctx_ = ctx
  245. return c
  246. }
  247. func (c *PredictCall) doRequest(alt string) (*http.Response, error) {
  248. var body io.Reader = nil
  249. body, err := googleapi.WithoutDataWrapper.JSONReader(c.input)
  250. if err != nil {
  251. return nil, err
  252. }
  253. ctype := "application/json"
  254. c.urlParams_.Set("alt", alt)
  255. urls := googleapi.ResolveRelative(c.s.BasePath, "training/{data}/predict")
  256. urls += "?" + c.urlParams_.Encode()
  257. req, _ := http.NewRequest("POST", urls, body)
  258. googleapi.Expand(req.URL, map[string]string{
  259. "data": c.data,
  260. })
  261. req.Header.Set("Content-Type", ctype)
  262. req.Header.Set("User-Agent", c.s.userAgent())
  263. if c.ctx_ != nil {
  264. return ctxhttp.Do(c.ctx_, c.s.client, req)
  265. }
  266. return c.s.client.Do(req)
  267. }
  268. // Do executes the "prediction.predict" call.
  269. // Exactly one of *Output or error will be non-nil. Any non-2xx status
  270. // code is an error. Response headers are in either
  271. // *Output.ServerResponse.Header or (if a response was returned at all)
  272. // in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to
  273. // check whether the returned error was because http.StatusNotModified
  274. // was returned.
  275. func (c *PredictCall) Do(opts ...googleapi.CallOption) (*Output, error) {
  276. gensupport.SetOptions(c.urlParams_, opts...)
  277. res, err := c.doRequest("json")
  278. if res != nil && res.StatusCode == http.StatusNotModified {
  279. if res.Body != nil {
  280. res.Body.Close()
  281. }
  282. return nil, &googleapi.Error{
  283. Code: res.StatusCode,
  284. Header: res.Header,
  285. }
  286. }
  287. if err != nil {
  288. return nil, err
  289. }
  290. defer googleapi.CloseBody(res)
  291. if err := googleapi.CheckResponse(res); err != nil {
  292. return nil, err
  293. }
  294. ret := &Output{
  295. ServerResponse: googleapi.ServerResponse{
  296. Header: res.Header,
  297. HTTPStatusCode: res.StatusCode,
  298. },
  299. }
  300. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  301. return nil, err
  302. }
  303. return ret, nil
  304. // {
  305. // "description": "Submit data and request a prediction",
  306. // "httpMethod": "POST",
  307. // "id": "prediction.predict",
  308. // "parameterOrder": [
  309. // "data"
  310. // ],
  311. // "parameters": {
  312. // "data": {
  313. // "description": "mybucket%2Fmydata resource in Google Storage",
  314. // "location": "path",
  315. // "required": true,
  316. // "type": "string"
  317. // }
  318. // },
  319. // "path": "training/{data}/predict",
  320. // "request": {
  321. // "$ref": "Input"
  322. // },
  323. // "response": {
  324. // "$ref": "Output"
  325. // },
  326. // "scopes": [
  327. // "https://www.googleapis.com/auth/prediction"
  328. // ]
  329. // }
  330. }
  331. // method id "prediction.hostedmodels.predict":
  332. type HostedmodelsPredictCall struct {
  333. s *Service
  334. hostedModelName string
  335. input *Input
  336. urlParams_ gensupport.URLParams
  337. ctx_ context.Context
  338. }
  339. // Predict: Submit input and request an output against a hosted model
  340. func (r *HostedmodelsService) Predict(hostedModelName string, input *Input) *HostedmodelsPredictCall {
  341. c := &HostedmodelsPredictCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  342. c.hostedModelName = hostedModelName
  343. c.input = input
  344. return c
  345. }
  346. // Fields allows partial responses to be retrieved. See
  347. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  348. // for more information.
  349. func (c *HostedmodelsPredictCall) Fields(s ...googleapi.Field) *HostedmodelsPredictCall {
  350. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  351. return c
  352. }
  353. // Context sets the context to be used in this call's Do method. Any
  354. // pending HTTP request will be aborted if the provided context is
  355. // canceled.
  356. func (c *HostedmodelsPredictCall) Context(ctx context.Context) *HostedmodelsPredictCall {
  357. c.ctx_ = ctx
  358. return c
  359. }
  360. func (c *HostedmodelsPredictCall) doRequest(alt string) (*http.Response, error) {
  361. var body io.Reader = nil
  362. body, err := googleapi.WithoutDataWrapper.JSONReader(c.input)
  363. if err != nil {
  364. return nil, err
  365. }
  366. ctype := "application/json"
  367. c.urlParams_.Set("alt", alt)
  368. urls := googleapi.ResolveRelative(c.s.BasePath, "hostedmodels/{hostedModelName}/predict")
  369. urls += "?" + c.urlParams_.Encode()
  370. req, _ := http.NewRequest("POST", urls, body)
  371. googleapi.Expand(req.URL, map[string]string{
  372. "hostedModelName": c.hostedModelName,
  373. })
  374. req.Header.Set("Content-Type", ctype)
  375. req.Header.Set("User-Agent", c.s.userAgent())
  376. if c.ctx_ != nil {
  377. return ctxhttp.Do(c.ctx_, c.s.client, req)
  378. }
  379. return c.s.client.Do(req)
  380. }
  381. // Do executes the "prediction.hostedmodels.predict" call.
  382. // Exactly one of *Output or error will be non-nil. Any non-2xx status
  383. // code is an error. Response headers are in either
  384. // *Output.ServerResponse.Header or (if a response was returned at all)
  385. // in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to
  386. // check whether the returned error was because http.StatusNotModified
  387. // was returned.
  388. func (c *HostedmodelsPredictCall) Do(opts ...googleapi.CallOption) (*Output, error) {
  389. gensupport.SetOptions(c.urlParams_, opts...)
  390. res, err := c.doRequest("json")
  391. if res != nil && res.StatusCode == http.StatusNotModified {
  392. if res.Body != nil {
  393. res.Body.Close()
  394. }
  395. return nil, &googleapi.Error{
  396. Code: res.StatusCode,
  397. Header: res.Header,
  398. }
  399. }
  400. if err != nil {
  401. return nil, err
  402. }
  403. defer googleapi.CloseBody(res)
  404. if err := googleapi.CheckResponse(res); err != nil {
  405. return nil, err
  406. }
  407. ret := &Output{
  408. ServerResponse: googleapi.ServerResponse{
  409. Header: res.Header,
  410. HTTPStatusCode: res.StatusCode,
  411. },
  412. }
  413. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  414. return nil, err
  415. }
  416. return ret, nil
  417. // {
  418. // "description": "Submit input and request an output against a hosted model",
  419. // "httpMethod": "POST",
  420. // "id": "prediction.hostedmodels.predict",
  421. // "parameterOrder": [
  422. // "hostedModelName"
  423. // ],
  424. // "parameters": {
  425. // "hostedModelName": {
  426. // "description": "The name of a hosted model",
  427. // "location": "path",
  428. // "required": true,
  429. // "type": "string"
  430. // }
  431. // },
  432. // "path": "hostedmodels/{hostedModelName}/predict",
  433. // "request": {
  434. // "$ref": "Input"
  435. // },
  436. // "response": {
  437. // "$ref": "Output"
  438. // },
  439. // "scopes": [
  440. // "https://www.googleapis.com/auth/prediction"
  441. // ]
  442. // }
  443. }
  444. // method id "prediction.training.delete":
  445. type TrainingDeleteCall struct {
  446. s *Service
  447. data string
  448. urlParams_ gensupport.URLParams
  449. ctx_ context.Context
  450. }
  451. // Delete: Delete a trained model
  452. func (r *TrainingService) Delete(data string) *TrainingDeleteCall {
  453. c := &TrainingDeleteCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  454. c.data = data
  455. return c
  456. }
  457. // Fields allows partial responses to be retrieved. See
  458. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  459. // for more information.
  460. func (c *TrainingDeleteCall) Fields(s ...googleapi.Field) *TrainingDeleteCall {
  461. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  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 *TrainingDeleteCall) Context(ctx context.Context) *TrainingDeleteCall {
  468. c.ctx_ = ctx
  469. return c
  470. }
  471. func (c *TrainingDeleteCall) doRequest(alt string) (*http.Response, error) {
  472. var body io.Reader = nil
  473. c.urlParams_.Set("alt", alt)
  474. urls := googleapi.ResolveRelative(c.s.BasePath, "training/{data}")
  475. urls += "?" + c.urlParams_.Encode()
  476. req, _ := http.NewRequest("DELETE", urls, body)
  477. googleapi.Expand(req.URL, map[string]string{
  478. "data": c.data,
  479. })
  480. req.Header.Set("User-Agent", c.s.userAgent())
  481. if c.ctx_ != nil {
  482. return ctxhttp.Do(c.ctx_, c.s.client, req)
  483. }
  484. return c.s.client.Do(req)
  485. }
  486. // Do executes the "prediction.training.delete" call.
  487. func (c *TrainingDeleteCall) Do(opts ...googleapi.CallOption) error {
  488. gensupport.SetOptions(c.urlParams_, opts...)
  489. res, err := c.doRequest("json")
  490. if err != nil {
  491. return err
  492. }
  493. defer googleapi.CloseBody(res)
  494. if err := googleapi.CheckResponse(res); err != nil {
  495. return err
  496. }
  497. return nil
  498. // {
  499. // "description": "Delete a trained model",
  500. // "httpMethod": "DELETE",
  501. // "id": "prediction.training.delete",
  502. // "parameterOrder": [
  503. // "data"
  504. // ],
  505. // "parameters": {
  506. // "data": {
  507. // "description": "mybucket/mydata resource in Google Storage",
  508. // "location": "path",
  509. // "required": true,
  510. // "type": "string"
  511. // }
  512. // },
  513. // "path": "training/{data}",
  514. // "scopes": [
  515. // "https://www.googleapis.com/auth/prediction"
  516. // ]
  517. // }
  518. }
  519. // method id "prediction.training.get":
  520. type TrainingGetCall struct {
  521. s *Service
  522. data string
  523. urlParams_ gensupport.URLParams
  524. ifNoneMatch_ string
  525. ctx_ context.Context
  526. }
  527. // Get: Check training status of your model
  528. func (r *TrainingService) Get(data string) *TrainingGetCall {
  529. c := &TrainingGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  530. c.data = data
  531. return c
  532. }
  533. // Fields allows partial responses to be retrieved. See
  534. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  535. // for more information.
  536. func (c *TrainingGetCall) Fields(s ...googleapi.Field) *TrainingGetCall {
  537. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  538. return c
  539. }
  540. // IfNoneMatch sets the optional parameter which makes the operation
  541. // fail if the object's ETag matches the given value. This is useful for
  542. // getting updates only after the object has changed since the last
  543. // request. Use googleapi.IsNotModified to check whether the response
  544. // error from Do is the result of In-None-Match.
  545. func (c *TrainingGetCall) IfNoneMatch(entityTag string) *TrainingGetCall {
  546. c.ifNoneMatch_ = entityTag
  547. return c
  548. }
  549. // Context sets the context to be used in this call's Do method. Any
  550. // pending HTTP request will be aborted if the provided context is
  551. // canceled.
  552. func (c *TrainingGetCall) Context(ctx context.Context) *TrainingGetCall {
  553. c.ctx_ = ctx
  554. return c
  555. }
  556. func (c *TrainingGetCall) doRequest(alt string) (*http.Response, error) {
  557. var body io.Reader = nil
  558. c.urlParams_.Set("alt", alt)
  559. urls := googleapi.ResolveRelative(c.s.BasePath, "training/{data}")
  560. urls += "?" + c.urlParams_.Encode()
  561. req, _ := http.NewRequest("GET", urls, body)
  562. googleapi.Expand(req.URL, map[string]string{
  563. "data": c.data,
  564. })
  565. req.Header.Set("User-Agent", c.s.userAgent())
  566. if c.ifNoneMatch_ != "" {
  567. req.Header.Set("If-None-Match", c.ifNoneMatch_)
  568. }
  569. if c.ctx_ != nil {
  570. return ctxhttp.Do(c.ctx_, c.s.client, req)
  571. }
  572. return c.s.client.Do(req)
  573. }
  574. // Do executes the "prediction.training.get" call.
  575. // Exactly one of *Training or error will be non-nil. Any non-2xx status
  576. // code is an error. Response headers are in either
  577. // *Training.ServerResponse.Header or (if a response was returned at
  578. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  579. // to check whether the returned error was because
  580. // http.StatusNotModified was returned.
  581. func (c *TrainingGetCall) Do(opts ...googleapi.CallOption) (*Training, error) {
  582. gensupport.SetOptions(c.urlParams_, opts...)
  583. res, err := c.doRequest("json")
  584. if res != nil && res.StatusCode == http.StatusNotModified {
  585. if res.Body != nil {
  586. res.Body.Close()
  587. }
  588. return nil, &googleapi.Error{
  589. Code: res.StatusCode,
  590. Header: res.Header,
  591. }
  592. }
  593. if err != nil {
  594. return nil, err
  595. }
  596. defer googleapi.CloseBody(res)
  597. if err := googleapi.CheckResponse(res); err != nil {
  598. return nil, err
  599. }
  600. ret := &Training{
  601. ServerResponse: googleapi.ServerResponse{
  602. Header: res.Header,
  603. HTTPStatusCode: res.StatusCode,
  604. },
  605. }
  606. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  607. return nil, err
  608. }
  609. return ret, nil
  610. // {
  611. // "description": "Check training status of your model",
  612. // "httpMethod": "GET",
  613. // "id": "prediction.training.get",
  614. // "parameterOrder": [
  615. // "data"
  616. // ],
  617. // "parameters": {
  618. // "data": {
  619. // "description": "mybucket/mydata resource in Google Storage",
  620. // "location": "path",
  621. // "required": true,
  622. // "type": "string"
  623. // }
  624. // },
  625. // "path": "training/{data}",
  626. // "response": {
  627. // "$ref": "Training"
  628. // },
  629. // "scopes": [
  630. // "https://www.googleapis.com/auth/prediction"
  631. // ]
  632. // }
  633. }
  634. // method id "prediction.training.insert":
  635. type TrainingInsertCall struct {
  636. s *Service
  637. training *Training
  638. urlParams_ gensupport.URLParams
  639. ctx_ context.Context
  640. }
  641. // Insert: Begin training your model
  642. func (r *TrainingService) Insert(training *Training) *TrainingInsertCall {
  643. c := &TrainingInsertCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  644. c.training = training
  645. return c
  646. }
  647. // Data sets the optional parameter "data": mybucket/mydata resource in
  648. // Google Storage
  649. func (c *TrainingInsertCall) Data(data string) *TrainingInsertCall {
  650. c.urlParams_.Set("data", data)
  651. return c
  652. }
  653. // Fields allows partial responses to be retrieved. See
  654. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  655. // for more information.
  656. func (c *TrainingInsertCall) Fields(s ...googleapi.Field) *TrainingInsertCall {
  657. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  658. return c
  659. }
  660. // Context sets the context to be used in this call's Do method. Any
  661. // pending HTTP request will be aborted if the provided context is
  662. // canceled.
  663. func (c *TrainingInsertCall) Context(ctx context.Context) *TrainingInsertCall {
  664. c.ctx_ = ctx
  665. return c
  666. }
  667. func (c *TrainingInsertCall) doRequest(alt string) (*http.Response, error) {
  668. var body io.Reader = nil
  669. body, err := googleapi.WithoutDataWrapper.JSONReader(c.training)
  670. if err != nil {
  671. return nil, err
  672. }
  673. ctype := "application/json"
  674. c.urlParams_.Set("alt", alt)
  675. urls := googleapi.ResolveRelative(c.s.BasePath, "training")
  676. urls += "?" + c.urlParams_.Encode()
  677. req, _ := http.NewRequest("POST", urls, body)
  678. googleapi.SetOpaque(req.URL)
  679. req.Header.Set("Content-Type", ctype)
  680. req.Header.Set("User-Agent", c.s.userAgent())
  681. if c.ctx_ != nil {
  682. return ctxhttp.Do(c.ctx_, c.s.client, req)
  683. }
  684. return c.s.client.Do(req)
  685. }
  686. // Do executes the "prediction.training.insert" call.
  687. // Exactly one of *Training or error will be non-nil. Any non-2xx status
  688. // code is an error. Response headers are in either
  689. // *Training.ServerResponse.Header or (if a response was returned at
  690. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  691. // to check whether the returned error was because
  692. // http.StatusNotModified was returned.
  693. func (c *TrainingInsertCall) Do(opts ...googleapi.CallOption) (*Training, error) {
  694. gensupport.SetOptions(c.urlParams_, opts...)
  695. res, err := c.doRequest("json")
  696. if res != nil && res.StatusCode == http.StatusNotModified {
  697. if res.Body != nil {
  698. res.Body.Close()
  699. }
  700. return nil, &googleapi.Error{
  701. Code: res.StatusCode,
  702. Header: res.Header,
  703. }
  704. }
  705. if err != nil {
  706. return nil, err
  707. }
  708. defer googleapi.CloseBody(res)
  709. if err := googleapi.CheckResponse(res); err != nil {
  710. return nil, err
  711. }
  712. ret := &Training{
  713. ServerResponse: googleapi.ServerResponse{
  714. Header: res.Header,
  715. HTTPStatusCode: res.StatusCode,
  716. },
  717. }
  718. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  719. return nil, err
  720. }
  721. return ret, nil
  722. // {
  723. // "description": "Begin training your model",
  724. // "httpMethod": "POST",
  725. // "id": "prediction.training.insert",
  726. // "parameters": {
  727. // "data": {
  728. // "description": "mybucket/mydata resource in Google Storage",
  729. // "location": "query",
  730. // "type": "string"
  731. // }
  732. // },
  733. // "path": "training",
  734. // "request": {
  735. // "$ref": "Training"
  736. // },
  737. // "response": {
  738. // "$ref": "Training"
  739. // },
  740. // "scopes": [
  741. // "https://www.googleapis.com/auth/devstorage.full_control",
  742. // "https://www.googleapis.com/auth/devstorage.read_only",
  743. // "https://www.googleapis.com/auth/devstorage.read_write",
  744. // "https://www.googleapis.com/auth/prediction"
  745. // ]
  746. // }
  747. }
  748. // method id "prediction.training.update":
  749. type TrainingUpdateCall struct {
  750. s *Service
  751. data string
  752. update *Update
  753. urlParams_ gensupport.URLParams
  754. ctx_ context.Context
  755. }
  756. // Update: Add new data to a trained model
  757. func (r *TrainingService) Update(data string, update *Update) *TrainingUpdateCall {
  758. c := &TrainingUpdateCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  759. c.data = data
  760. c.update = update
  761. return c
  762. }
  763. // Fields allows partial responses to be retrieved. See
  764. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  765. // for more information.
  766. func (c *TrainingUpdateCall) Fields(s ...googleapi.Field) *TrainingUpdateCall {
  767. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  768. return c
  769. }
  770. // Context sets the context to be used in this call's Do method. Any
  771. // pending HTTP request will be aborted if the provided context is
  772. // canceled.
  773. func (c *TrainingUpdateCall) Context(ctx context.Context) *TrainingUpdateCall {
  774. c.ctx_ = ctx
  775. return c
  776. }
  777. func (c *TrainingUpdateCall) doRequest(alt string) (*http.Response, error) {
  778. var body io.Reader = nil
  779. body, err := googleapi.WithoutDataWrapper.JSONReader(c.update)
  780. if err != nil {
  781. return nil, err
  782. }
  783. ctype := "application/json"
  784. c.urlParams_.Set("alt", alt)
  785. urls := googleapi.ResolveRelative(c.s.BasePath, "training/{data}")
  786. urls += "?" + c.urlParams_.Encode()
  787. req, _ := http.NewRequest("PUT", urls, body)
  788. googleapi.Expand(req.URL, map[string]string{
  789. "data": c.data,
  790. })
  791. req.Header.Set("Content-Type", ctype)
  792. req.Header.Set("User-Agent", c.s.userAgent())
  793. if c.ctx_ != nil {
  794. return ctxhttp.Do(c.ctx_, c.s.client, req)
  795. }
  796. return c.s.client.Do(req)
  797. }
  798. // Do executes the "prediction.training.update" call.
  799. // Exactly one of *Training or error will be non-nil. Any non-2xx status
  800. // code is an error. Response headers are in either
  801. // *Training.ServerResponse.Header or (if a response was returned at
  802. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  803. // to check whether the returned error was because
  804. // http.StatusNotModified was returned.
  805. func (c *TrainingUpdateCall) Do(opts ...googleapi.CallOption) (*Training, error) {
  806. gensupport.SetOptions(c.urlParams_, opts...)
  807. res, err := c.doRequest("json")
  808. if res != nil && res.StatusCode == http.StatusNotModified {
  809. if res.Body != nil {
  810. res.Body.Close()
  811. }
  812. return nil, &googleapi.Error{
  813. Code: res.StatusCode,
  814. Header: res.Header,
  815. }
  816. }
  817. if err != nil {
  818. return nil, err
  819. }
  820. defer googleapi.CloseBody(res)
  821. if err := googleapi.CheckResponse(res); err != nil {
  822. return nil, err
  823. }
  824. ret := &Training{
  825. ServerResponse: googleapi.ServerResponse{
  826. Header: res.Header,
  827. HTTPStatusCode: res.StatusCode,
  828. },
  829. }
  830. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  831. return nil, err
  832. }
  833. return ret, nil
  834. // {
  835. // "description": "Add new data to a trained model",
  836. // "httpMethod": "PUT",
  837. // "id": "prediction.training.update",
  838. // "parameterOrder": [
  839. // "data"
  840. // ],
  841. // "parameters": {
  842. // "data": {
  843. // "description": "mybucket/mydata resource in Google Storage",
  844. // "location": "path",
  845. // "required": true,
  846. // "type": "string"
  847. // }
  848. // },
  849. // "path": "training/{data}",
  850. // "request": {
  851. // "$ref": "Update"
  852. // },
  853. // "response": {
  854. // "$ref": "Training"
  855. // },
  856. // "scopes": [
  857. // "https://www.googleapis.com/auth/prediction"
  858. // ]
  859. // }
  860. }