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

GooglePhotos: implemented getGeneralData.

parent 85c7bc17
......@@ -153,6 +153,14 @@ IHttpRequest::Pointer GooglePhotos::uploadFileRequest(
return request;
}
IHttpRequest::Pointer GooglePhotos::getGeneralDataRequest(
std::ostream &) const {
auto r = http()->create(endpoint() + "/feed/api/user/default");
r->setParameter("fields",
"gphoto:quotalimit,gphoto:quotacurrent,gphoto:nickname");
return r;
}
std::vector<IItem::Pointer> GooglePhotos::listDirectoryResponse(
const IItem &, std::istream &stream, std::string &) const {
std::stringstream sstream;
......@@ -169,6 +177,27 @@ std::vector<IItem::Pointer> GooglePhotos::listDirectoryResponse(
return result;
}
GeneralData GooglePhotos::getGeneralDataResponse(std::istream &response) const {
std::stringstream sstream;
sstream << response.rdbuf();
tinyxml2::XMLDocument document;
if (document.Parse(sstream.str().c_str(), sstream.str().size()) !=
tinyxml2::XML_SUCCESS)
throw std::logic_error("invalid xml");
auto quota_limit =
document.RootElement()->FirstChildElement("gphoto:quotalimit");
auto quota_current =
document.RootElement()->FirstChildElement("gphoto:quotacurrent");
auto user = document.RootElement()->FirstChildElement("gphoto:nickname");
if (!quota_limit || !quota_current || !user)
throw std::logic_error("invalid xml");
GeneralData result;
result.space_total_ = std::stoull(quota_limit->GetText());
result.space_used_ = std::stoull(quota_current->GetText());
result.username_ = user->GetText();
return result;
}
ICloudProvider::DownloadFileRequest::Pointer GooglePhotos::downloadFileAsync(
IItem::Pointer i, IDownloadFileCallback::Pointer cb, Range range) {
return std::make_shared<DownloadFileFromUrlRequest>(shared_from_this(), i, cb,
......
......@@ -47,8 +47,10 @@ class GooglePhotos : public CloudProvider {
IHttpRequest::Pointer uploadFileRequest(
const IItem& directory, const std::string& filename,
std::ostream& prefix_stream, std::ostream& suffix_stream) const override;
IHttpRequest::Pointer getGeneralDataRequest(std::ostream&) const override;
std::vector<IItem::Pointer> listDirectoryResponse(
const IItem&, std::istream&, std::string& next_page_token) const override;
GeneralData getGeneralDataResponse(std::istream& response) const override;
DownloadFileRequest::Pointer downloadFileAsync(IItem::Pointer,
IDownloadFileCallback::Pointer,
Range) override;
......
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