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