Kgapi

driveservice.cpp
1/*
2 * This file is part of LibKGAPI library
3 *
4 * SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9#include "driveservice.h"
10#include "utils.h"
11
12#include <QUrlQuery>
13
14namespace KGAPI2
15{
16
17namespace Private
18{
19static const QUrl GoogleApisUrl(QStringLiteral("https://www.googleapis.com"));
20static const QString AppsBasePath(QStringLiteral("/drive/v2/about"));
21static const QString FilesBasePath(QStringLiteral("/drive/v2/files"));
22static const QString ChangeBasePath(QStringLiteral("/drive/v2/changes"));
23static const QString DrivesBasePath(QStringLiteral("/drive/v2/drives"));
24static const QString TeamdriveBasePath(QStringLiteral("/drive/v2/teamdrives"));
25}
26
27namespace DriveService
28{
29
30QUrl fetchAboutUrl(bool includeSubscribed, qlonglong maxChangeIdCount, qlonglong startChangeId)
31{
32 QUrl url(Private::GoogleApisUrl);
33 url.setPath(Private::AppsBasePath);
34 QUrlQuery query(url);
35 query.addQueryItem(QStringLiteral("includeSubscribed"), Utils::bool2Str(includeSubscribed));
36 if (maxChangeIdCount > 0) {
37 query.addQueryItem(QStringLiteral("maxChangeIdCount"), QString::number(maxChangeIdCount));
38 }
39 if (startChangeId > 0) {
40 query.addQueryItem(QStringLiteral("startChangeId"), QString::number(startChangeId));
41 }
42 url.setQuery(query);
43
44 return url;
45}
46
47QUrl fetchAppUrl(const QString &appId)
48{
49 QUrl url(Private::GoogleApisUrl);
50 url.setPath(Private::AppsBasePath % QLatin1Char('/') % appId);
51 return url;
52}
53
54QUrl fetchAppsUrl()
55{
56 QUrl url(Private::GoogleApisUrl);
57 url.setPath(Private::AppsBasePath);
58 return url;
59}
60
61QUrl fetchChildReference(const QString &folderId, const QString &referenceId)
62{
63 QUrl url(Private::GoogleApisUrl);
64 url.setPath(Private::FilesBasePath % QLatin1Char('/') % folderId % QLatin1StringView("/children/") % referenceId);
65 return url;
66}
67
68QUrl fetchChildReferences(const QString &folderId)
69{
70 QUrl url(Private::GoogleApisUrl);
71 url.setPath(Private::FilesBasePath % QLatin1Char('/') % folderId % QLatin1StringView("/children"));
72 return url;
73}
74
75QUrl createChildReference(const QString &folderId)
76{
77 QUrl url(Private::GoogleApisUrl);
78 url.setPath(Private::FilesBasePath % QLatin1Char('/') % folderId % QLatin1StringView("/children"));
79 return url;
80}
81
82QUrl deleteChildReference(const QString &folderId, const QString &referenceId)
83{
84 QUrl url(Private::GoogleApisUrl);
85 url.setPath(Private::FilesBasePath % QLatin1Char('/') % folderId % QLatin1StringView("/children/") % referenceId);
86 return url;
87}
88
89QUrl fetchChangeUrl(const QString &changeId)
90{
91 QUrl url(Private::GoogleApisUrl);
92 url.setPath(Private::ChangeBasePath % QLatin1Char('/') % changeId);
93 return url;
94}
95
96QUrl copyFileUrl(const QString &fileId)
97{
98 QUrl url(Private::GoogleApisUrl);
99 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1StringView("/copy"));
100 return url;
101}
102
103QUrl deleteFileUrl(const QString &fileId)
104{
105 QUrl url(Private::GoogleApisUrl);
106 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId);
107 return url;
108}
109
110QUrl fetchFileUrl(const QString &fileId)
111{
112 QUrl url(Private::GoogleApisUrl);
113 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId);
114 return url;
115}
116
117QUrl fetchFilesUrl()
118{
119 QUrl url(Private::GoogleApisUrl);
120 url.setPath(Private::FilesBasePath);
121 return url;
122}
123
124QUrl fetchChangesUrl()
125{
126 QUrl url(Private::GoogleApisUrl);
127 url.setPath(Private::ChangeBasePath);
128 return url;
129}
130
131QUrl touchFileUrl(const QString &fileId)
132{
133 QUrl url(Private::GoogleApisUrl);
134 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1StringView("/touch"));
135 return url;
136}
137
138QUrl trashFileUrl(const QString &fileId)
139{
140 QUrl url(Private::GoogleApisUrl);
141 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1StringView("/trash"));
142 return url;
143}
144
145QUrl untrashFileUrl(const QString &fileId)
146{
147 QUrl url(Private::GoogleApisUrl);
148 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1StringView("/untrash"));
149 return url;
150}
151
152QUrl uploadMetadataFileUrl(const QString &fileId)
153{
154 QUrl url(Private::GoogleApisUrl);
155 if (!fileId.isEmpty()) {
156 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId);
157 } else {
158 url.setPath(Private::FilesBasePath);
159 }
160 return url;
161}
162
163QUrl uploadMediaFileUrl(const QString &fileId)
164{
165 QUrl url(Private::GoogleApisUrl);
166 if (!fileId.isEmpty()) {
167 url.setPath(QLatin1StringView("/upload") % Private::FilesBasePath % QLatin1Char('/') % fileId);
168 } else {
169 url.setPath(QLatin1StringView("/upload") % Private::FilesBasePath);
170 }
171 return url;
172}
173
174QUrl uploadMultipartFileUrl(const QString &fileId)
175{
176 QUrl url(Private::GoogleApisUrl);
177 if (!fileId.isEmpty()) {
178 url.setPath(QLatin1StringView("/upload") % Private::FilesBasePath % QLatin1Char('/') % fileId);
179 } else {
180 url.setPath(QLatin1StringView("/upload") % Private::FilesBasePath);
181 }
182 return url;
183}
184
185QUrl fetchParentReferenceUrl(const QString &fileId, const QString &referenceId)
186{
187 QUrl url(Private::GoogleApisUrl);
188 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1StringView("/parents/") % referenceId);
189 return url;
190}
191
192QUrl fetchParentReferencesUrl(const QString &fileId)
193{
194 QUrl url(Private::GoogleApisUrl);
195 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1StringView("/parents"));
196
197 return url;
198}
199
200QUrl createParentReferenceUrl(const QString &fileId)
201{
202 QUrl url(Private::GoogleApisUrl);
203 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1StringView("/parents"));
204 return url;
205}
206
207QUrl deleteParentReferenceUrl(const QString &fileId, const QString &referenceId)
208{
209 QUrl url(Private::GoogleApisUrl);
210 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1StringView("/parents/") % referenceId);
211 return url;
212}
213
214QUrl fetchPermissionsUrl(const QString &fileId)
215{
216 QUrl url(Private::GoogleApisUrl);
217 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1StringView("/permissions"));
218 return url;
219}
220
221QUrl fetchPermissionUrl(const QString &fileId, const QString &permissionId)
222{
223 QUrl url(Private::GoogleApisUrl);
224 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1StringView("/permissions/") % permissionId);
225 return url;
226}
227
228QUrl createPermissionUrl(const QString &fileId)
229{
230 QUrl url(Private::GoogleApisUrl);
231 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1StringView("/permissions"));
232 return url;
233}
234
235QUrl deletePermissionUrl(const QString &fileId, const QString &permissionId)
236{
237 QUrl url(Private::GoogleApisUrl);
238 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1StringView("/permissions/") % permissionId);
239 return url;
240}
241
242QUrl modifyPermissionUrl(const QString &fileId, const QString &permissionId)
243{
244 QUrl url(Private::GoogleApisUrl);
245 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1StringView("/permissions/") % permissionId);
246 return url;
247}
248
249QUrl fetchRevisionUrl(const QString &fileId, const QString &revisionId)
250{
251 QUrl url(Private::GoogleApisUrl);
252 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1StringView("/revisions/") % revisionId);
253 return url;
254}
255
256QUrl fetchRevisionsUrl(const QString &fileId)
257{
258 QUrl url(Private::GoogleApisUrl);
259 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1StringView("/revisions"));
260 return url;
261}
262
263QUrl deleteRevisionUrl(const QString &fileId, const QString &revisionId)
264{
265 QUrl url(Private::GoogleApisUrl);
266 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1StringView("/revisions/") % revisionId);
267 return url;
268}
269
270QUrl modifyRevisionUrl(const QString &fileId, const QString &revisionId)
271{
272 QUrl url(Private::GoogleApisUrl);
273 url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1StringView("/revisions/") % revisionId);
274 return url;
275}
276
277QUrl fetchDrivesUrl(const QString &drivesId)
278{
279 QUrl url(Private::GoogleApisUrl);
280 url.setPath(Private::DrivesBasePath % QLatin1Char('/') % drivesId);
281 return url;
282}
283
284QUrl hideDrivesUrl(const QString &drivesId, bool hide)
285{
286 QUrl url(Private::GoogleApisUrl);
287 url.setPath(Private::DrivesBasePath % QLatin1Char('/') % drivesId % (hide ? QLatin1StringView("/hide") : QLatin1StringView("/unhide")));
288 return url;
289}
290
291QUrl fetchDrivesUrl()
292{
293 QUrl url(Private::GoogleApisUrl);
294 url.setPath(Private::DrivesBasePath);
295 return url;
296}
297
298QUrl fetchTeamdriveUrl(const QString &teamdriveId)
299{
300 QUrl url(Private::GoogleApisUrl);
301 url.setPath(Private::TeamdriveBasePath % QLatin1Char('/') % teamdriveId);
302 return url;
303}
304
305QUrl fetchTeamdrivesUrl()
306{
307 QUrl url(Private::GoogleApisUrl);
308 url.setPath(Private::TeamdriveBasePath);
309 return url;
310}
311
312} // namespace DriveService
313
314} // namespace KGAPI2
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
bool isEmpty() const const
QString number(double n, char format, int precision)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:52 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.