drive-gen.go 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  1. // Package drive provides access to the Drive API.
  2. //
  3. // See https://developers.google.com/drive/
  4. //
  5. // Usage example:
  6. //
  7. // import "google.golang.org/api/drive/v1"
  8. // ...
  9. // driveService, err := drive.New(oauthHttpClient)
  10. package drive // import "google.golang.org/api/drive/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 = "drive:v1"
  41. const apiName = "drive"
  42. const apiVersion = "v1"
  43. const basePath = "https://www.googleapis.com/drive/v1/"
  44. // OAuth2 scopes used by this API.
  45. const (
  46. // View and manage Google Drive files and folders that you have opened
  47. // or created with this app
  48. DriveFileScope = "https://www.googleapis.com/auth/drive.file"
  49. )
  50. func New(client *http.Client) (*Service, error) {
  51. if client == nil {
  52. return nil, errors.New("client is nil")
  53. }
  54. s := &Service{client: client, BasePath: basePath}
  55. s.Files = NewFilesService(s)
  56. return s, nil
  57. }
  58. type Service struct {
  59. client *http.Client
  60. BasePath string // API endpoint base URL
  61. UserAgent string // optional additional User-Agent fragment
  62. Files *FilesService
  63. }
  64. func (s *Service) userAgent() string {
  65. if s.UserAgent == "" {
  66. return googleapi.UserAgent
  67. }
  68. return googleapi.UserAgent + " " + s.UserAgent
  69. }
  70. func NewFilesService(s *Service) *FilesService {
  71. rs := &FilesService{s: s}
  72. return rs
  73. }
  74. type FilesService struct {
  75. s *Service
  76. }
  77. // File: The metadata for a file.
  78. type File struct {
  79. // CreatedDate: Create time for this file (formatted RFC 3339
  80. // timestamp).
  81. CreatedDate string `json:"createdDate,omitempty"`
  82. // Description: A short description of the file
  83. Description string `json:"description,omitempty"`
  84. DownloadUrl string `json:"downloadUrl,omitempty"`
  85. // Etag: ETag of the file.
  86. Etag string `json:"etag,omitempty"`
  87. // FileExtension: The file extension used when downloading this file.
  88. // This field is read only. To set the extension, include it on title
  89. // when creating the file. This will only be populated on files with
  90. // content stored in Drive.
  91. FileExtension string `json:"fileExtension,omitempty"`
  92. // FileSize: The size of the file in bytes. This will only be populated
  93. // on files with content stored in Drive.
  94. FileSize int64 `json:"fileSize,omitempty,string"`
  95. // Id: The id of the file.
  96. Id string `json:"id,omitempty"`
  97. // IndexableText: Indexable text attributes for the file (can only be
  98. // written)
  99. IndexableText *FileIndexableText `json:"indexableText,omitempty"`
  100. // Kind: The type of file. This is always drive#file
  101. Kind string `json:"kind,omitempty"`
  102. // Labels: Labels for the file.
  103. Labels *FileLabels `json:"labels,omitempty"`
  104. // LastViewedDate: Last time this file was viewed by the user (formatted
  105. // RFC 3339 timestamp).
  106. LastViewedDate string `json:"lastViewedDate,omitempty"`
  107. // Md5Checksum: An MD5 checksum for the content of this file. This will
  108. // only be populated on files with content stored in Drive.
  109. Md5Checksum string `json:"md5Checksum,omitempty"`
  110. // MimeType: The mimetype of the file
  111. MimeType string `json:"mimeType,omitempty"`
  112. // ModifiedByMeDate: Last time this file was modified by the user
  113. // (formatted RFC 3339 timestamp).
  114. ModifiedByMeDate string `json:"modifiedByMeDate,omitempty"`
  115. // ModifiedDate: Last time this file was modified by anyone (formatted
  116. // RFC 3339 timestamp).
  117. ModifiedDate string `json:"modifiedDate,omitempty"`
  118. // ParentsCollection: Collection of parent folders which contain this
  119. // file.
  120. // On insert, setting this field will put the file in all of the
  121. // provided folders. If no folders are provided, the file will be placed
  122. // in the default root folder. On update, this field is ignored.
  123. ParentsCollection []*FileParentsCollection `json:"parentsCollection,omitempty"`
  124. // SelfLink: A link back to this file.
  125. SelfLink string `json:"selfLink,omitempty"`
  126. // Title: The title of this file.
  127. Title string `json:"title,omitempty"`
  128. // UserPermission: The permissions for the authenticated user on this
  129. // file.
  130. UserPermission *Permission `json:"userPermission,omitempty"`
  131. // ServerResponse contains the HTTP response code and headers from the
  132. // server.
  133. googleapi.ServerResponse `json:"-"`
  134. // ForceSendFields is a list of field names (e.g. "CreatedDate") to
  135. // unconditionally include in API requests. By default, fields with
  136. // empty values are omitted from API requests. However, any non-pointer,
  137. // non-interface field appearing in ForceSendFields will be sent to the
  138. // server regardless of whether the field is empty or not. This may be
  139. // used to include empty fields in Patch requests.
  140. ForceSendFields []string `json:"-"`
  141. }
  142. func (s *File) MarshalJSON() ([]byte, error) {
  143. type noMethod File
  144. raw := noMethod(*s)
  145. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  146. }
  147. // FileIndexableText: Indexable text attributes for the file (can only
  148. // be written)
  149. type FileIndexableText struct {
  150. // Text: The text to be indexed for this file
  151. Text string `json:"text,omitempty"`
  152. // ForceSendFields is a list of field names (e.g. "Text") to
  153. // unconditionally include in API requests. By default, fields with
  154. // empty values are omitted from API requests. However, any non-pointer,
  155. // non-interface field appearing in ForceSendFields will be sent to the
  156. // server regardless of whether the field is empty or not. This may be
  157. // used to include empty fields in Patch requests.
  158. ForceSendFields []string `json:"-"`
  159. }
  160. func (s *FileIndexableText) MarshalJSON() ([]byte, error) {
  161. type noMethod FileIndexableText
  162. raw := noMethod(*s)
  163. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  164. }
  165. // FileLabels: Labels for the file.
  166. type FileLabels struct {
  167. // Hidden: Whether this file is hidden from the user
  168. Hidden bool `json:"hidden,omitempty"`
  169. // Starred: Whether this file is starred by the user.
  170. Starred bool `json:"starred,omitempty"`
  171. // Trashed: Whether this file has been trashed.
  172. Trashed bool `json:"trashed,omitempty"`
  173. // ForceSendFields is a list of field names (e.g. "Hidden") to
  174. // unconditionally include in API requests. By default, fields with
  175. // empty values are omitted from API requests. However, any non-pointer,
  176. // non-interface field appearing in ForceSendFields will be sent to the
  177. // server regardless of whether the field is empty or not. This may be
  178. // used to include empty fields in Patch requests.
  179. ForceSendFields []string `json:"-"`
  180. }
  181. func (s *FileLabels) MarshalJSON() ([]byte, error) {
  182. type noMethod FileLabels
  183. raw := noMethod(*s)
  184. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  185. }
  186. type FileParentsCollection struct {
  187. // Id: The id of this parent
  188. Id string `json:"id,omitempty"`
  189. // ParentLink: A link to get the metadata for this parent
  190. ParentLink string `json:"parentLink,omitempty"`
  191. // ForceSendFields is a list of field names (e.g. "Id") to
  192. // unconditionally include in API requests. By default, fields with
  193. // empty values are omitted from API requests. However, any non-pointer,
  194. // non-interface field appearing in ForceSendFields will be sent to the
  195. // server regardless of whether the field is empty or not. This may be
  196. // used to include empty fields in Patch requests.
  197. ForceSendFields []string `json:"-"`
  198. }
  199. func (s *FileParentsCollection) MarshalJSON() ([]byte, error) {
  200. type noMethod FileParentsCollection
  201. raw := noMethod(*s)
  202. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  203. }
  204. // Permission: A single permission for a file.
  205. type Permission struct {
  206. // AdditionalRoles: Any additional roles that this permission describes.
  207. AdditionalRoles []string `json:"additionalRoles,omitempty"`
  208. // Etag: An etag for this permission.
  209. Etag string `json:"etag,omitempty"`
  210. // Kind: The kind of this permission. This is always drive#permission
  211. Kind string `json:"kind,omitempty"`
  212. // Role: The role that this permission describes. (For example: reader,
  213. // writer, owner)
  214. Role string `json:"role,omitempty"`
  215. // Type: The type of permission (For example: user, group etc).
  216. Type string `json:"type,omitempty"`
  217. // ForceSendFields is a list of field names (e.g. "AdditionalRoles") to
  218. // unconditionally include in API requests. By default, fields with
  219. // empty values are omitted from API requests. However, any non-pointer,
  220. // non-interface field appearing in ForceSendFields will be sent to the
  221. // server regardless of whether the field is empty or not. This may be
  222. // used to include empty fields in Patch requests.
  223. ForceSendFields []string `json:"-"`
  224. }
  225. func (s *Permission) MarshalJSON() ([]byte, error) {
  226. type noMethod Permission
  227. raw := noMethod(*s)
  228. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  229. }
  230. // method id "drive.files.get":
  231. type FilesGetCall struct {
  232. s *Service
  233. id string
  234. urlParams_ gensupport.URLParams
  235. ifNoneMatch_ string
  236. ctx_ context.Context
  237. }
  238. // Get: Gets a file's metadata by id.
  239. func (r *FilesService) Get(id string) *FilesGetCall {
  240. c := &FilesGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  241. c.id = id
  242. return c
  243. }
  244. // Projection sets the optional parameter "projection": This parameter
  245. // is deprecated and has no function.
  246. //
  247. // Possible values:
  248. // "BASIC" - Deprecated
  249. // "FULL" - Deprecated
  250. func (c *FilesGetCall) Projection(projection string) *FilesGetCall {
  251. c.urlParams_.Set("projection", projection)
  252. return c
  253. }
  254. // UpdateViewedDate sets the optional parameter "updateViewedDate":
  255. // Whether to update the view date after successfully retrieving the
  256. // file.
  257. func (c *FilesGetCall) UpdateViewedDate(updateViewedDate bool) *FilesGetCall {
  258. c.urlParams_.Set("updateViewedDate", fmt.Sprint(updateViewedDate))
  259. return c
  260. }
  261. // Fields allows partial responses to be retrieved. See
  262. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  263. // for more information.
  264. func (c *FilesGetCall) Fields(s ...googleapi.Field) *FilesGetCall {
  265. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  266. return c
  267. }
  268. // IfNoneMatch sets the optional parameter which makes the operation
  269. // fail if the object's ETag matches the given value. This is useful for
  270. // getting updates only after the object has changed since the last
  271. // request. Use googleapi.IsNotModified to check whether the response
  272. // error from Do is the result of In-None-Match.
  273. func (c *FilesGetCall) IfNoneMatch(entityTag string) *FilesGetCall {
  274. c.ifNoneMatch_ = entityTag
  275. return c
  276. }
  277. // Context sets the context to be used in this call's Do method. Any
  278. // pending HTTP request will be aborted if the provided context is
  279. // canceled.
  280. func (c *FilesGetCall) Context(ctx context.Context) *FilesGetCall {
  281. c.ctx_ = ctx
  282. return c
  283. }
  284. func (c *FilesGetCall) doRequest(alt string) (*http.Response, error) {
  285. var body io.Reader = nil
  286. c.urlParams_.Set("alt", alt)
  287. urls := googleapi.ResolveRelative(c.s.BasePath, "files/{id}")
  288. urls += "?" + c.urlParams_.Encode()
  289. req, _ := http.NewRequest("GET", urls, body)
  290. googleapi.Expand(req.URL, map[string]string{
  291. "id": c.id,
  292. })
  293. req.Header.Set("User-Agent", c.s.userAgent())
  294. if c.ifNoneMatch_ != "" {
  295. req.Header.Set("If-None-Match", c.ifNoneMatch_)
  296. }
  297. if c.ctx_ != nil {
  298. return ctxhttp.Do(c.ctx_, c.s.client, req)
  299. }
  300. return c.s.client.Do(req)
  301. }
  302. // Do executes the "drive.files.get" call.
  303. // Exactly one of *File or error will be non-nil. Any non-2xx status
  304. // code is an error. Response headers are in either
  305. // *File.ServerResponse.Header or (if a response was returned at all) in
  306. // error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check
  307. // whether the returned error was because http.StatusNotModified was
  308. // returned.
  309. func (c *FilesGetCall) Do(opts ...googleapi.CallOption) (*File, error) {
  310. gensupport.SetOptions(c.urlParams_, opts...)
  311. res, err := c.doRequest("json")
  312. if res != nil && res.StatusCode == http.StatusNotModified {
  313. if res.Body != nil {
  314. res.Body.Close()
  315. }
  316. return nil, &googleapi.Error{
  317. Code: res.StatusCode,
  318. Header: res.Header,
  319. }
  320. }
  321. if err != nil {
  322. return nil, err
  323. }
  324. defer googleapi.CloseBody(res)
  325. if err := googleapi.CheckResponse(res); err != nil {
  326. return nil, err
  327. }
  328. ret := &File{
  329. ServerResponse: googleapi.ServerResponse{
  330. Header: res.Header,
  331. HTTPStatusCode: res.StatusCode,
  332. },
  333. }
  334. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  335. return nil, err
  336. }
  337. return ret, nil
  338. // {
  339. // "description": "Gets a file's metadata by id.",
  340. // "httpMethod": "GET",
  341. // "id": "drive.files.get",
  342. // "parameterOrder": [
  343. // "id"
  344. // ],
  345. // "parameters": {
  346. // "id": {
  347. // "description": "The id for the file in question.",
  348. // "location": "path",
  349. // "required": true,
  350. // "type": "string"
  351. // },
  352. // "projection": {
  353. // "description": "This parameter is deprecated and has no function.",
  354. // "enum": [
  355. // "BASIC",
  356. // "FULL"
  357. // ],
  358. // "enumDescriptions": [
  359. // "Deprecated",
  360. // "Deprecated"
  361. // ],
  362. // "location": "query",
  363. // "type": "string"
  364. // },
  365. // "updateViewedDate": {
  366. // "default": "true",
  367. // "description": "Whether to update the view date after successfully retrieving the file.",
  368. // "location": "query",
  369. // "type": "boolean"
  370. // }
  371. // },
  372. // "path": "files/{id}",
  373. // "response": {
  374. // "$ref": "File"
  375. // },
  376. // "scopes": [
  377. // "https://www.googleapis.com/auth/drive.file"
  378. // ]
  379. // }
  380. }
  381. // method id "drive.files.insert":
  382. type FilesInsertCall struct {
  383. s *Service
  384. file *File
  385. urlParams_ gensupport.URLParams
  386. media_ io.Reader
  387. resumableBuffer_ *gensupport.ResumableBuffer
  388. mediaType_ string
  389. mediaSize_ int64 // mediaSize, if known. Used only for calls to progressUpdater_.
  390. progressUpdater_ googleapi.ProgressUpdater
  391. ctx_ context.Context
  392. }
  393. // Insert: Inserts a file, and any settable metadata or blob content
  394. // sent with the request.
  395. func (r *FilesService) Insert(file *File) *FilesInsertCall {
  396. c := &FilesInsertCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  397. c.file = file
  398. return c
  399. }
  400. // Media specifies the media to upload in one or more chunks. The chunk
  401. // size may be controlled by supplying a MediaOption generated by
  402. // googleapi.ChunkSize. The chunk size defaults to
  403. // googleapi.DefaultUploadChunkSize.
  404. // At most one of Media and ResumableMedia may be set.
  405. func (c *FilesInsertCall) Media(r io.Reader, options ...googleapi.MediaOption) *FilesInsertCall {
  406. opts := googleapi.ProcessMediaOptions(options)
  407. chunkSize := opts.ChunkSize
  408. r, c.mediaType_ = gensupport.DetermineContentType(r, opts.ContentType)
  409. c.media_, c.resumableBuffer_ = gensupport.PrepareUpload(r, chunkSize)
  410. return c
  411. }
  412. // ResumableMedia specifies the media to upload in chunks and can be
  413. // canceled with ctx.
  414. //
  415. // Deprecated: use Media instead.
  416. //
  417. // At most one of Media and ResumableMedia may be set. mediaType
  418. // identifies the MIME media type of the upload, such as "image/png". If
  419. // mediaType is "", it will be auto-detected. The provided ctx will
  420. // supersede any context previously provided to the Context method.
  421. func (c *FilesInsertCall) ResumableMedia(ctx context.Context, r io.ReaderAt, size int64, mediaType string) *FilesInsertCall {
  422. c.ctx_ = ctx
  423. rdr := gensupport.ReaderAtToReader(r, size)
  424. rdr, c.mediaType_ = gensupport.DetermineContentType(rdr, mediaType)
  425. c.resumableBuffer_ = gensupport.NewResumableBuffer(rdr, googleapi.DefaultUploadChunkSize)
  426. c.media_ = nil
  427. c.mediaSize_ = size
  428. return c
  429. }
  430. // ProgressUpdater provides a callback function that will be called
  431. // after every chunk. It should be a low-latency function in order to
  432. // not slow down the upload operation. This should only be called when
  433. // using ResumableMedia (as opposed to Media).
  434. func (c *FilesInsertCall) ProgressUpdater(pu googleapi.ProgressUpdater) *FilesInsertCall {
  435. c.progressUpdater_ = pu
  436. return c
  437. }
  438. // Fields allows partial responses to be retrieved. See
  439. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  440. // for more information.
  441. func (c *FilesInsertCall) Fields(s ...googleapi.Field) *FilesInsertCall {
  442. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  443. return c
  444. }
  445. // Context sets the context to be used in this call's Do method. Any
  446. // pending HTTP request will be aborted if the provided context is
  447. // canceled.
  448. // This context will supersede any context previously provided to the
  449. // ResumableMedia method.
  450. func (c *FilesInsertCall) Context(ctx context.Context) *FilesInsertCall {
  451. c.ctx_ = ctx
  452. return c
  453. }
  454. func (c *FilesInsertCall) doRequest(alt string) (*http.Response, error) {
  455. var body io.Reader = nil
  456. body, err := googleapi.WithoutDataWrapper.JSONReader(c.file)
  457. if err != nil {
  458. return nil, err
  459. }
  460. ctype := "application/json"
  461. c.urlParams_.Set("alt", alt)
  462. urls := googleapi.ResolveRelative(c.s.BasePath, "files")
  463. if c.media_ != nil || c.resumableBuffer_ != nil {
  464. urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
  465. protocol := "multipart"
  466. if c.resumableBuffer_ != nil {
  467. protocol = "resumable"
  468. }
  469. c.urlParams_.Set("uploadType", protocol)
  470. }
  471. urls += "?" + c.urlParams_.Encode()
  472. if c.media_ != nil {
  473. var combined io.ReadCloser
  474. combined, ctype = gensupport.CombineBodyMedia(body, ctype, c.media_, c.mediaType_)
  475. defer combined.Close()
  476. body = combined
  477. }
  478. req, _ := http.NewRequest("POST", urls, body)
  479. googleapi.SetOpaque(req.URL)
  480. if c.resumableBuffer_ != nil {
  481. req.Header.Set("X-Upload-Content-Type", c.mediaType_)
  482. }
  483. req.Header.Set("Content-Type", ctype)
  484. req.Header.Set("User-Agent", c.s.userAgent())
  485. if c.ctx_ != nil {
  486. return ctxhttp.Do(c.ctx_, c.s.client, req)
  487. }
  488. return c.s.client.Do(req)
  489. }
  490. // Do executes the "drive.files.insert" call.
  491. // Exactly one of *File or error will be non-nil. Any non-2xx status
  492. // code is an error. Response headers are in either
  493. // *File.ServerResponse.Header or (if a response was returned at all) in
  494. // error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check
  495. // whether the returned error was because http.StatusNotModified was
  496. // returned.
  497. func (c *FilesInsertCall) Do(opts ...googleapi.CallOption) (*File, error) {
  498. gensupport.SetOptions(c.urlParams_, opts...)
  499. res, err := gensupport.Retry(c.ctx_, func() (*http.Response, error) {
  500. return c.doRequest("json")
  501. }, gensupport.DefaultBackoffStrategy())
  502. if res != nil && res.StatusCode == http.StatusNotModified {
  503. if res.Body != nil {
  504. res.Body.Close()
  505. }
  506. return nil, &googleapi.Error{
  507. Code: res.StatusCode,
  508. Header: res.Header,
  509. }
  510. }
  511. if err != nil {
  512. return nil, err
  513. }
  514. defer googleapi.CloseBody(res)
  515. if err := googleapi.CheckResponse(res); err != nil {
  516. return nil, err
  517. }
  518. if c.resumableBuffer_ != nil {
  519. loc := res.Header.Get("Location")
  520. rx := &gensupport.ResumableUpload{
  521. Client: c.s.client,
  522. UserAgent: c.s.userAgent(),
  523. URI: loc,
  524. Media: c.resumableBuffer_,
  525. MediaType: c.mediaType_,
  526. Callback: func(curr int64) {
  527. if c.progressUpdater_ != nil {
  528. c.progressUpdater_(curr, c.mediaSize_)
  529. }
  530. },
  531. }
  532. ctx := c.ctx_
  533. if ctx == nil {
  534. ctx = context.TODO()
  535. }
  536. res, err = rx.Upload(ctx)
  537. if err != nil {
  538. return nil, err
  539. }
  540. defer res.Body.Close()
  541. if err := googleapi.CheckResponse(res); err != nil {
  542. return nil, err
  543. }
  544. }
  545. ret := &File{
  546. ServerResponse: googleapi.ServerResponse{
  547. Header: res.Header,
  548. HTTPStatusCode: res.StatusCode,
  549. },
  550. }
  551. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  552. return nil, err
  553. }
  554. return ret, nil
  555. // {
  556. // "description": "Inserts a file, and any settable metadata or blob content sent with the request.",
  557. // "httpMethod": "POST",
  558. // "id": "drive.files.insert",
  559. // "mediaUpload": {
  560. // "accept": [
  561. // "*/*"
  562. // ],
  563. // "maxSize": "5120GB",
  564. // "protocols": {
  565. // "resumable": {
  566. // "multipart": true,
  567. // "path": "/resumable/upload/drive/v1/files"
  568. // },
  569. // "simple": {
  570. // "multipart": true,
  571. // "path": "/upload/drive/v1/files"
  572. // }
  573. // }
  574. // },
  575. // "path": "files",
  576. // "request": {
  577. // "$ref": "File"
  578. // },
  579. // "response": {
  580. // "$ref": "File"
  581. // },
  582. // "scopes": [
  583. // "https://www.googleapis.com/auth/drive.file"
  584. // ],
  585. // "supportsMediaUpload": true
  586. // }
  587. }
  588. // method id "drive.files.patch":
  589. type FilesPatchCall struct {
  590. s *Service
  591. id string
  592. file *File
  593. urlParams_ gensupport.URLParams
  594. ctx_ context.Context
  595. }
  596. // Patch: Updates file metadata and/or content. This method supports
  597. // patch semantics.
  598. func (r *FilesService) Patch(id string, file *File) *FilesPatchCall {
  599. c := &FilesPatchCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  600. c.id = id
  601. c.file = file
  602. return c
  603. }
  604. // NewRevision sets the optional parameter "newRevision": Whether a blob
  605. // upload should create a new revision. If false, the blob data in the
  606. // current head revision is replaced. If true or not set, a new blob is
  607. // created as head revision, and previous unpinned revisions are
  608. // preserved for a short period of time. Pinned revisions are stored
  609. // indefinitely, using additional storage quota, up to a maximum of 200
  610. // revisions.
  611. func (c *FilesPatchCall) NewRevision(newRevision bool) *FilesPatchCall {
  612. c.urlParams_.Set("newRevision", fmt.Sprint(newRevision))
  613. return c
  614. }
  615. // UpdateModifiedDate sets the optional parameter "updateModifiedDate":
  616. // Controls updating the modified date of the file. If true, the
  617. // modified date will be updated to the current time, regardless of
  618. // whether other changes are being made. If false, the modified date
  619. // will only be updated to the current time if other changes are also
  620. // being made (changing the title, for example).
  621. func (c *FilesPatchCall) UpdateModifiedDate(updateModifiedDate bool) *FilesPatchCall {
  622. c.urlParams_.Set("updateModifiedDate", fmt.Sprint(updateModifiedDate))
  623. return c
  624. }
  625. // UpdateViewedDate sets the optional parameter "updateViewedDate":
  626. // Whether to update the view date after successfully updating the file.
  627. func (c *FilesPatchCall) UpdateViewedDate(updateViewedDate bool) *FilesPatchCall {
  628. c.urlParams_.Set("updateViewedDate", fmt.Sprint(updateViewedDate))
  629. return c
  630. }
  631. // Fields allows partial responses to be retrieved. See
  632. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  633. // for more information.
  634. func (c *FilesPatchCall) Fields(s ...googleapi.Field) *FilesPatchCall {
  635. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  636. return c
  637. }
  638. // Context sets the context to be used in this call's Do method. Any
  639. // pending HTTP request will be aborted if the provided context is
  640. // canceled.
  641. func (c *FilesPatchCall) Context(ctx context.Context) *FilesPatchCall {
  642. c.ctx_ = ctx
  643. return c
  644. }
  645. func (c *FilesPatchCall) doRequest(alt string) (*http.Response, error) {
  646. var body io.Reader = nil
  647. body, err := googleapi.WithoutDataWrapper.JSONReader(c.file)
  648. if err != nil {
  649. return nil, err
  650. }
  651. ctype := "application/json"
  652. c.urlParams_.Set("alt", alt)
  653. urls := googleapi.ResolveRelative(c.s.BasePath, "files/{id}")
  654. urls += "?" + c.urlParams_.Encode()
  655. req, _ := http.NewRequest("PATCH", urls, body)
  656. googleapi.Expand(req.URL, map[string]string{
  657. "id": c.id,
  658. })
  659. req.Header.Set("Content-Type", ctype)
  660. req.Header.Set("User-Agent", c.s.userAgent())
  661. if c.ctx_ != nil {
  662. return ctxhttp.Do(c.ctx_, c.s.client, req)
  663. }
  664. return c.s.client.Do(req)
  665. }
  666. // Do executes the "drive.files.patch" call.
  667. // Exactly one of *File or error will be non-nil. Any non-2xx status
  668. // code is an error. Response headers are in either
  669. // *File.ServerResponse.Header or (if a response was returned at all) in
  670. // error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check
  671. // whether the returned error was because http.StatusNotModified was
  672. // returned.
  673. func (c *FilesPatchCall) Do(opts ...googleapi.CallOption) (*File, error) {
  674. gensupport.SetOptions(c.urlParams_, opts...)
  675. res, err := c.doRequest("json")
  676. if res != nil && res.StatusCode == http.StatusNotModified {
  677. if res.Body != nil {
  678. res.Body.Close()
  679. }
  680. return nil, &googleapi.Error{
  681. Code: res.StatusCode,
  682. Header: res.Header,
  683. }
  684. }
  685. if err != nil {
  686. return nil, err
  687. }
  688. defer googleapi.CloseBody(res)
  689. if err := googleapi.CheckResponse(res); err != nil {
  690. return nil, err
  691. }
  692. ret := &File{
  693. ServerResponse: googleapi.ServerResponse{
  694. Header: res.Header,
  695. HTTPStatusCode: res.StatusCode,
  696. },
  697. }
  698. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  699. return nil, err
  700. }
  701. return ret, nil
  702. // {
  703. // "description": "Updates file metadata and/or content. This method supports patch semantics.",
  704. // "httpMethod": "PATCH",
  705. // "id": "drive.files.patch",
  706. // "parameterOrder": [
  707. // "id"
  708. // ],
  709. // "parameters": {
  710. // "id": {
  711. // "description": "The id for the file in question.",
  712. // "location": "path",
  713. // "required": true,
  714. // "type": "string"
  715. // },
  716. // "newRevision": {
  717. // "default": "true",
  718. // "description": "Whether a blob upload should create a new revision. If false, the blob data in the current head revision is replaced. If true or not set, a new blob is created as head revision, and previous unpinned revisions are preserved for a short period of time. Pinned revisions are stored indefinitely, using additional storage quota, up to a maximum of 200 revisions.",
  719. // "location": "query",
  720. // "type": "boolean"
  721. // },
  722. // "updateModifiedDate": {
  723. // "default": "false",
  724. // "description": "Controls updating the modified date of the file. If true, the modified date will be updated to the current time, regardless of whether other changes are being made. If false, the modified date will only be updated to the current time if other changes are also being made (changing the title, for example).",
  725. // "location": "query",
  726. // "type": "boolean"
  727. // },
  728. // "updateViewedDate": {
  729. // "default": "true",
  730. // "description": "Whether to update the view date after successfully updating the file.",
  731. // "location": "query",
  732. // "type": "boolean"
  733. // }
  734. // },
  735. // "path": "files/{id}",
  736. // "request": {
  737. // "$ref": "File"
  738. // },
  739. // "response": {
  740. // "$ref": "File"
  741. // },
  742. // "scopes": [
  743. // "https://www.googleapis.com/auth/drive.file"
  744. // ]
  745. // }
  746. }
  747. // method id "drive.files.update":
  748. type FilesUpdateCall struct {
  749. s *Service
  750. id string
  751. file *File
  752. urlParams_ gensupport.URLParams
  753. media_ io.Reader
  754. resumableBuffer_ *gensupport.ResumableBuffer
  755. mediaType_ string
  756. mediaSize_ int64 // mediaSize, if known. Used only for calls to progressUpdater_.
  757. progressUpdater_ googleapi.ProgressUpdater
  758. ctx_ context.Context
  759. }
  760. // Update: Updates file metadata and/or content
  761. func (r *FilesService) Update(id string, file *File) *FilesUpdateCall {
  762. c := &FilesUpdateCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  763. c.id = id
  764. c.file = file
  765. return c
  766. }
  767. // NewRevision sets the optional parameter "newRevision": Whether a blob
  768. // upload should create a new revision. If false, the blob data in the
  769. // current head revision is replaced. If true or not set, a new blob is
  770. // created as head revision, and previous unpinned revisions are
  771. // preserved for a short period of time. Pinned revisions are stored
  772. // indefinitely, using additional storage quota, up to a maximum of 200
  773. // revisions.
  774. func (c *FilesUpdateCall) NewRevision(newRevision bool) *FilesUpdateCall {
  775. c.urlParams_.Set("newRevision", fmt.Sprint(newRevision))
  776. return c
  777. }
  778. // UpdateModifiedDate sets the optional parameter "updateModifiedDate":
  779. // Controls updating the modified date of the file. If true, the
  780. // modified date will be updated to the current time, regardless of
  781. // whether other changes are being made. If false, the modified date
  782. // will only be updated to the current time if other changes are also
  783. // being made (changing the title, for example).
  784. func (c *FilesUpdateCall) UpdateModifiedDate(updateModifiedDate bool) *FilesUpdateCall {
  785. c.urlParams_.Set("updateModifiedDate", fmt.Sprint(updateModifiedDate))
  786. return c
  787. }
  788. // UpdateViewedDate sets the optional parameter "updateViewedDate":
  789. // Whether to update the view date after successfully updating the file.
  790. func (c *FilesUpdateCall) UpdateViewedDate(updateViewedDate bool) *FilesUpdateCall {
  791. c.urlParams_.Set("updateViewedDate", fmt.Sprint(updateViewedDate))
  792. return c
  793. }
  794. // Media specifies the media to upload in one or more chunks. The chunk
  795. // size may be controlled by supplying a MediaOption generated by
  796. // googleapi.ChunkSize. The chunk size defaults to
  797. // googleapi.DefaultUploadChunkSize.
  798. // At most one of Media and ResumableMedia may be set.
  799. func (c *FilesUpdateCall) Media(r io.Reader, options ...googleapi.MediaOption) *FilesUpdateCall {
  800. opts := googleapi.ProcessMediaOptions(options)
  801. chunkSize := opts.ChunkSize
  802. r, c.mediaType_ = gensupport.DetermineContentType(r, opts.ContentType)
  803. c.media_, c.resumableBuffer_ = gensupport.PrepareUpload(r, chunkSize)
  804. return c
  805. }
  806. // ResumableMedia specifies the media to upload in chunks and can be
  807. // canceled with ctx.
  808. //
  809. // Deprecated: use Media instead.
  810. //
  811. // At most one of Media and ResumableMedia may be set. mediaType
  812. // identifies the MIME media type of the upload, such as "image/png". If
  813. // mediaType is "", it will be auto-detected. The provided ctx will
  814. // supersede any context previously provided to the Context method.
  815. func (c *FilesUpdateCall) ResumableMedia(ctx context.Context, r io.ReaderAt, size int64, mediaType string) *FilesUpdateCall {
  816. c.ctx_ = ctx
  817. rdr := gensupport.ReaderAtToReader(r, size)
  818. rdr, c.mediaType_ = gensupport.DetermineContentType(rdr, mediaType)
  819. c.resumableBuffer_ = gensupport.NewResumableBuffer(rdr, googleapi.DefaultUploadChunkSize)
  820. c.media_ = nil
  821. c.mediaSize_ = size
  822. return c
  823. }
  824. // ProgressUpdater provides a callback function that will be called
  825. // after every chunk. It should be a low-latency function in order to
  826. // not slow down the upload operation. This should only be called when
  827. // using ResumableMedia (as opposed to Media).
  828. func (c *FilesUpdateCall) ProgressUpdater(pu googleapi.ProgressUpdater) *FilesUpdateCall {
  829. c.progressUpdater_ = pu
  830. return c
  831. }
  832. // Fields allows partial responses to be retrieved. See
  833. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  834. // for more information.
  835. func (c *FilesUpdateCall) Fields(s ...googleapi.Field) *FilesUpdateCall {
  836. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  837. return c
  838. }
  839. // Context sets the context to be used in this call's Do method. Any
  840. // pending HTTP request will be aborted if the provided context is
  841. // canceled.
  842. // This context will supersede any context previously provided to the
  843. // ResumableMedia method.
  844. func (c *FilesUpdateCall) Context(ctx context.Context) *FilesUpdateCall {
  845. c.ctx_ = ctx
  846. return c
  847. }
  848. func (c *FilesUpdateCall) doRequest(alt string) (*http.Response, error) {
  849. var body io.Reader = nil
  850. body, err := googleapi.WithoutDataWrapper.JSONReader(c.file)
  851. if err != nil {
  852. return nil, err
  853. }
  854. ctype := "application/json"
  855. c.urlParams_.Set("alt", alt)
  856. urls := googleapi.ResolveRelative(c.s.BasePath, "files/{id}")
  857. if c.media_ != nil || c.resumableBuffer_ != nil {
  858. urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
  859. protocol := "multipart"
  860. if c.resumableBuffer_ != nil {
  861. protocol = "resumable"
  862. }
  863. c.urlParams_.Set("uploadType", protocol)
  864. }
  865. urls += "?" + c.urlParams_.Encode()
  866. if c.media_ != nil {
  867. var combined io.ReadCloser
  868. combined, ctype = gensupport.CombineBodyMedia(body, ctype, c.media_, c.mediaType_)
  869. defer combined.Close()
  870. body = combined
  871. }
  872. req, _ := http.NewRequest("PUT", urls, body)
  873. googleapi.Expand(req.URL, map[string]string{
  874. "id": c.id,
  875. })
  876. if c.resumableBuffer_ != nil {
  877. req.Header.Set("X-Upload-Content-Type", c.mediaType_)
  878. }
  879. req.Header.Set("Content-Type", ctype)
  880. req.Header.Set("User-Agent", c.s.userAgent())
  881. if c.ctx_ != nil {
  882. return ctxhttp.Do(c.ctx_, c.s.client, req)
  883. }
  884. return c.s.client.Do(req)
  885. }
  886. // Do executes the "drive.files.update" call.
  887. // Exactly one of *File or error will be non-nil. Any non-2xx status
  888. // code is an error. Response headers are in either
  889. // *File.ServerResponse.Header or (if a response was returned at all) in
  890. // error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check
  891. // whether the returned error was because http.StatusNotModified was
  892. // returned.
  893. func (c *FilesUpdateCall) Do(opts ...googleapi.CallOption) (*File, error) {
  894. gensupport.SetOptions(c.urlParams_, opts...)
  895. res, err := gensupport.Retry(c.ctx_, func() (*http.Response, error) {
  896. return c.doRequest("json")
  897. }, gensupport.DefaultBackoffStrategy())
  898. if res != nil && res.StatusCode == http.StatusNotModified {
  899. if res.Body != nil {
  900. res.Body.Close()
  901. }
  902. return nil, &googleapi.Error{
  903. Code: res.StatusCode,
  904. Header: res.Header,
  905. }
  906. }
  907. if err != nil {
  908. return nil, err
  909. }
  910. defer googleapi.CloseBody(res)
  911. if err := googleapi.CheckResponse(res); err != nil {
  912. return nil, err
  913. }
  914. if c.resumableBuffer_ != nil {
  915. loc := res.Header.Get("Location")
  916. rx := &gensupport.ResumableUpload{
  917. Client: c.s.client,
  918. UserAgent: c.s.userAgent(),
  919. URI: loc,
  920. Media: c.resumableBuffer_,
  921. MediaType: c.mediaType_,
  922. Callback: func(curr int64) {
  923. if c.progressUpdater_ != nil {
  924. c.progressUpdater_(curr, c.mediaSize_)
  925. }
  926. },
  927. }
  928. ctx := c.ctx_
  929. if ctx == nil {
  930. ctx = context.TODO()
  931. }
  932. res, err = rx.Upload(ctx)
  933. if err != nil {
  934. return nil, err
  935. }
  936. defer res.Body.Close()
  937. if err := googleapi.CheckResponse(res); err != nil {
  938. return nil, err
  939. }
  940. }
  941. ret := &File{
  942. ServerResponse: googleapi.ServerResponse{
  943. Header: res.Header,
  944. HTTPStatusCode: res.StatusCode,
  945. },
  946. }
  947. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  948. return nil, err
  949. }
  950. return ret, nil
  951. // {
  952. // "description": "Updates file metadata and/or content",
  953. // "httpMethod": "PUT",
  954. // "id": "drive.files.update",
  955. // "mediaUpload": {
  956. // "accept": [
  957. // "*/*"
  958. // ],
  959. // "maxSize": "5120GB",
  960. // "protocols": {
  961. // "resumable": {
  962. // "multipart": true,
  963. // "path": "/resumable/upload/drive/v1/files/{id}"
  964. // },
  965. // "simple": {
  966. // "multipart": true,
  967. // "path": "/upload/drive/v1/files/{id}"
  968. // }
  969. // }
  970. // },
  971. // "parameterOrder": [
  972. // "id"
  973. // ],
  974. // "parameters": {
  975. // "id": {
  976. // "description": "The id for the file in question.",
  977. // "location": "path",
  978. // "required": true,
  979. // "type": "string"
  980. // },
  981. // "newRevision": {
  982. // "default": "true",
  983. // "description": "Whether a blob upload should create a new revision. If false, the blob data in the current head revision is replaced. If true or not set, a new blob is created as head revision, and previous unpinned revisions are preserved for a short period of time. Pinned revisions are stored indefinitely, using additional storage quota, up to a maximum of 200 revisions.",
  984. // "location": "query",
  985. // "type": "boolean"
  986. // },
  987. // "updateModifiedDate": {
  988. // "default": "false",
  989. // "description": "Controls updating the modified date of the file. If true, the modified date will be updated to the current time, regardless of whether other changes are being made. If false, the modified date will only be updated to the current time if other changes are also being made (changing the title, for example).",
  990. // "location": "query",
  991. // "type": "boolean"
  992. // },
  993. // "updateViewedDate": {
  994. // "default": "true",
  995. // "description": "Whether to update the view date after successfully updating the file.",
  996. // "location": "query",
  997. // "type": "boolean"
  998. // }
  999. // },
  1000. // "path": "files/{id}",
  1001. // "request": {
  1002. // "$ref": "File"
  1003. // },
  1004. // "response": {
  1005. // "$ref": "File"
  1006. // },
  1007. // "scopes": [
  1008. // "https://www.googleapis.com/auth/drive.file"
  1009. // ],
  1010. // "supportsMediaUpload": true
  1011. // }
  1012. }