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
5#ifndef GOOGLE_APIS_DRIVE_DRIVE_API_URL_GENERATOR_H_
6#define GOOGLE_APIS_DRIVE_DRIVE_API_URL_GENERATOR_H_
7
8#include <string>
9
10#include "url/gurl.h"
11
12namespace google_apis {
13
14// This class is used to generate URLs for communicating with drive api
15// servers for production, and a local server for testing.
16class DriveApiUrlGenerator {
17 public:
18  // |base_url| is the path to the target drive api server.
19  // Note that this is an injecting point for a testing server.
20  DriveApiUrlGenerator(const GURL& base_url, const GURL& base_download_url);
21  ~DriveApiUrlGenerator();
22
23  // The base URL for communicating with the production drive api server.
24  static const char kBaseUrlForProduction[];
25
26  // The base URL for the file download server for production.
27  static const char kBaseDownloadUrlForProduction[];
28
29  // Returns a URL to invoke "About: get" method.
30  GURL GetAboutGetUrl() const;
31
32  // Returns a URL to invoke "Apps: list" method.
33  // Set |use_internal_endpoint| to true if official Chrome's API key is used
34  // and retrieving more information (related to App uninstall) is necessary.
35  GURL GetAppsListUrl(bool use_internal_endpoint) const;
36
37  // Returns a URL to uninstall an app with the give |app_id|.
38  GURL GetAppsDeleteUrl(const std::string& app_id) const;
39
40  // Returns a URL to fetch a file metadata.
41  GURL GetFilesGetUrl(const std::string& file_id) const;
42
43  // Returns a URL to authorize an app to access a file.
44  GURL GetFilesAuthorizeUrl(const std::string& file_id,
45                            const std::string& app_id) const;
46
47  // Returns a URL to create a resource.
48  GURL GetFilesInsertUrl() const;
49
50  // Returns a URL to patch file metadata.
51  GURL GetFilesPatchUrl(const std::string& file_id,
52                        bool set_modified_date,
53                        bool update_viewed_date) const;
54
55  // Returns a URL to copy a resource specified by |file_id|.
56  GURL GetFilesCopyUrl(const std::string& file_id) const;
57
58  // Returns a URL to fetch file list.
59  GURL GetFilesListUrl(int max_results,
60                       const std::string& page_token,
61                       const std::string& q) const;
62
63  // Returns a URL to delete a resource with the given |file_id|.
64  GURL GetFilesDeleteUrl(const std::string& file_id) const;
65
66  // Returns a URL to trash a resource with the given |file_id|.
67  GURL GetFilesTrashUrl(const std::string& file_id) const;
68
69  // Returns a URL to fetch a list of changes.
70  GURL GetChangesListUrl(bool include_deleted,
71                         int max_results,
72                         const std::string& page_token,
73                         int64 start_change_id) const;
74
75  // Returns a URL to add a resource to a directory with |folder_id|.
76  GURL GetChildrenInsertUrl(const std::string& folder_id) const;
77
78  // Returns a URL to remove a resource with |child_id| from a directory
79  // with |folder_id|.
80  GURL GetChildrenDeleteUrl(const std::string& child_id,
81                            const std::string& folder_id) const;
82
83  // Returns a URL to initiate uploading a new file.
84  GURL GetInitiateUploadNewFileUrl(bool set_modified_date) const;
85
86  // Returns a URL to initiate uploading an existing file specified by
87  // |resource_id|.
88  GURL GetInitiateUploadExistingFileUrl(const std::string& resource_id,
89                                        bool set_modified_date) const;
90
91  // Generates a URL for downloading a file.
92  GURL GenerateDownloadFileUrl(const std::string& resource_id) const;
93
94  // Generates a URL for adding permissions.
95  GURL GetPermissionsInsertUrl(const std::string& resource_id) const;
96
97 private:
98  const GURL base_url_;
99  const GURL base_download_url_;
100
101  // This class is copyable hence no DISALLOW_COPY_AND_ASSIGN here.
102};
103
104}  // namespace google_apis
105
106#endif  // GOOGLE_APIS_DRIVE_DRIVE_API_URL_GENERATOR_H_
107