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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
#ifndef _DROPBOXSERVICE_API_H_
#define _DROPBOXSERVICE_API_H_
// https://www.dropbox.com/developers/documentation/http/documentation
namespace DropboxAPI
{
#define DROPBOX_API_VER "/2"
#define DROPBOX_API "https://api.dropboxapi.com"
#define DROPBOX_API_OAUTH DROPBOX_API "/oauth2"
#define DROPBOX_API_RPC DROPBOX_API DROPBOX_API_VER
#define DROPBOX_CONTENT "https://content.dropboxapi.com"
#define DROPBOX_API_CU DROPBOX_CONTENT DROPBOX_API_VER
#define DROPBOX_APP_KEY "fa8du7gkf2q8xzg"
#include "../../../miranda-private-keys/Dropbox/secret_key.h"
#define DROPBOX_API_AUTH "https://www.dropbox.com/oauth2/authorize?response_type=code&redirect_uri=https%3A%2F%2Foauth.miranda-ng.org%2Fverification&client_id=" DROPBOX_APP_KEY
class GetAccessTokenRequest : public HttpRequest
{
public:
GetAccessTokenRequest(const char *code) :
HttpRequest(REQUEST_POST, DROPBOX_API_OAUTH "/token")
{
AddHeader("Content-Type", "application/x-www-form-urlencoded");
CMStringA data = "redirect_uri=https://oauth.miranda-ng.org/verification";
data.AppendFormat("&client_id=%s&client_secret=%s", DROPBOX_APP_KEY, DROPBOX_API_SECRET);
data.AppendFormat("&grant_type=authorization_code&code=%s", code);
SetData(data.GetBuffer(), data.GetLength());
}
};
class RevokeAccessTokenRequest : public HttpRequest
{
public:
RevokeAccessTokenRequest(const char *token) :
HttpRequest(REQUEST_POST, DROPBOX_API_OAUTH "/token/revoke")
{
AddBearerAuthHeader(token);
}
};
class UploadFileRequest : public HttpRequest
{
public:
UploadFileRequest(const char *token, const char *path, const char *data, size_t size, OnConflict strategy = NONE) :
HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload")
{
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/octet-stream");
JSONNode params(JSON_NODE);
params
<< JSONNode("path", path);
if (strategy == OnConflict::RENAME) {
params
<< JSONNode("mode", "add")
<< JSONNode("autorename", true);
}
else if (strategy == OnConflict::REPLACE) {
params
<< JSONNode("mode", "overwrite")
<< JSONNode("autorename", false);
}
AddHeader("Dropbox-API-Arg", params.write().c_str());
SetData(data, size);
}
};
class CreateUploadSessionRequest : public HttpRequest
{
public:
CreateUploadSessionRequest(const char *token, const char *chunk, size_t chunkSize) :
HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload_session/start")
{
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/octet-stream");
SetData(chunk, chunkSize);
}
};
class UploadFileChunkRequest : public HttpRequest
{
public:
UploadFileChunkRequest(const char *token, const char *sessionId, size_t offset, const char *chunk, size_t chunkSize) :
HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload_session/append_v2")
{
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/octet-stream");
JSONNode cursor;
cursor.set_name("cursor");
cursor
<< JSONNode("session_id", sessionId)
<< JSONNode("offset", (unsigned long)offset);
JSONNode param;
param << cursor;
AddHeader("Dropbox-API-Arg", param.write().c_str());
SetData(chunk, chunkSize);
}
};
class CommitUploadSessionRequest : public HttpRequest
{
public:
CommitUploadSessionRequest(const char *token, const char *sessionId, size_t offset, const char *path, const char *chunk, size_t chunkSize, OnConflict strategy = NONE) :
HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload_session/finish")
{
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/octet-stream");
JSONNode cursor(JSON_NODE);
cursor.set_name("cursor");
cursor
<< JSONNode("session_id", sessionId)
<< JSONNode("offset", (unsigned long)offset);
JSONNode commit(JSON_NODE);
commit.set_name("commit");
commit
<< JSONNode("path", path);
if (strategy == OnConflict::RENAME) {
commit
<< JSONNode("mode", "add")
<< JSONNode("autorename", true);
}
else if (strategy == OnConflict::REPLACE) {
commit
<< JSONNode("mode", "overwrite")
<< JSONNode("autorename", false);
}
JSONNode params(JSON_NODE);
params
<< cursor
<< commit;
AddHeader("Dropbox-API-Arg", params.write().c_str());
SetData(chunk, chunkSize);
}
};
class CreateFolderRequest : public HttpRequest
{
public:
CreateFolderRequest(const char *token, const char *path) :
HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/files/create_folder_v2")
{
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/json");
JSONNode root(JSON_NODE);
root << JSONNode("path", path);
json_string data = root.write();
SetData(data.c_str(), data.length());
}
};
class GetTemporaryLinkRequest : public HttpRequest
{
public:
GetTemporaryLinkRequest(const char *token, const char *path) :
HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/files/get_temporary_link")
{
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/json");
JSONNode root(JSON_NODE);
root << JSONNode("path", path);
json_string data = root.write();
SetData(data.c_str(), data.length());
}
};
class CreateSharedLinkRequest : public HttpRequest
{
public:
CreateSharedLinkRequest(const char *token, const char *path) :
HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/sharing/create_shared_link_with_settings")
{
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/json");
JSONNode root(JSON_NODE);
root << JSONNode("path", path);
json_string data = root.write();
SetData(data.c_str(), data.length());
}
};
class GetSharedLinkRequest : public HttpRequest
{
public:
GetSharedLinkRequest(const char *token, const char *path) :
HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/sharing/list_shared_links")
{
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/json");
JSONNode root(JSON_NODE);
root << JSONNode("path", path);
json_string data = root.write();
SetData(data.c_str(), data.length());
}
};
};
#endif //_DROPBOXSERVICE_API_H_
|