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.
 
 
 

1136 lines
34 KiB

  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. // NullFields is a list of field names (e.g. "Input") to include in API
  101. // requests with the JSON null value. By default, fields with empty
  102. // values are omitted from API requests. However, any field with an
  103. // empty value appearing in NullFields will be sent to the server as
  104. // null. It is an error if a field in this list has a non-empty value.
  105. // This may be used to include null fields in Patch requests.
  106. NullFields []string `json:"-"`
  107. }
  108. func (s *Input) MarshalJSON() ([]byte, error) {
  109. type NoMethod Input
  110. raw := NoMethod(*s)
  111. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  112. }
  113. type InputInput struct {
  114. CsvInstance []interface{} `json:"csvInstance,omitempty"`
  115. // ForceSendFields is a list of field names (e.g. "CsvInstance") to
  116. // unconditionally include in API requests. By default, fields with
  117. // empty values are omitted from API requests. However, any non-pointer,
  118. // non-interface field appearing in ForceSendFields will be sent to the
  119. // server regardless of whether the field is empty or not. This may be
  120. // used to include empty fields in Patch requests.
  121. ForceSendFields []string `json:"-"`
  122. // NullFields is a list of field names (e.g. "CsvInstance") to include
  123. // in API requests with the JSON null value. By default, fields with
  124. // empty values are omitted from API requests. However, any field with
  125. // an empty value appearing in NullFields will be sent to the server as
  126. // null. It is an error if a field in this list has a non-empty value.
  127. // This may be used to include null fields in Patch requests.
  128. NullFields []string `json:"-"`
  129. }
  130. func (s *InputInput) MarshalJSON() ([]byte, error) {
  131. type NoMethod InputInput
  132. raw := NoMethod(*s)
  133. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  134. }
  135. type Output struct {
  136. Id string `json:"id,omitempty"`
  137. Kind string `json:"kind,omitempty"`
  138. OutputLabel string `json:"outputLabel,omitempty"`
  139. OutputMulti []*OutputOutputMulti `json:"outputMulti,omitempty"`
  140. OutputValue float64 `json:"outputValue,omitempty"`
  141. SelfLink string `json:"selfLink,omitempty"`
  142. // ServerResponse contains the HTTP response code and headers from the
  143. // server.
  144. googleapi.ServerResponse `json:"-"`
  145. // ForceSendFields is a list of field names (e.g. "Id") to
  146. // unconditionally include in API requests. By default, fields with
  147. // empty values are omitted from API requests. However, any non-pointer,
  148. // non-interface field appearing in ForceSendFields will be sent to the
  149. // server regardless of whether the field is empty or not. This may be
  150. // used to include empty fields in Patch requests.
  151. ForceSendFields []string `json:"-"`
  152. // NullFields is a list of field names (e.g. "Id") to include in API
  153. // requests with the JSON null value. By default, fields with empty
  154. // values are omitted from API requests. However, any field with an
  155. // empty value appearing in NullFields will be sent to the server as
  156. // null. It is an error if a field in this list has a non-empty value.
  157. // This may be used to include null fields in Patch requests.
  158. NullFields []string `json:"-"`
  159. }
  160. func (s *Output) MarshalJSON() ([]byte, error) {
  161. type NoMethod Output
  162. raw := NoMethod(*s)
  163. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  164. }
  165. func (s *Output) UnmarshalJSON(data []byte) error {
  166. type NoMethod Output
  167. var s1 struct {
  168. OutputValue gensupport.JSONFloat64 `json:"outputValue"`
  169. *NoMethod
  170. }
  171. s1.NoMethod = (*NoMethod)(s)
  172. if err := json.Unmarshal(data, &s1); err != nil {
  173. return err
  174. }
  175. s.OutputValue = float64(s1.OutputValue)
  176. return nil
  177. }
  178. type OutputOutputMulti struct {
  179. Label string `json:"label,omitempty"`
  180. Score float64 `json:"score,omitempty"`
  181. // ForceSendFields is a list of field names (e.g. "Label") to
  182. // unconditionally include in API requests. By default, fields with
  183. // empty values are omitted from API requests. However, any non-pointer,
  184. // non-interface field appearing in ForceSendFields will be sent to the
  185. // server regardless of whether the field is empty or not. This may be
  186. // used to include empty fields in Patch requests.
  187. ForceSendFields []string `json:"-"`
  188. // NullFields is a list of field names (e.g. "Label") to include in API
  189. // requests with the JSON null value. By default, fields with empty
  190. // values are omitted from API requests. However, any field with an
  191. // empty value appearing in NullFields will be sent to the server as
  192. // null. It is an error if a field in this list has a non-empty value.
  193. // This may be used to include null fields in Patch requests.
  194. NullFields []string `json:"-"`
  195. }
  196. func (s *OutputOutputMulti) MarshalJSON() ([]byte, error) {
  197. type NoMethod OutputOutputMulti
  198. raw := NoMethod(*s)
  199. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  200. }
  201. func (s *OutputOutputMulti) UnmarshalJSON(data []byte) error {
  202. type NoMethod OutputOutputMulti
  203. var s1 struct {
  204. Score gensupport.JSONFloat64 `json:"score"`
  205. *NoMethod
  206. }
  207. s1.NoMethod = (*NoMethod)(s)
  208. if err := json.Unmarshal(data, &s1); err != nil {
  209. return err
  210. }
  211. s.Score = float64(s1.Score)
  212. return nil
  213. }
  214. type Training struct {
  215. Id string `json:"id,omitempty"`
  216. Kind string `json:"kind,omitempty"`
  217. ModelInfo *TrainingModelInfo `json:"modelInfo,omitempty"`
  218. SelfLink string `json:"selfLink,omitempty"`
  219. TrainingStatus string `json:"trainingStatus,omitempty"`
  220. // ServerResponse contains the HTTP response code and headers from the
  221. // server.
  222. googleapi.ServerResponse `json:"-"`
  223. // ForceSendFields is a list of field names (e.g. "Id") to
  224. // unconditionally include in API requests. By default, fields with
  225. // empty values are omitted from API requests. However, any non-pointer,
  226. // non-interface field appearing in ForceSendFields will be sent to the
  227. // server regardless of whether the field is empty or not. This may be
  228. // used to include empty fields in Patch requests.
  229. ForceSendFields []string `json:"-"`
  230. // NullFields is a list of field names (e.g. "Id") to include in API
  231. // requests with the JSON null value. By default, fields with empty
  232. // values are omitted from API requests. However, any field with an
  233. // empty value appearing in NullFields will be sent to the server as
  234. // null. It is an error if a field in this list has a non-empty value.
  235. // This may be used to include null fields in Patch requests.
  236. NullFields []string `json:"-"`
  237. }
  238. func (s *Training) MarshalJSON() ([]byte, error) {
  239. type NoMethod Training
  240. raw := NoMethod(*s)
  241. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  242. }
  243. type TrainingModelInfo struct {
  244. ClassificationAccuracy float64 `json:"classificationAccuracy,omitempty"`
  245. MeanSquaredError float64 `json:"meanSquaredError,omitempty"`
  246. ModelType string `json:"modelType,omitempty"`
  247. // ForceSendFields is a list of field names (e.g.
  248. // "ClassificationAccuracy") to unconditionally include in API requests.
  249. // By default, fields with empty values are omitted from API requests.
  250. // However, any non-pointer, non-interface field appearing in
  251. // ForceSendFields will be sent to the server regardless of whether the
  252. // field is empty or not. This may be used to include empty fields in
  253. // Patch requests.
  254. ForceSendFields []string `json:"-"`
  255. // NullFields is a list of field names (e.g. "ClassificationAccuracy")
  256. // to include in API requests with the JSON null value. By default,
  257. // fields with empty values are omitted from API requests. However, any
  258. // field with an empty value appearing in NullFields will be sent to the
  259. // server as null. It is an error if a field in this list has a
  260. // non-empty value. This may be used to include null fields in Patch
  261. // requests.
  262. NullFields []string `json:"-"`
  263. }
  264. func (s *TrainingModelInfo) MarshalJSON() ([]byte, error) {
  265. type NoMethod TrainingModelInfo
  266. raw := NoMethod(*s)
  267. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  268. }
  269. func (s *TrainingModelInfo) UnmarshalJSON(data []byte) error {
  270. type NoMethod TrainingModelInfo
  271. var s1 struct {
  272. ClassificationAccuracy gensupport.JSONFloat64 `json:"classificationAccuracy"`
  273. MeanSquaredError gensupport.JSONFloat64 `json:"meanSquaredError"`
  274. *NoMethod
  275. }
  276. s1.NoMethod = (*NoMethod)(s)
  277. if err := json.Unmarshal(data, &s1); err != nil {
  278. return err
  279. }
  280. s.ClassificationAccuracy = float64(s1.ClassificationAccuracy)
  281. s.MeanSquaredError = float64(s1.MeanSquaredError)
  282. return nil
  283. }
  284. type Update struct {
  285. // ClassLabel: The true class label of this instance
  286. ClassLabel string `json:"classLabel,omitempty"`
  287. // CsvInstance: The input features for this instance
  288. CsvInstance []interface{} `json:"csvInstance,omitempty"`
  289. // ForceSendFields is a list of field names (e.g. "ClassLabel") to
  290. // unconditionally include in API requests. By default, fields with
  291. // empty values are omitted from API requests. However, any non-pointer,
  292. // non-interface field appearing in ForceSendFields will be sent to the
  293. // server regardless of whether the field is empty or not. This may be
  294. // used to include empty fields in Patch requests.
  295. ForceSendFields []string `json:"-"`
  296. // NullFields is a list of field names (e.g. "ClassLabel") to include in
  297. // API requests with the JSON null value. By default, fields with empty
  298. // values are omitted from API requests. However, any field with an
  299. // empty value appearing in NullFields will be sent to the server as
  300. // null. It is an error if a field in this list has a non-empty value.
  301. // This may be used to include null fields in Patch requests.
  302. NullFields []string `json:"-"`
  303. }
  304. func (s *Update) MarshalJSON() ([]byte, error) {
  305. type NoMethod Update
  306. raw := NoMethod(*s)
  307. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  308. }
  309. // method id "prediction.predict":
  310. type PredictCall struct {
  311. s *Service
  312. data string
  313. input *Input
  314. urlParams_ gensupport.URLParams
  315. ctx_ context.Context
  316. header_ http.Header
  317. }
  318. // Predict: Submit data and request a prediction
  319. func (s *Service) Predict(data string, input *Input) *PredictCall {
  320. c := &PredictCall{s: s, urlParams_: make(gensupport.URLParams)}
  321. c.data = data
  322. c.input = input
  323. return c
  324. }
  325. // Fields allows partial responses to be retrieved. See
  326. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  327. // for more information.
  328. func (c *PredictCall) Fields(s ...googleapi.Field) *PredictCall {
  329. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  330. return c
  331. }
  332. // Context sets the context to be used in this call's Do method. Any
  333. // pending HTTP request will be aborted if the provided context is
  334. // canceled.
  335. func (c *PredictCall) Context(ctx context.Context) *PredictCall {
  336. c.ctx_ = ctx
  337. return c
  338. }
  339. // Header returns an http.Header that can be modified by the caller to
  340. // add HTTP headers to the request.
  341. func (c *PredictCall) Header() http.Header {
  342. if c.header_ == nil {
  343. c.header_ = make(http.Header)
  344. }
  345. return c.header_
  346. }
  347. func (c *PredictCall) doRequest(alt string) (*http.Response, error) {
  348. reqHeaders := make(http.Header)
  349. for k, v := range c.header_ {
  350. reqHeaders[k] = v
  351. }
  352. reqHeaders.Set("User-Agent", c.s.userAgent())
  353. var body io.Reader = nil
  354. body, err := googleapi.WithoutDataWrapper.JSONReader(c.input)
  355. if err != nil {
  356. return nil, err
  357. }
  358. reqHeaders.Set("Content-Type", "application/json")
  359. c.urlParams_.Set("alt", alt)
  360. urls := googleapi.ResolveRelative(c.s.BasePath, "training/{data}/predict")
  361. urls += "?" + c.urlParams_.Encode()
  362. req, _ := http.NewRequest("POST", urls, body)
  363. req.Header = reqHeaders
  364. googleapi.Expand(req.URL, map[string]string{
  365. "data": c.data,
  366. })
  367. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  368. }
  369. // Do executes the "prediction.predict" call.
  370. // Exactly one of *Output or error will be non-nil. Any non-2xx status
  371. // code is an error. Response headers are in either
  372. // *Output.ServerResponse.Header or (if a response was returned at all)
  373. // in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to
  374. // check whether the returned error was because http.StatusNotModified
  375. // was returned.
  376. func (c *PredictCall) Do(opts ...googleapi.CallOption) (*Output, error) {
  377. gensupport.SetOptions(c.urlParams_, opts...)
  378. res, err := c.doRequest("json")
  379. if res != nil && res.StatusCode == http.StatusNotModified {
  380. if res.Body != nil {
  381. res.Body.Close()
  382. }
  383. return nil, &googleapi.Error{
  384. Code: res.StatusCode,
  385. Header: res.Header,
  386. }
  387. }
  388. if err != nil {
  389. return nil, err
  390. }
  391. defer googleapi.CloseBody(res)
  392. if err := googleapi.CheckResponse(res); err != nil {
  393. return nil, err
  394. }
  395. ret := &Output{
  396. ServerResponse: googleapi.ServerResponse{
  397. Header: res.Header,
  398. HTTPStatusCode: res.StatusCode,
  399. },
  400. }
  401. target := &ret
  402. if err := gensupport.DecodeResponse(target, res); err != nil {
  403. return nil, err
  404. }
  405. return ret, nil
  406. // {
  407. // "description": "Submit data and request a prediction",
  408. // "httpMethod": "POST",
  409. // "id": "prediction.predict",
  410. // "parameterOrder": [
  411. // "data"
  412. // ],
  413. // "parameters": {
  414. // "data": {
  415. // "description": "mybucket%2Fmydata resource in Google Storage",
  416. // "location": "path",
  417. // "required": true,
  418. // "type": "string"
  419. // }
  420. // },
  421. // "path": "training/{data}/predict",
  422. // "request": {
  423. // "$ref": "Input"
  424. // },
  425. // "response": {
  426. // "$ref": "Output"
  427. // },
  428. // "scopes": [
  429. // "https://www.googleapis.com/auth/prediction"
  430. // ]
  431. // }
  432. }
  433. // method id "prediction.hostedmodels.predict":
  434. type HostedmodelsPredictCall struct {
  435. s *Service
  436. hostedModelName string
  437. input *Input
  438. urlParams_ gensupport.URLParams
  439. ctx_ context.Context
  440. header_ http.Header
  441. }
  442. // Predict: Submit input and request an output against a hosted model
  443. func (r *HostedmodelsService) Predict(hostedModelName string, input *Input) *HostedmodelsPredictCall {
  444. c := &HostedmodelsPredictCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  445. c.hostedModelName = hostedModelName
  446. c.input = input
  447. return c
  448. }
  449. // Fields allows partial responses to be retrieved. See
  450. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  451. // for more information.
  452. func (c *HostedmodelsPredictCall) Fields(s ...googleapi.Field) *HostedmodelsPredictCall {
  453. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  454. return c
  455. }
  456. // Context sets the context to be used in this call's Do method. Any
  457. // pending HTTP request will be aborted if the provided context is
  458. // canceled.
  459. func (c *HostedmodelsPredictCall) Context(ctx context.Context) *HostedmodelsPredictCall {
  460. c.ctx_ = ctx
  461. return c
  462. }
  463. // Header returns an http.Header that can be modified by the caller to
  464. // add HTTP headers to the request.
  465. func (c *HostedmodelsPredictCall) Header() http.Header {
  466. if c.header_ == nil {
  467. c.header_ = make(http.Header)
  468. }
  469. return c.header_
  470. }
  471. func (c *HostedmodelsPredictCall) doRequest(alt string) (*http.Response, error) {
  472. reqHeaders := make(http.Header)
  473. for k, v := range c.header_ {
  474. reqHeaders[k] = v
  475. }
  476. reqHeaders.Set("User-Agent", c.s.userAgent())
  477. var body io.Reader = nil
  478. body, err := googleapi.WithoutDataWrapper.JSONReader(c.input)
  479. if err != nil {
  480. return nil, err
  481. }
  482. reqHeaders.Set("Content-Type", "application/json")
  483. c.urlParams_.Set("alt", alt)
  484. urls := googleapi.ResolveRelative(c.s.BasePath, "hostedmodels/{hostedModelName}/predict")
  485. urls += "?" + c.urlParams_.Encode()
  486. req, _ := http.NewRequest("POST", urls, body)
  487. req.Header = reqHeaders
  488. googleapi.Expand(req.URL, map[string]string{
  489. "hostedModelName": c.hostedModelName,
  490. })
  491. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  492. }
  493. // Do executes the "prediction.hostedmodels.predict" call.
  494. // Exactly one of *Output or error will be non-nil. Any non-2xx status
  495. // code is an error. Response headers are in either
  496. // *Output.ServerResponse.Header or (if a response was returned at all)
  497. // in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to
  498. // check whether the returned error was because http.StatusNotModified
  499. // was returned.
  500. func (c *HostedmodelsPredictCall) Do(opts ...googleapi.CallOption) (*Output, error) {
  501. gensupport.SetOptions(c.urlParams_, opts...)
  502. res, err := c.doRequest("json")
  503. if res != nil && res.StatusCode == http.StatusNotModified {
  504. if res.Body != nil {
  505. res.Body.Close()
  506. }
  507. return nil, &googleapi.Error{
  508. Code: res.StatusCode,
  509. Header: res.Header,
  510. }
  511. }
  512. if err != nil {
  513. return nil, err
  514. }
  515. defer googleapi.CloseBody(res)
  516. if err := googleapi.CheckResponse(res); err != nil {
  517. return nil, err
  518. }
  519. ret := &Output{
  520. ServerResponse: googleapi.ServerResponse{
  521. Header: res.Header,
  522. HTTPStatusCode: res.StatusCode,
  523. },
  524. }
  525. target := &ret
  526. if err := gensupport.DecodeResponse(target, res); err != nil {
  527. return nil, err
  528. }
  529. return ret, nil
  530. // {
  531. // "description": "Submit input and request an output against a hosted model",
  532. // "httpMethod": "POST",
  533. // "id": "prediction.hostedmodels.predict",
  534. // "parameterOrder": [
  535. // "hostedModelName"
  536. // ],
  537. // "parameters": {
  538. // "hostedModelName": {
  539. // "description": "The name of a hosted model",
  540. // "location": "path",
  541. // "required": true,
  542. // "type": "string"
  543. // }
  544. // },
  545. // "path": "hostedmodels/{hostedModelName}/predict",
  546. // "request": {
  547. // "$ref": "Input"
  548. // },
  549. // "response": {
  550. // "$ref": "Output"
  551. // },
  552. // "scopes": [
  553. // "https://www.googleapis.com/auth/prediction"
  554. // ]
  555. // }
  556. }
  557. // method id "prediction.training.delete":
  558. type TrainingDeleteCall struct {
  559. s *Service
  560. data string
  561. urlParams_ gensupport.URLParams
  562. ctx_ context.Context
  563. header_ http.Header
  564. }
  565. // Delete: Delete a trained model
  566. func (r *TrainingService) Delete(data string) *TrainingDeleteCall {
  567. c := &TrainingDeleteCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  568. c.data = data
  569. return c
  570. }
  571. // Fields allows partial responses to be retrieved. See
  572. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  573. // for more information.
  574. func (c *TrainingDeleteCall) Fields(s ...googleapi.Field) *TrainingDeleteCall {
  575. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  576. return c
  577. }
  578. // Context sets the context to be used in this call's Do method. Any
  579. // pending HTTP request will be aborted if the provided context is
  580. // canceled.
  581. func (c *TrainingDeleteCall) Context(ctx context.Context) *TrainingDeleteCall {
  582. c.ctx_ = ctx
  583. return c
  584. }
  585. // Header returns an http.Header that can be modified by the caller to
  586. // add HTTP headers to the request.
  587. func (c *TrainingDeleteCall) Header() http.Header {
  588. if c.header_ == nil {
  589. c.header_ = make(http.Header)
  590. }
  591. return c.header_
  592. }
  593. func (c *TrainingDeleteCall) doRequest(alt string) (*http.Response, error) {
  594. reqHeaders := make(http.Header)
  595. for k, v := range c.header_ {
  596. reqHeaders[k] = v
  597. }
  598. reqHeaders.Set("User-Agent", c.s.userAgent())
  599. var body io.Reader = nil
  600. c.urlParams_.Set("alt", alt)
  601. urls := googleapi.ResolveRelative(c.s.BasePath, "training/{data}")
  602. urls += "?" + c.urlParams_.Encode()
  603. req, _ := http.NewRequest("DELETE", urls, body)
  604. req.Header = reqHeaders
  605. googleapi.Expand(req.URL, map[string]string{
  606. "data": c.data,
  607. })
  608. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  609. }
  610. // Do executes the "prediction.training.delete" call.
  611. func (c *TrainingDeleteCall) Do(opts ...googleapi.CallOption) error {
  612. gensupport.SetOptions(c.urlParams_, opts...)
  613. res, err := c.doRequest("json")
  614. if err != nil {
  615. return err
  616. }
  617. defer googleapi.CloseBody(res)
  618. if err := googleapi.CheckResponse(res); err != nil {
  619. return err
  620. }
  621. return nil
  622. // {
  623. // "description": "Delete a trained model",
  624. // "httpMethod": "DELETE",
  625. // "id": "prediction.training.delete",
  626. // "parameterOrder": [
  627. // "data"
  628. // ],
  629. // "parameters": {
  630. // "data": {
  631. // "description": "mybucket/mydata resource in Google Storage",
  632. // "location": "path",
  633. // "required": true,
  634. // "type": "string"
  635. // }
  636. // },
  637. // "path": "training/{data}",
  638. // "scopes": [
  639. // "https://www.googleapis.com/auth/prediction"
  640. // ]
  641. // }
  642. }
  643. // method id "prediction.training.get":
  644. type TrainingGetCall struct {
  645. s *Service
  646. data string
  647. urlParams_ gensupport.URLParams
  648. ifNoneMatch_ string
  649. ctx_ context.Context
  650. header_ http.Header
  651. }
  652. // Get: Check training status of your model
  653. func (r *TrainingService) Get(data string) *TrainingGetCall {
  654. c := &TrainingGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  655. c.data = data
  656. return c
  657. }
  658. // Fields allows partial responses to be retrieved. See
  659. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  660. // for more information.
  661. func (c *TrainingGetCall) Fields(s ...googleapi.Field) *TrainingGetCall {
  662. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  663. return c
  664. }
  665. // IfNoneMatch sets the optional parameter which makes the operation
  666. // fail if the object's ETag matches the given value. This is useful for
  667. // getting updates only after the object has changed since the last
  668. // request. Use googleapi.IsNotModified to check whether the response
  669. // error from Do is the result of In-None-Match.
  670. func (c *TrainingGetCall) IfNoneMatch(entityTag string) *TrainingGetCall {
  671. c.ifNoneMatch_ = entityTag
  672. return c
  673. }
  674. // Context sets the context to be used in this call's Do method. Any
  675. // pending HTTP request will be aborted if the provided context is
  676. // canceled.
  677. func (c *TrainingGetCall) Context(ctx context.Context) *TrainingGetCall {
  678. c.ctx_ = ctx
  679. return c
  680. }
  681. // Header returns an http.Header that can be modified by the caller to
  682. // add HTTP headers to the request.
  683. func (c *TrainingGetCall) Header() http.Header {
  684. if c.header_ == nil {
  685. c.header_ = make(http.Header)
  686. }
  687. return c.header_
  688. }
  689. func (c *TrainingGetCall) doRequest(alt string) (*http.Response, error) {
  690. reqHeaders := make(http.Header)
  691. for k, v := range c.header_ {
  692. reqHeaders[k] = v
  693. }
  694. reqHeaders.Set("User-Agent", c.s.userAgent())
  695. if c.ifNoneMatch_ != "" {
  696. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  697. }
  698. var body io.Reader = nil
  699. c.urlParams_.Set("alt", alt)
  700. urls := googleapi.ResolveRelative(c.s.BasePath, "training/{data}")
  701. urls += "?" + c.urlParams_.Encode()
  702. req, _ := http.NewRequest("GET", urls, body)
  703. req.Header = reqHeaders
  704. googleapi.Expand(req.URL, map[string]string{
  705. "data": c.data,
  706. })
  707. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  708. }
  709. // Do executes the "prediction.training.get" call.
  710. // Exactly one of *Training or error will be non-nil. Any non-2xx status
  711. // code is an error. Response headers are in either
  712. // *Training.ServerResponse.Header or (if a response was returned at
  713. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  714. // to check whether the returned error was because
  715. // http.StatusNotModified was returned.
  716. func (c *TrainingGetCall) Do(opts ...googleapi.CallOption) (*Training, error) {
  717. gensupport.SetOptions(c.urlParams_, opts...)
  718. res, err := c.doRequest("json")
  719. if res != nil && res.StatusCode == http.StatusNotModified {
  720. if res.Body != nil {
  721. res.Body.Close()
  722. }
  723. return nil, &googleapi.Error{
  724. Code: res.StatusCode,
  725. Header: res.Header,
  726. }
  727. }
  728. if err != nil {
  729. return nil, err
  730. }
  731. defer googleapi.CloseBody(res)
  732. if err := googleapi.CheckResponse(res); err != nil {
  733. return nil, err
  734. }
  735. ret := &Training{
  736. ServerResponse: googleapi.ServerResponse{
  737. Header: res.Header,
  738. HTTPStatusCode: res.StatusCode,
  739. },
  740. }
  741. target := &ret
  742. if err := gensupport.DecodeResponse(target, res); err != nil {
  743. return nil, err
  744. }
  745. return ret, nil
  746. // {
  747. // "description": "Check training status of your model",
  748. // "httpMethod": "GET",
  749. // "id": "prediction.training.get",
  750. // "parameterOrder": [
  751. // "data"
  752. // ],
  753. // "parameters": {
  754. // "data": {
  755. // "description": "mybucket/mydata resource in Google Storage",
  756. // "location": "path",
  757. // "required": true,
  758. // "type": "string"
  759. // }
  760. // },
  761. // "path": "training/{data}",
  762. // "response": {
  763. // "$ref": "Training"
  764. // },
  765. // "scopes": [
  766. // "https://www.googleapis.com/auth/prediction"
  767. // ]
  768. // }
  769. }
  770. // method id "prediction.training.insert":
  771. type TrainingInsertCall struct {
  772. s *Service
  773. training *Training
  774. urlParams_ gensupport.URLParams
  775. ctx_ context.Context
  776. header_ http.Header
  777. }
  778. // Insert: Begin training your model
  779. func (r *TrainingService) Insert(training *Training) *TrainingInsertCall {
  780. c := &TrainingInsertCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  781. c.training = training
  782. return c
  783. }
  784. // Data sets the optional parameter "data": mybucket/mydata resource in
  785. // Google Storage
  786. func (c *TrainingInsertCall) Data(data string) *TrainingInsertCall {
  787. c.urlParams_.Set("data", data)
  788. return c
  789. }
  790. // Fields allows partial responses to be retrieved. See
  791. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  792. // for more information.
  793. func (c *TrainingInsertCall) Fields(s ...googleapi.Field) *TrainingInsertCall {
  794. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  795. return c
  796. }
  797. // Context sets the context to be used in this call's Do method. Any
  798. // pending HTTP request will be aborted if the provided context is
  799. // canceled.
  800. func (c *TrainingInsertCall) Context(ctx context.Context) *TrainingInsertCall {
  801. c.ctx_ = ctx
  802. return c
  803. }
  804. // Header returns an http.Header that can be modified by the caller to
  805. // add HTTP headers to the request.
  806. func (c *TrainingInsertCall) Header() http.Header {
  807. if c.header_ == nil {
  808. c.header_ = make(http.Header)
  809. }
  810. return c.header_
  811. }
  812. func (c *TrainingInsertCall) doRequest(alt string) (*http.Response, error) {
  813. reqHeaders := make(http.Header)
  814. for k, v := range c.header_ {
  815. reqHeaders[k] = v
  816. }
  817. reqHeaders.Set("User-Agent", c.s.userAgent())
  818. var body io.Reader = nil
  819. body, err := googleapi.WithoutDataWrapper.JSONReader(c.training)
  820. if err != nil {
  821. return nil, err
  822. }
  823. reqHeaders.Set("Content-Type", "application/json")
  824. c.urlParams_.Set("alt", alt)
  825. urls := googleapi.ResolveRelative(c.s.BasePath, "training")
  826. urls += "?" + c.urlParams_.Encode()
  827. req, _ := http.NewRequest("POST", urls, body)
  828. req.Header = reqHeaders
  829. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  830. }
  831. // Do executes the "prediction.training.insert" call.
  832. // Exactly one of *Training or error will be non-nil. Any non-2xx status
  833. // code is an error. Response headers are in either
  834. // *Training.ServerResponse.Header or (if a response was returned at
  835. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  836. // to check whether the returned error was because
  837. // http.StatusNotModified was returned.
  838. func (c *TrainingInsertCall) Do(opts ...googleapi.CallOption) (*Training, error) {
  839. gensupport.SetOptions(c.urlParams_, opts...)
  840. res, err := c.doRequest("json")
  841. if res != nil && res.StatusCode == http.StatusNotModified {
  842. if res.Body != nil {
  843. res.Body.Close()
  844. }
  845. return nil, &googleapi.Error{
  846. Code: res.StatusCode,
  847. Header: res.Header,
  848. }
  849. }
  850. if err != nil {
  851. return nil, err
  852. }
  853. defer googleapi.CloseBody(res)
  854. if err := googleapi.CheckResponse(res); err != nil {
  855. return nil, err
  856. }
  857. ret := &Training{
  858. ServerResponse: googleapi.ServerResponse{
  859. Header: res.Header,
  860. HTTPStatusCode: res.StatusCode,
  861. },
  862. }
  863. target := &ret
  864. if err := gensupport.DecodeResponse(target, res); err != nil {
  865. return nil, err
  866. }
  867. return ret, nil
  868. // {
  869. // "description": "Begin training your model",
  870. // "httpMethod": "POST",
  871. // "id": "prediction.training.insert",
  872. // "parameters": {
  873. // "data": {
  874. // "description": "mybucket/mydata resource in Google Storage",
  875. // "location": "query",
  876. // "type": "string"
  877. // }
  878. // },
  879. // "path": "training",
  880. // "request": {
  881. // "$ref": "Training"
  882. // },
  883. // "response": {
  884. // "$ref": "Training"
  885. // },
  886. // "scopes": [
  887. // "https://www.googleapis.com/auth/devstorage.full_control",
  888. // "https://www.googleapis.com/auth/devstorage.read_only",
  889. // "https://www.googleapis.com/auth/devstorage.read_write",
  890. // "https://www.googleapis.com/auth/prediction"
  891. // ]
  892. // }
  893. }
  894. // method id "prediction.training.update":
  895. type TrainingUpdateCall struct {
  896. s *Service
  897. data string
  898. update *Update
  899. urlParams_ gensupport.URLParams
  900. ctx_ context.Context
  901. header_ http.Header
  902. }
  903. // Update: Add new data to a trained model
  904. func (r *TrainingService) Update(data string, update *Update) *TrainingUpdateCall {
  905. c := &TrainingUpdateCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  906. c.data = data
  907. c.update = update
  908. return c
  909. }
  910. // Fields allows partial responses to be retrieved. See
  911. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  912. // for more information.
  913. func (c *TrainingUpdateCall) Fields(s ...googleapi.Field) *TrainingUpdateCall {
  914. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  915. return c
  916. }
  917. // Context sets the context to be used in this call's Do method. Any
  918. // pending HTTP request will be aborted if the provided context is
  919. // canceled.
  920. func (c *TrainingUpdateCall) Context(ctx context.Context) *TrainingUpdateCall {
  921. c.ctx_ = ctx
  922. return c
  923. }
  924. // Header returns an http.Header that can be modified by the caller to
  925. // add HTTP headers to the request.
  926. func (c *TrainingUpdateCall) Header() http.Header {
  927. if c.header_ == nil {
  928. c.header_ = make(http.Header)
  929. }
  930. return c.header_
  931. }
  932. func (c *TrainingUpdateCall) doRequest(alt string) (*http.Response, error) {
  933. reqHeaders := make(http.Header)
  934. for k, v := range c.header_ {
  935. reqHeaders[k] = v
  936. }
  937. reqHeaders.Set("User-Agent", c.s.userAgent())
  938. var body io.Reader = nil
  939. body, err := googleapi.WithoutDataWrapper.JSONReader(c.update)
  940. if err != nil {
  941. return nil, err
  942. }
  943. reqHeaders.Set("Content-Type", "application/json")
  944. c.urlParams_.Set("alt", alt)
  945. urls := googleapi.ResolveRelative(c.s.BasePath, "training/{data}")
  946. urls += "?" + c.urlParams_.Encode()
  947. req, _ := http.NewRequest("PUT", urls, body)
  948. req.Header = reqHeaders
  949. googleapi.Expand(req.URL, map[string]string{
  950. "data": c.data,
  951. })
  952. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  953. }
  954. // Do executes the "prediction.training.update" call.
  955. // Exactly one of *Training or error will be non-nil. Any non-2xx status
  956. // code is an error. Response headers are in either
  957. // *Training.ServerResponse.Header or (if a response was returned at
  958. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  959. // to check whether the returned error was because
  960. // http.StatusNotModified was returned.
  961. func (c *TrainingUpdateCall) Do(opts ...googleapi.CallOption) (*Training, error) {
  962. gensupport.SetOptions(c.urlParams_, opts...)
  963. res, err := c.doRequest("json")
  964. if res != nil && res.StatusCode == http.StatusNotModified {
  965. if res.Body != nil {
  966. res.Body.Close()
  967. }
  968. return nil, &googleapi.Error{
  969. Code: res.StatusCode,
  970. Header: res.Header,
  971. }
  972. }
  973. if err != nil {
  974. return nil, err
  975. }
  976. defer googleapi.CloseBody(res)
  977. if err := googleapi.CheckResponse(res); err != nil {
  978. return nil, err
  979. }
  980. ret := &Training{
  981. ServerResponse: googleapi.ServerResponse{
  982. Header: res.Header,
  983. HTTPStatusCode: res.StatusCode,
  984. },
  985. }
  986. target := &ret
  987. if err := gensupport.DecodeResponse(target, res); err != nil {
  988. return nil, err
  989. }
  990. return ret, nil
  991. // {
  992. // "description": "Add new data to a trained model",
  993. // "httpMethod": "PUT",
  994. // "id": "prediction.training.update",
  995. // "parameterOrder": [
  996. // "data"
  997. // ],
  998. // "parameters": {
  999. // "data": {
  1000. // "description": "mybucket/mydata resource in Google Storage",
  1001. // "location": "path",
  1002. // "required": true,
  1003. // "type": "string"
  1004. // }
  1005. // },
  1006. // "path": "training/{data}",
  1007. // "request": {
  1008. // "$ref": "Update"
  1009. // },
  1010. // "response": {
  1011. // "$ref": "Training"
  1012. // },
  1013. // "scopes": [
  1014. // "https://www.googleapis.com/auth/prediction"
  1015. // ]
  1016. // }
  1017. }