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

ICloudProvider: added getGeneralDataAsync.

parent a7a7dcef
...@@ -457,6 +457,27 @@ ICloudProvider::UploadFileRequest::Pointer CloudProvider::uploadFileAsync( ...@@ -457,6 +457,27 @@ ICloudProvider::UploadFileRequest::Pointer CloudProvider::uploadFileAsync(
util::make_unique<::UploadFileCallback>(path, callback)); util::make_unique<::UploadFileCallback>(path, callback));
} }
ICloudProvider::GeneralDataRequest::Pointer CloudProvider::getGeneralDataAsync(
GeneralDataCallback cb) {
auto resolver = [=](Request<EitherError<GeneralData>>::Pointer r) {
r->request(
[=](util::Output stream) {
return r->provider()->getGeneralDataRequest(*stream);
},
[=](EitherError<Response> e) {
if (e.left()) return r->done(e.left());
try {
r->done(r->provider()->getGeneralDataResponse(e.right()->output()));
} catch (const std::exception&) {
r->done(Error{IHttpRequest::Failure, e.right()->output().str()});
}
});
};
return std::make_shared<Request<EitherError<GeneralData>>>(shared_from_this(),
cb, resolver)
->run();
}
IHttpRequest::Pointer CloudProvider::getItemDataRequest(const std::string&, IHttpRequest::Pointer CloudProvider::getItemDataRequest(const std::string&,
std::ostream&) const { std::ostream&) const {
return nullptr; return nullptr;
...@@ -513,6 +534,11 @@ IHttpRequest::Pointer CloudProvider::renameItemRequest(const IItem&, ...@@ -513,6 +534,11 @@ IHttpRequest::Pointer CloudProvider::renameItemRequest(const IItem&,
return nullptr; return nullptr;
} }
IHttpRequest::Pointer CloudProvider::getGeneralDataRequest(
std::ostream&) const {
return nullptr;
}
IItem::Pointer CloudProvider::getItemDataResponse(std::istream&) const { IItem::Pointer CloudProvider::getItemDataResponse(std::istream&) const {
return nullptr; return nullptr;
} }
...@@ -534,6 +560,10 @@ IItem::Pointer CloudProvider::uploadFileResponse(const IItem&, ...@@ -534,6 +560,10 @@ IItem::Pointer CloudProvider::uploadFileResponse(const IItem&,
return getItemDataResponse(response); return getItemDataResponse(response);
} }
GeneralData CloudProvider::getGeneralDataResponse(std::istream&) const {
return {};
}
std::string CloudProvider::getItemUrlResponse( std::string CloudProvider::getItemUrlResponse(
const IItem&, const IHttpRequest::HeaderParameters&, std::istream&) const { const IItem&, const IHttpRequest::HeaderParameters&, std::istream&) const {
return ""; return "";
......
...@@ -106,6 +106,7 @@ class CloudProvider : public ICloudProvider, ...@@ -106,6 +106,7 @@ class CloudProvider : public ICloudProvider,
const std::string& path, const std::string& path,
const std::string& filename, const std::string& filename,
UploadFileCallback) override; UploadFileCallback) override;
GeneralDataRequest::Pointer getGeneralDataAsync(GeneralDataCallback) override;
/** /**
* Used by default implementation of getItemDataAsync. * Used by default implementation of getItemDataAsync.
...@@ -204,6 +205,8 @@ class CloudProvider : public ICloudProvider, ...@@ -204,6 +205,8 @@ class CloudProvider : public ICloudProvider,
const std::string& name, const std::string& name,
std::ostream&) const; std::ostream&) const;
virtual IHttpRequest::Pointer getGeneralDataRequest(std::ostream&) const;
/** /**
* Used by default implementation of getItemDataAsync, should translate * Used by default implementation of getItemDataAsync, should translate
* reponse into IItem object. * reponse into IItem object.
...@@ -243,6 +246,7 @@ class CloudProvider : public ICloudProvider, ...@@ -243,6 +246,7 @@ class CloudProvider : public ICloudProvider,
const std::string& filename, const std::string& filename,
uint64_t size, uint64_t size,
std::istream& response) const; std::istream& response) const;
virtual GeneralData getGeneralDataResponse(std::istream& response) const;
/** /**
* Used by default implementation of createDirectoryAsync, should translate * Used by default implementation of createDirectoryAsync, should translate
...@@ -280,8 +284,7 @@ class CloudProvider : public ICloudProvider, ...@@ -280,8 +284,7 @@ class CloudProvider : public ICloudProvider,
static std::string getPath(const std::string&); static std::string getPath(const std::string&);
static std::string getFilename(const std::string& path); static std::string getFilename(const std::string& path);
static Json::Value credentialsFromString( static Json::Value credentialsFromString(const std::string&);
const std::string&);
static std::string credentialsToString(const Json::Value& json); static std::string credentialsToString(const Json::Value& json);
protected: protected:
......
...@@ -56,6 +56,7 @@ class ICloudProvider { ...@@ -56,6 +56,7 @@ class ICloudProvider {
using CreateDirectoryRequest = IRequest<EitherError<IItem>>; using CreateDirectoryRequest = IRequest<EitherError<IItem>>;
using MoveItemRequest = IRequest<EitherError<IItem>>; using MoveItemRequest = IRequest<EitherError<IItem>>;
using RenameItemRequest = IRequest<EitherError<IItem>>; using RenameItemRequest = IRequest<EitherError<IItem>>;
using GeneralDataRequest = IRequest<EitherError<GeneralData>>;
using OperationSet = uint32_t; using OperationSet = uint32_t;
...@@ -462,6 +463,9 @@ class ICloudProvider { ...@@ -462,6 +463,9 @@ class ICloudProvider {
IItem::Pointer parent, const std::string& path, IItem::Pointer parent, const std::string& path,
const std::string& filename, const std::string& filename,
UploadFileCallback callback = [](EitherError<IItem>) {}) = 0; UploadFileCallback callback = [](EitherError<IItem>) {}) = 0;
virtual GeneralDataRequest::Pointer getGeneralDataAsync(
GeneralDataCallback = [](EitherError<GeneralData>) {}) = 0;
}; };
} // namespace cloudstorage } // namespace cloudstorage
......
...@@ -41,6 +41,12 @@ class Either; ...@@ -41,6 +41,12 @@ class Either;
template <class T> template <class T>
using EitherError = Either<Error, T>; using EitherError = Either<Error, T>;
struct GeneralData {
std::string username_;
uint64_t space_total_;
uint64_t space_used_;
};
struct PageData { struct PageData {
std::vector<IItem::Pointer> items_; std::vector<IItem::Pointer> items_;
std::string next_token_; // empty if no next page std::string next_token_; // empty if no next page
...@@ -236,6 +242,7 @@ using ListDirectoryCallback = ...@@ -236,6 +242,7 @@ using ListDirectoryCallback =
using DownloadFileCallback = std::function<void(EitherError<void>)>; using DownloadFileCallback = std::function<void(EitherError<void>)>;
using UploadFileCallback = std::function<void(EitherError<IItem>)>; using UploadFileCallback = std::function<void(EitherError<IItem>)>;
using GetThumbnailCallback = std::function<void(EitherError<void>)>; using GetThumbnailCallback = std::function<void(EitherError<void>)>;
using GeneralDataCallback = std::function<void(EitherError<GeneralData>)>;
} // namespace cloudstorage } // namespace cloudstorage
......
...@@ -310,5 +310,6 @@ template class Request<EitherError<std::string>>; ...@@ -310,5 +310,6 @@ template class Request<EitherError<std::string>>;
template class Request<EitherError<IItem>>; template class Request<EitherError<IItem>>;
template class Request<EitherError<std::vector<IItem::Pointer>>>; template class Request<EitherError<std::vector<IItem::Pointer>>>;
template class Request<EitherError<void>>; template class Request<EitherError<void>>;
template class Request<EitherError<GeneralData>>;
} // namespace cloudstorage } // namespace cloudstorage
...@@ -161,6 +161,11 @@ class CloudProviderWrapper : public ICloudProvider { ...@@ -161,6 +161,11 @@ class CloudProviderWrapper : public ICloudProvider {
return p_->uploadFileAsync(parent, path, filename, callback); return p_->uploadFileAsync(parent, path, filename, callback);
} }
GeneralDataRequest::Pointer getGeneralDataAsync(
GeneralDataCallback callback) override {
return p_->getGeneralDataAsync(callback);
}
private: private:
std::shared_ptr<CloudProvider> p_; std::shared_ptr<CloudProvider> p_;
}; };
......
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