From 71846c4e387e27164ffde6b2e8a188b3bc21b2eb Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Wed, 13 May 2015 14:29:47 +0000 Subject: Dropbox: refactoring of http requests git-svn-id: http://svn.miranda-ng.org/main/trunk@13570 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Dropbox/src/api/account.h | 38 +++++++++++++++++++++++ plugins/Dropbox/src/api/operations.h | 60 ++++++++++++++++++++++++++++++++++++ plugins/Dropbox/src/api/upload.h | 47 ++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 plugins/Dropbox/src/api/account.h create mode 100644 plugins/Dropbox/src/api/operations.h create mode 100644 plugins/Dropbox/src/api/upload.h (limited to 'plugins/Dropbox/src/api') diff --git a/plugins/Dropbox/src/api/account.h b/plugins/Dropbox/src/api/account.h new file mode 100644 index 0000000000..4db79622d2 --- /dev/null +++ b/plugins/Dropbox/src/api/account.h @@ -0,0 +1,38 @@ +#ifndef _DROPBOX_API_ACCOUNT_H_ +#define _DROPBOX_API_ACCOUNT_H_ + +class GetAccessTokenRequest : public HttpRequest +{ +public: + GetAccessTokenRequest(const char *requestToken) : + HttpRequest(REQUEST_POST, DROPBOX_API_URL "/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); + pData = data.GetBuffer(); + dataLength = data.GetLength(); + } +}; + +class DisableAccessTokenRequest : public HttpRequest +{ +public: + DisableAccessTokenRequest() : + HttpRequest(REQUEST_POST, DROPBOX_API_URL "/disable_access_token") + { + } +}; + +class GetAccountInfoRequest : public HttpRequest +{ +public: + GetAccountInfoRequest(const char *token) : + HttpRequest(REQUEST_GET, DROPBOX_API_URL "/account/info") + { + AddBearerAuthHeader(token); + } +}; + +#endif //_DROPBOX_API_ACCOUNT_H_ diff --git a/plugins/Dropbox/src/api/operations.h b/plugins/Dropbox/src/api/operations.h new file mode 100644 index 0000000000..1ff7d50230 --- /dev/null +++ b/plugins/Dropbox/src/api/operations.h @@ -0,0 +1,60 @@ +#ifndef _DROPBOX_API_OPERATIONS_H_ +#define _DROPBOX_API_OPERATIONS_H_ + +class ShareRequest : public HttpRequest +{ +public: + ShareRequest(const char *token, const char *path, bool useShortUrl = true) : + HttpRequest(REQUEST_POST, FORMAT, DROPBOX_API_URL "/shares/auto/%s", path) + { + if (!useShortUrl) + AddUrlParameter("short_url=false"); + + AddBearerAuthHeader(token); + AddHeader("Content-Type", "application/x-www-form-urlencoded"); + } +}; + +class DeleteRequest : public HttpRequest +{ +public: + DeleteRequest(const char *token, const char *path) : + HttpRequest(REQUEST_POST, DROPBOX_API_URL "/fileops/delete") + { + AddBearerAuthHeader(token); + AddHeader("Content-Type", "application/x-www-form-urlencoded"); + + CMStringA data(CMStringDataFormat::FORMAT, "root=auto&path=%s", path); + data.Replace('\\', '/'); + pData = data.GetBuffer(); + dataLength = data.GetLength(); + } +}; + +class CreateFolderRequest : public HttpRequest +{ +public: + CreateFolderRequest(const char *token, const char *path) : + HttpRequest(REQUEST_POST, DROPBOX_API_URL "/fileops/create_folder") + { + AddBearerAuthHeader(token); + AddHeader("Content-Type", "application/x-www-form-urlencoded"); + + CMStringA data(CMStringDataFormat::FORMAT, "root=auto&path=%s", path); + data.Replace('\\', '/'); + pData = data.GetBuffer(); + dataLength = data.GetLength(); + } +}; + +class GetMetadataRequest : public HttpRequest +{ +public: + GetMetadataRequest(const char *token, const char *path) : + HttpRequest(REQUEST_GET, FORMAT, DROPBOX_API_URL "/metadata/auto/%s", path) + { + AddBearerAuthHeader(token); + } +}; + +#endif //_DROPBOX_API_OPERATIONS_H_ diff --git a/plugins/Dropbox/src/api/upload.h b/plugins/Dropbox/src/api/upload.h new file mode 100644 index 0000000000..323bf907a5 --- /dev/null +++ b/plugins/Dropbox/src/api/upload.h @@ -0,0 +1,47 @@ +#ifndef _DROPBOX_API_UPLOAD_H_ +#define _DROPBOX_API_UPLOAD_H_ + +class UploadFileRequest : public HttpRequest +{ +public: + UploadFileRequest(const char *token, const char *fileName, const char *data, int length) : + HttpRequest(REQUEST_PUT, FORMAT, DROPBOX_APICONTENT_URL "/files_put/auto/%s", fileName) + { + AddBearerAuthHeader(token); + pData = (char*)data; + dataLength = length; + } +}; + +class UploadFileChunkRequest : public HttpRequest +{ +public: + UploadFileChunkRequest(const char *token, const char *data, int length) : + HttpRequest(REQUEST_PUT, DROPBOX_APICONTENT_URL "/chunked_upload") + { + AddBearerAuthHeader(token); + AddHeader("Content-Type", "application/octet-stream"); + pData = (char*)data; + dataLength = length; + } + + UploadFileChunkRequest(const char *token, const char *uploadId, size_t offset, const char *data, int length) : + HttpRequest(REQUEST_PUT, FORMAT, DROPBOX_APICONTENT_URL "/chunked_upload?upload_id=%s&offset=%i", uploadId, offset) + { + AddBearerAuthHeader(token); + AddHeader("Content-Type", "application/octet-stream"); + pData = (char*)data; + dataLength = length; + } + + UploadFileChunkRequest(const char *token, const char *uploadId, const char *path) : + HttpRequest(REQUEST_POST, FORMAT, DROPBOX_APICONTENT_URL "/commit_chunked_upload/auto/%s", path) + { + AddBearerAuthHeader(token); + AddHeader("Content-Type", "application/x-www-form-urlencoded"); + + AddUrlParameter("upload_id=%s", uploadId); + } +}; + +#endif //_DROPBOX_API_UPLOAD_H_ -- cgit v1.2.3