drive_api_url_generator.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // Copyright (c) 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef GOOGLE_APIS_DRIVE_DRIVE_API_URL_GENERATOR_H_
  5. #define GOOGLE_APIS_DRIVE_DRIVE_API_URL_GENERATOR_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include "url/gurl.h"
  9. namespace google_apis {
  10. // This enum class is used to express a corpora parameter configuration for
  11. // Files:list.
  12. enum class FilesListCorpora {
  13. // 'default': The user's subscribed items.
  14. DEFAULT,
  15. // 'teamDrives': A Team Drive.
  16. TEAM_DRIVE,
  17. // 'default,allTeamDrives': All Team Drives and the user's subscribed items.
  18. ALL_TEAM_DRIVES
  19. };
  20. // This class is used to generate URLs for communicating with drive api
  21. // servers for production, and a local server for testing.
  22. class DriveApiUrlGenerator {
  23. public:
  24. // |base_url| is the path to the target drive api server.
  25. // Note that this is an injecting point for a testing server.
  26. DriveApiUrlGenerator(const GURL& base_url, const GURL& base_thumbnail_url);
  27. DriveApiUrlGenerator(const DriveApiUrlGenerator& src);
  28. ~DriveApiUrlGenerator();
  29. // The base URL for the thumbnail download server for production.
  30. static const char kBaseThumbnailUrlForProduction[];
  31. // Returns a URL to invoke "About: get" method.
  32. GURL GetAboutGetUrl() const;
  33. // Returns a URL to fetch a file metadata.
  34. GURL GetFilesGetUrl(const std::string& file_id,
  35. const GURL& embed_origin) const;
  36. // Returns a URL to create a resource.
  37. GURL GetFilesInsertUrl(const std::string& visibility) const;
  38. // Returns a URL to patch file metadata.
  39. GURL GetFilesPatchUrl(const std::string& file_id,
  40. bool set_modified_date,
  41. bool update_viewed_date) const;
  42. // Returns a URL to copy a resource specified by |file_id|.
  43. GURL GetFilesCopyUrl(const std::string& file_id,
  44. const std::string& visibility) const;
  45. // Returns a URL to fetch file list.
  46. GURL GetFilesListUrl(int max_results,
  47. const std::string& page_token,
  48. FilesListCorpora corpora,
  49. const std::string& team_drive_id,
  50. const std::string& q) const;
  51. // Returns a URL to delete a resource with the given |file_id|.
  52. GURL GetFilesDeleteUrl(const std::string& file_id) const;
  53. // Returns a URL to trash a resource with the given |file_id|.
  54. GURL GetFilesTrashUrl(const std::string& file_id) const;
  55. // Returns a URL to invoke "TeamDrives: list" method.
  56. GURL GetTeamDriveListUrl(int max_results,
  57. const std::string& page_token) const;
  58. // Returns a URL to fetch a list of changes.
  59. GURL GetChangesListUrl(bool include_deleted,
  60. int max_results,
  61. const std::string& page_token,
  62. int64_t start_change_id,
  63. const std::string& team_dirve_id) const;
  64. // Returns a URL to add a resource to a directory with |folder_id|.
  65. GURL GetChildrenInsertUrl(const std::string& folder_id) const;
  66. // Returns a URL to remove a resource with |child_id| from a directory
  67. // with |folder_id|.
  68. GURL GetChildrenDeleteUrl(const std::string& child_id,
  69. const std::string& folder_id) const;
  70. // Returns a URL to initiate "resumable upload" of a new file that uploads
  71. // chunked data by multiple HTTP posts.
  72. GURL GetInitiateUploadNewFileUrl(bool set_modified_date) const;
  73. // Returns a URL to initiate "resumable upload" of an existing file specified
  74. // by |resource_id| that uploads chunked data by multiple HTTP posts.
  75. GURL GetInitiateUploadExistingFileUrl(const std::string& resource_id,
  76. bool set_modified_date) const;
  77. // Returns a URL for "multipart upload" of a new file that sends both metadata
  78. // and file content in a single HTTP post.
  79. GURL GetMultipartUploadNewFileUrl(bool set_modified_date) const;
  80. // Returns a URL for "multipart upload" of an existing file specified by
  81. // |resource_id| that sends both metadata and file content in a single HTTP
  82. // post.
  83. GURL GetMultipartUploadExistingFileUrl(const std::string& resource_id,
  84. bool set_modified_date) const;
  85. // Generates a URL for downloading a file.
  86. GURL GenerateDownloadFileUrl(const std::string& resource_id) const;
  87. // Generates a URL for adding permissions.
  88. GURL GetPermissionsInsertUrl(const std::string& resource_id) const;
  89. // Generates a URL for a thumbnail with specified dimensions. Set |crop| to
  90. // true to get a cropped thumbnail in the dimensions.
  91. GURL GetThumbnailUrl(const std::string& resource_id,
  92. int width,
  93. int height,
  94. bool crop) const;
  95. // Generates a URL for batch upload.
  96. GURL GetBatchUploadUrl() const;
  97. // Returns a URL for the start page token for a |team_drive|. |team_drive|
  98. // may be empty, in which case the start page token will be returned for
  99. // the users changes.
  100. GURL GetStartPageTokenUrl(const std::string& team_drive) const;
  101. private:
  102. const GURL base_url_;
  103. const GURL base_download_url_;
  104. const GURL base_thumbnail_url_;
  105. // This class is copyable hence no DISALLOW_COPY_AND_ASSIGN here.
  106. };
  107. } // namespace google_apis
  108. #endif // GOOGLE_APIS_DRIVE_DRIVE_API_URL_GENERATOR_H_