Commit 85c7bc17 authored by Paweł Wegner's avatar Paweł Wegner

YouTube: implemented getGeneralData.

parent 913c8d63
......@@ -379,6 +379,10 @@ IHttpRequest::Pointer YouTube::getItemDataRequest(const std::string& full_id,
}
}
IHttpRequest::Pointer YouTube::getGeneralDataRequest(std::ostream&) const {
return http()->create("https://www.googleapis.com/plus/v1/people/me");
}
IHttpRequest::Pointer YouTube::listDirectoryRequest(
const IItem& item, const std::string& page_token, std::ostream&) const {
if (item.id() == rootDirectory()->id() || item.id() == AUDIO_DIRECTORY_ID ||
......@@ -467,6 +471,17 @@ std::vector<IItem::Pointer> YouTube::listDirectoryResponse(
return result;
}
GeneralData YouTube::getGeneralDataResponse(std::istream& response) const {
auto json = util::json::from_stream(response);
GeneralData data;
data.space_total_ = 0;
data.space_used_ = 0;
for (auto&& j : json["emails"])
if (j["type"].asString() == "account")
data.username_ = j["value"].asString();
return data;
}
Item::Pointer YouTube::toItem(const Json::Value& v, std::string kind,
bool audio, bool high_quality) const {
if (kind == "youtube#playlistListResponse") {
......@@ -501,7 +516,8 @@ Item::Pointer YouTube::toItem(const Json::Value& v, std::string kind,
std::string YouTube::Auth::authorizeLibraryUrl() const {
return "https://accounts.google.com/o/oauth2/auth?client_id=" + client_id() +
"&redirect_uri=" + redirect_uri() +
"&scope=https://www.googleapis.com/auth/youtube.readonly"
"&scope=https://www.googleapis.com/auth/youtube.readonly+https://"
"www.googleapis.com/auth/plus.profile.emails.read"
"&response_type=code&access_type=offline&prompt=consent"
"&state=" +
state();
......
......@@ -55,11 +55,14 @@ class YouTube : public CloudProvider {
IHttpRequest::Pointer getItemDataRequest(const std::string& full_id,
std::ostream&) const override;
IHttpRequest::Pointer getGeneralDataRequest(std::ostream&) const override;
IItem::Pointer getItemDataResponse(std::istream& response, bool audio,
bool high_quality) const;
std::vector<IItem::Pointer> listDirectoryResponse(
const IItem& directory, std::istream&,
std::string& next_page_token) const override;
GeneralData getGeneralDataResponse(std::istream& response) const override;
Item::Pointer toItem(const Json::Value&, std::string kind, bool audio,
bool high_quality) const;
......
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