script-gen.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. // Package script provides access to the Google Apps Script Execution API.
  2. //
  3. // See https://developers.google.com/apps-script/execution/rest/v1/run
  4. //
  5. // Usage example:
  6. //
  7. // import "google.golang.org/api/script/v1"
  8. // ...
  9. // scriptService, err := script.New(oauthHttpClient)
  10. package script // import "google.golang.org/api/script/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 = "script:v1"
  41. const apiName = "script"
  42. const apiVersion = "v1"
  43. const basePath = "https://script.googleapis.com/"
  44. // OAuth2 scopes used by this API.
  45. const (
  46. // View and manage your mail
  47. MailGoogleComScope = "https://mail.google.com/"
  48. // Manage your calendars
  49. WwwGoogleComCalendarFeedsScope = "https://www.google.com/calendar/feeds"
  50. // Manage your contacts
  51. WwwGoogleComM8FeedsScope = "https://www.google.com/m8/feeds"
  52. // View and manage the provisioning of groups on your domain
  53. AdminDirectoryGroupScope = "https://www.googleapis.com/auth/admin.directory.group"
  54. // View and manage the provisioning of users on your domain
  55. AdminDirectoryUserScope = "https://www.googleapis.com/auth/admin.directory.user"
  56. // View and manage the files in your Google Drive
  57. DriveScope = "https://www.googleapis.com/auth/drive"
  58. // View and manage your forms in Google Drive
  59. FormsScope = "https://www.googleapis.com/auth/forms"
  60. // View and manage forms that this application has been installed in
  61. FormsCurrentonlyScope = "https://www.googleapis.com/auth/forms.currentonly"
  62. // View and manage your Google Groups
  63. GroupsScope = "https://www.googleapis.com/auth/groups"
  64. // View your email address
  65. UserinfoEmailScope = "https://www.googleapis.com/auth/userinfo.email"
  66. )
  67. func New(client *http.Client) (*Service, error) {
  68. if client == nil {
  69. return nil, errors.New("client is nil")
  70. }
  71. s := &Service{client: client, BasePath: basePath}
  72. s.Scripts = NewScriptsService(s)
  73. return s, nil
  74. }
  75. type Service struct {
  76. client *http.Client
  77. BasePath string // API endpoint base URL
  78. UserAgent string // optional additional User-Agent fragment
  79. Scripts *ScriptsService
  80. }
  81. func (s *Service) userAgent() string {
  82. if s.UserAgent == "" {
  83. return googleapi.UserAgent
  84. }
  85. return googleapi.UserAgent + " " + s.UserAgent
  86. }
  87. func NewScriptsService(s *Service) *ScriptsService {
  88. rs := &ScriptsService{s: s}
  89. return rs
  90. }
  91. type ScriptsService struct {
  92. s *Service
  93. }
  94. // ExecutionError: An object that provides information about the nature
  95. // of an error in the Apps Script Execution API. If an `run` call
  96. // succeeds but the script function (or Apps Script itself) throws an
  97. // exception, the response body's `error` field will contain a `Status`
  98. // object. The `Status` object's `details` field will contain an array
  99. // with a single one of these `ExecutionError` objects.
  100. type ExecutionError struct {
  101. // ErrorMessage: The error message thrown by Apps Script, usually
  102. // localized into the user's language.
  103. ErrorMessage string `json:"errorMessage,omitempty"`
  104. // ErrorType: The error type, for example `TypeError` or
  105. // `ReferenceError`. If the error type is unavailable, this field is not
  106. // included.
  107. ErrorType string `json:"errorType,omitempty"`
  108. // ScriptStackTraceElements: An array of objects that provide a stack
  109. // trace through the script to show where the execution failed, with the
  110. // deepest call first.
  111. ScriptStackTraceElements []*ScriptStackTraceElement `json:"scriptStackTraceElements,omitempty"`
  112. // ForceSendFields is a list of field names (e.g. "ErrorMessage") to
  113. // unconditionally include in API requests. By default, fields with
  114. // empty values are omitted from API requests. However, any non-pointer,
  115. // non-interface field appearing in ForceSendFields will be sent to the
  116. // server regardless of whether the field is empty or not. This may be
  117. // used to include empty fields in Patch requests.
  118. ForceSendFields []string `json:"-"`
  119. }
  120. func (s *ExecutionError) MarshalJSON() ([]byte, error) {
  121. type noMethod ExecutionError
  122. raw := noMethod(*s)
  123. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  124. }
  125. // ExecutionRequest: A request to run the function in a script. The
  126. // script is identified by the specified `script_id`. Executing a
  127. // function on a script will return results based on the implementation
  128. // of the script.
  129. type ExecutionRequest struct {
  130. // DevMode: If `true` and the user is an owner of the script, the script
  131. // runs at the most recently saved version rather than the version
  132. // deployed for use with the Execution API. Optional; default is
  133. // `false`.
  134. DevMode bool `json:"devMode,omitempty"`
  135. // Function: The name of the function to execute in the given script.
  136. // The name does not include parentheses or parameters.
  137. Function string `json:"function,omitempty"`
  138. // Parameters: The parameters to be passed to the function being
  139. // executed. The type for each parameter should match the expected type
  140. // in Apps Script. Parameters cannot be Apps Script-specific objects
  141. // (such as a `Document` or `Calendar`); they can only be primitive
  142. // types such as a `string`, `number`, `array`, `object`, or `boolean`.
  143. // Optional.
  144. Parameters []interface{} `json:"parameters,omitempty"`
  145. // SessionState: This field is not used.
  146. SessionState string `json:"sessionState,omitempty"`
  147. // ForceSendFields is a list of field names (e.g. "DevMode") 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 *ExecutionRequest) MarshalJSON() ([]byte, error) {
  156. type noMethod ExecutionRequest
  157. raw := noMethod(*s)
  158. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  159. }
  160. // ExecutionResponse: An object that provides the return value of a
  161. // function executed through the Apps Script Execution API. If an `run`
  162. // call succeeds and the script function returns successfully, the
  163. // response body's `response` field will contain this
  164. // `ExecutionResponse` object.
  165. type ExecutionResponse struct {
  166. // Result: The return value of the script function. The type will match
  167. // the type returned in Apps Script. Functions called through the
  168. // Execution API cannot return Apps Script-specific objects (such as a
  169. // `Document` or `Calendar`); they can only return primitive types such
  170. // as a `string`, `number`, `array`, `object`, or `boolean`.
  171. Result interface{} `json:"result,omitempty"`
  172. // ForceSendFields is a list of field names (e.g. "Result") to
  173. // unconditionally include in API requests. By default, fields with
  174. // empty values are omitted from API requests. However, any non-pointer,
  175. // non-interface field appearing in ForceSendFields will be sent to the
  176. // server regardless of whether the field is empty or not. This may be
  177. // used to include empty fields in Patch requests.
  178. ForceSendFields []string `json:"-"`
  179. }
  180. func (s *ExecutionResponse) MarshalJSON() ([]byte, error) {
  181. type noMethod ExecutionResponse
  182. raw := noMethod(*s)
  183. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  184. }
  185. // Operation: The response will not arrive until the function finishes
  186. // executing. The maximum runtime is listed in the guide to [limitations
  187. // in Apps
  188. // Script](https://developers.google.com/apps-script/guides/services/quot
  189. // as#current_limitations).
  190. // If the script function returns successfully, the `response` field
  191. // will contain an `ExecutionResponse` object with the function's return
  192. // value in the object's `result` field.
  193. //
  194. // If the script function (or Apps Script itself) throws an exception,
  195. // the `error` field will contain a `Status` object. The `Status`
  196. // object's `details` field will contain an array with a single
  197. // `ExecutionError` object that provides information about the nature of
  198. // the error.
  199. //
  200. // If the `run` call itself fails (for example, because of a malformed
  201. // request or an authorization error), the method will return an HTTP
  202. // response code in the 4XX range with a different format for the
  203. // response body. Client libraries will automatically convert a 4XX
  204. // response into an exception class.
  205. type Operation struct {
  206. // Done: This field is not used.
  207. Done bool `json:"done,omitempty"`
  208. // Error: If a `run` call succeeds but the script function (or Apps
  209. // Script itself) throws an exception, this field will contain a
  210. // `Status` object. The `Status` object's `details` field will contain
  211. // an array with a single `ExecutionError` object that provides
  212. // information about the nature of the error.
  213. Error *Status `json:"error,omitempty"`
  214. // Metadata: This field is not used.
  215. Metadata OperationMetadata `json:"metadata,omitempty"`
  216. // Name: This field is not used.
  217. Name string `json:"name,omitempty"`
  218. // Response: If the script function returns successfully, this field
  219. // will contain an `ExecutionResponse` object with the function's return
  220. // value as the object's `result` field.
  221. Response OperationResponse `json:"response,omitempty"`
  222. // ServerResponse contains the HTTP response code and headers from the
  223. // server.
  224. googleapi.ServerResponse `json:"-"`
  225. // ForceSendFields is a list of field names (e.g. "Done") to
  226. // unconditionally include in API requests. By default, fields with
  227. // empty values are omitted from API requests. However, any non-pointer,
  228. // non-interface field appearing in ForceSendFields will be sent to the
  229. // server regardless of whether the field is empty or not. This may be
  230. // used to include empty fields in Patch requests.
  231. ForceSendFields []string `json:"-"`
  232. }
  233. func (s *Operation) MarshalJSON() ([]byte, error) {
  234. type noMethod Operation
  235. raw := noMethod(*s)
  236. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  237. }
  238. type OperationMetadata interface{}
  239. type OperationResponse interface{}
  240. // ScriptStackTraceElement: A stack trace through the script that shows
  241. // where the execution failed.
  242. type ScriptStackTraceElement struct {
  243. // Function: The name of the function that failed.
  244. Function string `json:"function,omitempty"`
  245. // LineNumber: The line number where the script failed.
  246. LineNumber int64 `json:"lineNumber,omitempty"`
  247. // ForceSendFields is a list of field names (e.g. "Function") to
  248. // unconditionally include in API requests. By default, fields with
  249. // empty values are omitted from API requests. However, any non-pointer,
  250. // non-interface field appearing in ForceSendFields will be sent to the
  251. // server regardless of whether the field is empty or not. This may be
  252. // used to include empty fields in Patch requests.
  253. ForceSendFields []string `json:"-"`
  254. }
  255. func (s *ScriptStackTraceElement) MarshalJSON() ([]byte, error) {
  256. type noMethod ScriptStackTraceElement
  257. raw := noMethod(*s)
  258. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  259. }
  260. // Status: If a `run` call succeeds but the script function (or Apps
  261. // Script itself) throws an exception, the response body's `error` field
  262. // will contain this `Status` object.
  263. type Status struct {
  264. // Code: The status code, which should be an enum value of
  265. // google.rpc.Code.
  266. Code int64 `json:"code,omitempty"`
  267. // Details: An array that contains a single `ExecutionError` object that
  268. // provides information about the nature of the error.
  269. Details []StatusDetails `json:"details,omitempty"`
  270. // Message: A developer-facing error message, which should be in
  271. // English. Any user-facing error message should be localized and sent
  272. // in the google.rpc.Status.details field, or localized by the client.
  273. Message string `json:"message,omitempty"`
  274. // ForceSendFields is a list of field names (e.g. "Code") to
  275. // unconditionally include in API requests. By default, fields with
  276. // empty values are omitted from API requests. However, any non-pointer,
  277. // non-interface field appearing in ForceSendFields will be sent to the
  278. // server regardless of whether the field is empty or not. This may be
  279. // used to include empty fields in Patch requests.
  280. ForceSendFields []string `json:"-"`
  281. }
  282. func (s *Status) MarshalJSON() ([]byte, error) {
  283. type noMethod Status
  284. raw := noMethod(*s)
  285. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  286. }
  287. type StatusDetails interface{}
  288. // method id "script.scripts.run":
  289. type ScriptsRunCall struct {
  290. s *Service
  291. scriptId string
  292. executionrequest *ExecutionRequest
  293. urlParams_ gensupport.URLParams
  294. ctx_ context.Context
  295. }
  296. // Run: Runs a function in an Apps Script project that has been deployed
  297. // for use with the Apps Script Execution API. This method requires
  298. // authorization with an OAuth 2.0 token that includes at least one of
  299. // the scopes listed in the [Authentication](#authentication) section;
  300. // script projects that do not require authorization cannot be executed
  301. // through this API. To find the correct scopes to include in the
  302. // authentication token, open the project in the script editor, then
  303. // select **File > Project properties** and click the **Scopes** tab.
  304. func (r *ScriptsService) Run(scriptId string, executionrequest *ExecutionRequest) *ScriptsRunCall {
  305. c := &ScriptsRunCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  306. c.scriptId = scriptId
  307. c.executionrequest = executionrequest
  308. return c
  309. }
  310. // Fields allows partial responses to be retrieved. See
  311. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  312. // for more information.
  313. func (c *ScriptsRunCall) Fields(s ...googleapi.Field) *ScriptsRunCall {
  314. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  315. return c
  316. }
  317. // Context sets the context to be used in this call's Do method. Any
  318. // pending HTTP request will be aborted if the provided context is
  319. // canceled.
  320. func (c *ScriptsRunCall) Context(ctx context.Context) *ScriptsRunCall {
  321. c.ctx_ = ctx
  322. return c
  323. }
  324. func (c *ScriptsRunCall) doRequest(alt string) (*http.Response, error) {
  325. var body io.Reader = nil
  326. body, err := googleapi.WithoutDataWrapper.JSONReader(c.executionrequest)
  327. if err != nil {
  328. return nil, err
  329. }
  330. ctype := "application/json"
  331. c.urlParams_.Set("alt", alt)
  332. urls := googleapi.ResolveRelative(c.s.BasePath, "v1/scripts/{scriptId}:run")
  333. urls += "?" + c.urlParams_.Encode()
  334. req, _ := http.NewRequest("POST", urls, body)
  335. googleapi.Expand(req.URL, map[string]string{
  336. "scriptId": c.scriptId,
  337. })
  338. req.Header.Set("Content-Type", ctype)
  339. req.Header.Set("User-Agent", c.s.userAgent())
  340. if c.ctx_ != nil {
  341. return ctxhttp.Do(c.ctx_, c.s.client, req)
  342. }
  343. return c.s.client.Do(req)
  344. }
  345. // Do executes the "script.scripts.run" call.
  346. // Exactly one of *Operation or error will be non-nil. Any non-2xx
  347. // status code is an error. Response headers are in either
  348. // *Operation.ServerResponse.Header or (if a response was returned at
  349. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  350. // to check whether the returned error was because
  351. // http.StatusNotModified was returned.
  352. func (c *ScriptsRunCall) Do(opts ...googleapi.CallOption) (*Operation, error) {
  353. gensupport.SetOptions(c.urlParams_, opts...)
  354. res, err := c.doRequest("json")
  355. if res != nil && res.StatusCode == http.StatusNotModified {
  356. if res.Body != nil {
  357. res.Body.Close()
  358. }
  359. return nil, &googleapi.Error{
  360. Code: res.StatusCode,
  361. Header: res.Header,
  362. }
  363. }
  364. if err != nil {
  365. return nil, err
  366. }
  367. defer googleapi.CloseBody(res)
  368. if err := googleapi.CheckResponse(res); err != nil {
  369. return nil, err
  370. }
  371. ret := &Operation{
  372. ServerResponse: googleapi.ServerResponse{
  373. Header: res.Header,
  374. HTTPStatusCode: res.StatusCode,
  375. },
  376. }
  377. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  378. return nil, err
  379. }
  380. return ret, nil
  381. // {
  382. // "description": "Runs a function in an Apps Script project that has been deployed for use with the Apps Script Execution API. This method requires authorization with an OAuth 2.0 token that includes at least one of the scopes listed in the [Authentication](#authentication) section; script projects that do not require authorization cannot be executed through this API. To find the correct scopes to include in the authentication token, open the project in the script editor, then select **File \u003e Project properties** and click the **Scopes** tab.",
  383. // "httpMethod": "POST",
  384. // "id": "script.scripts.run",
  385. // "parameterOrder": [
  386. // "scriptId"
  387. // ],
  388. // "parameters": {
  389. // "scriptId": {
  390. // "description": "The project key of the script to be executed. To find the project key, open the project in the script editor, then select **File \u003e Project properties**.",
  391. // "location": "path",
  392. // "required": true,
  393. // "type": "string"
  394. // }
  395. // },
  396. // "path": "v1/scripts/{scriptId}:run",
  397. // "request": {
  398. // "$ref": "ExecutionRequest"
  399. // },
  400. // "response": {
  401. // "$ref": "Operation"
  402. // },
  403. // "scopes": [
  404. // "https://mail.google.com/",
  405. // "https://www.google.com/calendar/feeds",
  406. // "https://www.google.com/m8/feeds",
  407. // "https://www.googleapis.com/auth/admin.directory.group",
  408. // "https://www.googleapis.com/auth/admin.directory.user",
  409. // "https://www.googleapis.com/auth/drive",
  410. // "https://www.googleapis.com/auth/forms",
  411. // "https://www.googleapis.com/auth/forms.currentonly",
  412. // "https://www.googleapis.com/auth/groups",
  413. // "https://www.googleapis.com/auth/userinfo.email"
  414. // ]
  415. // }
  416. }