Commit e41eaa7a authored by Paweł Wegner's avatar Paweł Wegner

Added CreateDirectoryRequest.

parent d6924c2c
......@@ -29,6 +29,7 @@
#include "Utility/Item.h"
#include "Utility/Utility.h"
#include "Request/CreateDirectoryRequest.h"
#include "Request/DeleteItemRequest.h"
#include "Request/DownloadFileRequest.h"
#include "Request/GetItemDataRequest.h"
......@@ -183,6 +184,14 @@ ICloudProvider::DeleteItemRequest::Pointer CloudProvider::deleteItemAsync(
callback);
}
ICloudProvider::CreateDirectoryRequest::Pointer
CloudProvider::createDirectoryAsync(IItem::Pointer parent,
const std::string& name,
CreateDirectoryCallback callback) {
return make_unique<cloudstorage::CreateDirectoryRequest>(
shared_from_this(), parent, name, callback);
}
HttpRequest::Pointer CloudProvider::getItemDataRequest(const std::string&,
std::ostream&) const {
return nullptr;
......@@ -218,6 +227,11 @@ HttpRequest::Pointer CloudProvider::deleteItemRequest(const IItem&,
return nullptr;
}
HttpRequest::Pointer CloudProvider::createDirectoryRequest(
const IItem&, const std::string&, std::ostream&) const {
return nullptr;
}
IItem::Pointer CloudProvider::getItemDataResponse(std::istream&) const {
return nullptr;
}
......@@ -227,4 +241,8 @@ std::vector<IItem::Pointer> CloudProvider::listDirectoryResponse(
return {};
}
IItem::Pointer CloudProvider::createDirectoryResponse(std::istream&) const {
return nullptr;
}
} // namespace cloudstorage
......@@ -72,6 +72,9 @@ class CloudProvider : public ICloudProvider,
IItem::Pointer, IDownloadFileCallback::Pointer);
DeleteItemRequest::Pointer deleteItemAsync(IItem::Pointer,
DeleteItemCallback);
CreateDirectoryRequest::Pointer createDirectoryAsync(IItem::Pointer parent,
const std::string& name,
CreateDirectoryCallback);
virtual HttpRequest::Pointer getItemDataRequest(
const std::string& id, std::ostream& input_stream) const;
......@@ -87,10 +90,14 @@ class CloudProvider : public ICloudProvider,
const IItem&, std::ostream& input_stream) const;
virtual HttpRequest::Pointer deleteItemRequest(
const IItem&, std::ostream& input_stream) const;
virtual HttpRequest::Pointer createDirectoryRequest(const IItem&,
const std::string&,
std::ostream&) const;
virtual IItem::Pointer getItemDataResponse(std::istream& response) const;
virtual std::vector<IItem::Pointer> listDirectoryResponse(
std::istream& response, std::string& next_page_token) const;
virtual IItem::Pointer createDirectoryResponse(std::istream& response) const;
virtual void authorizeRequest(HttpRequest&) const;
virtual bool reauthorize(int code) const;
......
......@@ -45,10 +45,11 @@ class ICloudProvider {
using UploadFileRequest = IRequest<void>;
using GetItemDataRequest = IRequest<IItem::Pointer>;
using DeleteItemRequest = IRequest<bool>;
using CreateDirectoryRequest = IRequest<IItem::Pointer>;
class ICallback {
public:
using Pointer = std::unique_ptr<ICallback>;
using Pointer = std::shared_ptr<ICallback>;
enum class Status { WaitForAuthorizationCode, None };
......@@ -85,6 +86,9 @@ class ICloudProvider {
IItem::Pointer item, IDownloadFileCallback::Pointer) = 0;
virtual DeleteItemRequest::Pointer deleteItemAsync(IItem::Pointer,
DeleteItemCallback) = 0;
virtual CreateDirectoryRequest::Pointer createDirectoryAsync(
IItem::Pointer parent, const std::string& name,
CreateDirectoryCallback) = 0;
};
} // namespace cloudstorage
......
......@@ -82,6 +82,7 @@ class IUploadFileCallback {
using GetItemCallback = std::function<void(IItem::Pointer)>;
using GetItemDataCallback = std::function<void(IItem::Pointer)>;
using DeleteItemCallback = std::function<void(bool)>;
using CreateDirectoryCallback = std::function<void(IItem::Pointer)>;
} // namespace cloudstorage
......
......@@ -32,7 +32,8 @@ libcloudstorage_la_SOURCES = \
Request/ListDirectoryRequest.cpp \
Request/UploadFileRequest.cpp \
Request/GetItemDataRequest.cpp \
Request/DeleteItemRequest.cpp
Request/DeleteItemRequest.cpp \
Request/CreateDirectoryRequest.cpp
noinst_HEADERS = \
IAuth.h \
......@@ -56,7 +57,8 @@ noinst_HEADERS = \
Request/GetItemRequest.h \
Request/ListDirectoryRequest.h \
Request/UploadFileRequest.h \
Request/DeleteItemRequest.h
Request/DeleteItemRequest.h \
Request/CreateDirectoryRequest.h
nobase_include_HEADERS = \
IItem.h \
......
/*****************************************************************************
* CreateDirectoryRequest.cpp : CreateDirectoryRequest implementation
*
*****************************************************************************
* Copyright (C) 2016-2016 VideoLAN
*
* Authors: Paweł Wegner <pawel.wegner95@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "CreateDirectoryRequest.h"
#include "CloudProvider/CloudProvider.h"
#include "Utility/HttpRequest.h"
namespace cloudstorage {
CreateDirectoryRequest::CreateDirectoryRequest(std::shared_ptr<CloudProvider> p,
IItem::Pointer parent,
const std::string& name,
CreateDirectoryCallback callback)
: Request(p), parent_(parent), name_(name), callback_(callback) {
set_resolver([this](Request* r) -> IItem::Pointer {
std::stringstream output;
int code = r->sendRequest(
[this](std::ostream& stream) {
return provider()->createDirectoryRequest(*parent_, name_, stream);
},
output);
if (HttpRequest::isSuccess(code)) {
auto i = provider()->createDirectoryResponse(output);
callback_(i);
return i;
} else {
callback_(nullptr);
return nullptr;
}
});
}
CreateDirectoryRequest::~CreateDirectoryRequest() { cancel(); }
} // namespace cloudstorage
/*****************************************************************************
* CreateDirectoryRequest.h : CreateDirectoryRequest headers
*
*****************************************************************************
* Copyright (C) 2016-2016 VideoLAN
*
* Authors: Paweł Wegner <pawel.wegner95@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef CREATEDIRECTORYREQUEST_H
#define CREATEDIRECTORYREQUEST_H
#include "Request.h"
namespace cloudstorage {
class CreateDirectoryRequest : public Request<IItem::Pointer> {
public:
CreateDirectoryRequest(std::shared_ptr<CloudProvider>, IItem::Pointer,
const std::string&, CreateDirectoryCallback);
~CreateDirectoryRequest();
private:
IItem::Pointer parent_;
std::string name_;
CreateDirectoryCallback callback_;
};
} // namespace cloudstorage
#endif // CREATEDIRECTORYREQUEST_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment