summaryrefslogtreecommitdiffstats
path: root/chrome/browser/google_apis/gdata_wapi_url_generator.h
blob: 6781cf07ccbd2520d057e9442738e23b38d7ae37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// URL utility functions for Google Documents List API (aka WAPI).

#ifndef CHROME_BROWSER_GOOGLE_APIS_GDATA_WAPI_URL_GENERATOR_H_
#define CHROME_BROWSER_GOOGLE_APIS_GDATA_WAPI_URL_GENERATOR_H_

#include <string>

#include "url/gurl.h"

namespace google_apis {

// The class is used to generate URLs for communicating with the WAPI server.
// for production, and the local server for testing.
class GDataWapiUrlGenerator {
 public:
  // The
  GDataWapiUrlGenerator(const GURL& base_url, const GURL& base_download_url);
  ~GDataWapiUrlGenerator();

  // The base URL for communicating with the WAPI server for production.
  static const char kBaseUrlForProduction[];

  // The base URL for the file download server for production.
  static const char kBaseDownloadUrlForProduction[];

  // Adds additional parameters for API version, output content type and to
  // show folders in the feed are added to document feed URLs.
  static GURL AddStandardUrlParams(const GURL& url);

  // Adds additional parameters for initiate uploading as well as standard
  // url params (as AddStandardUrlParams above does).
  static GURL AddInitiateUploadUrlParams(const GURL& url);

  // Adds additional parameters for API version, output content type and to
  // show folders in the feed are added to document feed URLs.
  static GURL AddFeedUrlParams(const GURL& url,
                               int num_items_to_fetch);

  // Generates a URL for getting the resource list feed.
  //
  // The parameters other than |search_string| are mutually exclusive.
  // If |override_url| is non-empty, other parameters are ignored. Or if
  // |override_url| is empty, others are not used. Besides, |search_string|
  // cannot be set together with |start_changestamp|.
  //
  // override_url:
  //   By default, a hard-coded base URL of the WAPI server is used.
  //   The base URL can be overridden by |override_url|.
  //   This is used for handling continuation of feeds (2nd page and onward).
  //
  // start_changestamp
  //   If |start_changestamp| is 0, URL for a full feed is generated.
  //   If |start_changestamp| is non-zero, URL for a delta feed is generated.
  //
  // search_string
  //   If |search_string| is non-empty, q=... parameter is added, and
  //   max-results=... parameter is adjusted for a search.
  //
  // directory_resource_id:
  //   If |directory_resource_id| is non-empty, a URL for fetching documents in
  //   a particular directory is generated.
  //
  GURL GenerateResourceListUrl(
      const GURL& override_url,
      int64 start_changestamp,
      const std::string& search_string,
      const std::string& directory_resource_id) const;

  // Generates a URL for searching resources by title (exact-match).
  // |directory_resource_id| is optional parameter. When it is empty
  // all the existing resources are target of the search. Otherwise,
  // the search target is just under the directory with it.
  GURL GenerateSearchByTitleUrl(
      const std::string& title,
      const std::string& directory_resource_id) const;

  // Generates a URL for getting or editing the resource entry of
  // the given resource ID.
  GURL GenerateEditUrl(const std::string& resource_id) const;

  // Generates a URL for getting or editing the resource entry of the
  // given resource ID without query params.
  // Note that, in order to access to the WAPI server, it is necessary to
  // append some query parameters to the URL. GenerateEditUrl declared above
  // should be used in such cases. This method is designed for constructing
  // the data, such as xml element/attributes in request body containing
  // edit urls.
  GURL GenerateEditUrlWithoutParams(const std::string& resource_id) const;

  // Generates a URL for getting or editing the resource entry of the given
  // resource ID with additionally passed embed origin. This is used to fetch
  // share urls for the sharing dialog to be embedded with the |embed_origin|
  // origin.
  GURL GenerateEditUrlWithEmbedOrigin(const std::string& resource_id,
                                      const GURL& embed_origin) const;

  // Generates a URL for editing the contents in the directory specified
  // by the given resource ID.
  GURL GenerateContentUrl(const std::string& resource_id) const;

  // Generates a URL to remove an entry specified by |resource_id| from
  // the directory specified by the given |parent_resource_id|.
  GURL GenerateResourceUrlForRemoval(const std::string& parent_resource_id,
                                     const std::string& resource_id) const;

  // Generates a URL to initiate uploading a new file to a directory
  // specified by |parent_resource_id|.
  GURL GenerateInitiateUploadNewFileUrl(
      const std::string& parent_resource_id) const;

  // Generates a URL to initiate uploading file content to overwrite a
  // file specified by |resource_id|.
  GURL GenerateInitiateUploadExistingFileUrl(
      const std::string& resource_id) const;

  // Generates a URL for getting the root resource list feed.
  // Used to make changes in the root directory (ex. create a directory in the
  // root directory)
  GURL GenerateResourceListRootUrl() const;

  // Generates a URL for getting the account metadata feed.
  // If |include_installed_apps| is set to true, the response will include the
  // list of installed third party applications.
  GURL GenerateAccountMetadataUrl(bool include_installed_apps) const;

  // Generates a URL for downloading a file.
  GURL GenerateDownloadFileUrl(const std::string& resource_id) const;

 private:
  const GURL base_url_;
  const GURL base_download_url_;
};

}  // namespace google_apis

#endif  // CHROME_BROWSER_GOOGLE_APIS_GDATA_WAPI_URL_GENERATOR_H_