diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2016-02-22 21:12:25 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2016-02-22 21:12:25 +0000 |
commit | 0b82b879821c7e73b86f189be747c5634c8b46b7 (patch) | |
tree | 28c7e3b06c25a7b9fbd49a33972e7fae07dd2e56 /plugins/Dropbox/src/api | |
parent | 477664ed5c4b018562e9419428175ae938cf2761 (diff) |
Dropbox:
- updated api to v2
- version bump
git-svn-id: http://svn.miranda-ng.org/main/trunk@16326 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dropbox/src/api')
-rw-r--r-- | plugins/Dropbox/src/api/account.h | 19 | ||||
-rw-r--r-- | plugins/Dropbox/src/api/operations.h | 74 | ||||
-rw-r--r-- | plugins/Dropbox/src/api/upload.h | 67 |
3 files changed, 120 insertions, 40 deletions
diff --git a/plugins/Dropbox/src/api/account.h b/plugins/Dropbox/src/api/account.h index 9c8bf20e7e..2842804dcc 100644 --- a/plugins/Dropbox/src/api/account.h +++ b/plugins/Dropbox/src/api/account.h @@ -5,30 +5,31 @@ class GetAccessTokenRequest : public HttpRequest {
public:
GetAccessTokenRequest(const char *requestToken) :
- HttpRequest(REQUEST_POST, DROPBOX_API_URL "/oauth2/token")
+ HttpRequest(REQUEST_POST, DROPBOX_API_OLD "/oauth2/token")
{
- AddBasicAuthHeader(DROPBOX_APP_KEY, DROPBOX_API_SECRET);
AddHeader("Content-Type", "application/x-www-form-urlencoded");
- CMStringA data(CMStringDataFormat::FORMAT, "grant_type=authorization_code&code=%s", requestToken);
+ CMStringA data(CMStringDataFormat::FORMAT,
+ "client_id=%s&client_secret=%s&grant_type=authorization_code&code=%s",
+ DROPBOX_APP_KEY, DROPBOX_API_SECRET, requestToken);
SetData(data.GetBuffer(), data.GetLength());
}
};
-class DisableAccessTokenRequest : public HttpRequest
+/*class DisableAccessTokenRequest : public HttpRequest
{
public:
DisableAccessTokenRequest() :
- HttpRequest(REQUEST_POST, DROPBOX_API_URL "/disable_access_token")
+ HttpRequest(REQUEST_POST, DROPBOX_API_OLD "/disable_access_token")
{
}
-};
+};*/
-class GetAccountInfoRequest : public HttpRequest
+class GetCurrentAccountRequest : public HttpRequest
{
public:
- GetAccountInfoRequest(const char *token) :
- HttpRequest(REQUEST_GET, DROPBOX_API_URL "/account/info")
+ GetCurrentAccountRequest(const char *token) :
+ HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/users/get_current_account")
{
AddBearerAuthHeader(token);
}
diff --git a/plugins/Dropbox/src/api/operations.h b/plugins/Dropbox/src/api/operations.h index e41dbaabfe..71c455d1e8 100644 --- a/plugins/Dropbox/src/api/operations.h +++ b/plugins/Dropbox/src/api/operations.h @@ -4,54 +4,88 @@ class ShareRequest : public HttpRequest
{
public:
- ShareRequest(const char *token, const char *path, bool useShortUrl, const char *root = "auto") :
- HttpRequest(REQUEST_POST, FORMAT, DROPBOX_API_URL "/shares/%s/%s", root, path)
+ ShareRequest(const char *token, const char *path, time_t expires = 0) :
+ HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/sharing/create_shared_link_with_settings")
{
- if (!useShortUrl)
- AddUrlParameter("short_url=false");
-
AddBearerAuthHeader(token);
- AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ AddHeader("Content-Type", "application/json");
+
+ JSONNode root(JSON_NODE);
+ root << JSONNode("path", path);
+
+ if (expires)
+ root << JSONNode("expires", (unsigned int)expires);
+
+ json_string data = root.write();
+ SetData(data.c_str(), data.length());
}
};
class DeleteRequest : public HttpRequest
{
public:
- DeleteRequest(const char *token, const char *path, const char *root = "auto") :
- HttpRequest(REQUEST_POST, DROPBOX_API_URL "/fileops/delete")
+ DeleteRequest(const char *token, const char *path) :
+ HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/files/delete")
{
AddBearerAuthHeader(token);
- AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ AddHeader("Content-Type", "application/json");
+
+ JSONNode root(JSON_NODE);
+ root << JSONNode("path", path);
- CMStringA data(CMStringDataFormat::FORMAT, "root=%s&path=%s", root, path);
- data.Replace('\\', '/');
- SetData(data.GetBuffer(), data.GetLength());
+ json_string data = root.write();
+ SetData(data.c_str(), data.length());
}
};
class CreateFolderRequest : public HttpRequest
{
public:
- CreateFolderRequest(const char *token, const char *path, const char *root = "auto") :
- HttpRequest(REQUEST_POST, DROPBOX_API_URL "/fileops/create_folder")
+ CreateFolderRequest(const char *token, const char *path) :
+ HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/files/create_folder")
{
AddBearerAuthHeader(token);
- AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ AddHeader("Content-Type", "application/json");
- CMStringA data(CMStringDataFormat::FORMAT, "root=%s&path=%s", root, path);
- data.Replace('\\', '/');
- SetData(data.GetBuffer(), data.GetLength());
+ JSONNode root(JSON_NODE);
+ root << JSONNode("path", path);
+
+ json_string data = root.write();
+ SetData(data.c_str(), data.length());
}
};
class GetMetadataRequest : public HttpRequest
{
public:
- GetMetadataRequest(const char *token, const char *path, const char *root = "auto") :
- HttpRequest(REQUEST_GET, FORMAT, DROPBOX_API_URL "/metadata/%s/%s", root, path)
+ GetMetadataRequest(const char *token, const char *path) :
+ HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/files/get_metadata")
{
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 ListFolderRequest : public HttpRequest
+{
+public:
+ ListFolderRequest(const char *token, const char *path) :
+ HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/files/list_folder")
+ {
+ 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());
}
};
diff --git a/plugins/Dropbox/src/api/upload.h b/plugins/Dropbox/src/api/upload.h index 4bc9da9043..22125ed66d 100644 --- a/plugins/Dropbox/src/api/upload.h +++ b/plugins/Dropbox/src/api/upload.h @@ -4,39 +4,84 @@ class UploadFileRequest : public HttpRequest
{
public:
- UploadFileRequest(const char *token, const char *fileName, const char *data, size_t size, const char *root = "auto") :
- HttpRequest(REQUEST_PUT, FORMAT, DROPBOX_APICONTENT_URL "/files_put/%s/%s", root, fileName)
+ UploadFileRequest(const char *token, const char *path, const char *data, size_t size) :
+ HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload")
{
AddBearerAuthHeader(token);
+ AddHeader("Content-Type", "application/octet-stream");
+
+ JSONNode root(JSON_NODE);
+ root << JSONNode("path", path);
+
+ json_string params = root.write();
+ AddHeader("Dropbox-API-Arg", params.c_str());
+
SetData(data, size);
}
};
-class UploadFileChunkRequest : public HttpRequest
+class StartUploadSessionRequest : public HttpRequest
{
public:
- UploadFileChunkRequest(const char *token, const char *data, size_t size) :
- HttpRequest(REQUEST_PUT, DROPBOX_APICONTENT_URL "/chunked_upload")
+ StartUploadSessionRequest(const char *token, const char *data, size_t size) :
+ HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload_session/start")
{
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/octet-stream");
+
SetData(data, size);
}
+};
- UploadFileChunkRequest(const char *token, const char *uploadId, size_t offset, const char *data, size_t size) :
- HttpRequest(REQUEST_PUT, FORMAT, DROPBOX_APICONTENT_URL "/chunked_upload?upload_id=%s&offset=%i", uploadId, offset)
+class AppendToUploadSessionRequest : public HttpRequest
+{
+public:
+ AppendToUploadSessionRequest(const char *token, const char *sessionId, size_t offset, const char *data, size_t size) :
+ HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload_session/append")
{
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/octet-stream");
+
+ JSONNode root(JSON_NODE);
+ root
+ << JSONNode("session_id", sessionId)
+ << JSONNode("offset", offset);
+
+ json_string params = root.write();
+ AddHeader("Dropbox-API-Arg", params.c_str());
+
SetData(data, size);
}
+};
- UploadFileChunkRequest(const char *token, const char *uploadId, const char *path, const char *root = "auto") :
- HttpRequest(REQUEST_POST, FORMAT, DROPBOX_APICONTENT_URL "/commit_chunked_upload/%s/%s", root, path)
+class FinishUploadSessionRequest : public HttpRequest
+{
+public:
+ FinishUploadSessionRequest(const char *token, const char *sessionId, size_t offset, const char *path, const char *data, size_t size) :
+ HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload_session/finish")
{
AddBearerAuthHeader(token);
- AddHeader("Content-Type", "application/x-www-form-urlencoded");
- AddUrlParameter("upload_id=%s", uploadId);
+ AddHeader("Content-Type", "application/octet-stream");
+
+ JSONNode cursor(JSON_NODE);
+ cursor.set_name("cursor");
+ cursor
+ << JSONNode("session_id", sessionId)
+ << JSONNode("offset", offset);
+
+ JSONNode commit(JSON_NODE);
+ commit.set_name("commit");
+ commit << JSONNode("path", path);
+
+ JSONNode root(JSON_NODE);
+ root
+ << cursor
+ << commit;
+
+ json_string params = root.write();
+ AddHeader("Dropbox-API-Arg", params.c_str());
+
+ SetData(data, size);
}
};
|