From e1ec6ddaddfc4d61c2240cc8f99c5342e5b75867 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Mon, 15 Feb 2021 12:55:17 +0100 Subject: [PATCH] work on feedly --- .../desktop/com.github.rssguard.appdata.xml | 2 +- resources/scripts/7za | 2 +- src/librssguard/services/feedly/definitions.h | 1 + .../services/feedly/feedlynetwork.cpp | 58 ++++++++++++++++++- .../services/feedly/feedlynetwork.h | 6 +- 5 files changed, 64 insertions(+), 5 deletions(-) diff --git a/resources/desktop/com.github.rssguard.appdata.xml b/resources/desktop/com.github.rssguard.appdata.xml index f9c88e647..af149a451 100644 --- a/resources/desktop/com.github.rssguard.appdata.xml +++ b/resources/desktop/com.github.rssguard.appdata.xml @@ -30,7 +30,7 @@ https://martinrotter.github.io/donate/ - + none diff --git a/resources/scripts/7za b/resources/scripts/7za index 9c10723bf..47f412575 160000 --- a/resources/scripts/7za +++ b/resources/scripts/7za @@ -1 +1 @@ -Subproject commit 9c10723bfbaf6cb85107d6ee16e0324e9e487749 +Subproject commit 47f4125753452eff8800dbd6600c5a05540b15d9 diff --git a/src/librssguard/services/feedly/definitions.h b/src/librssguard/services/feedly/definitions.h index ce457732c..848a41498 100755 --- a/src/librssguard/services/feedly/definitions.h +++ b/src/librssguard/services/feedly/definitions.h @@ -18,5 +18,6 @@ #define FEEDLY_API_URL_AUTH "auth/auth" #define FEEDLY_API_URL_TOKEN "auth/token" #define FEEDLY_API_URL_PROFILE "profile" +#define FEEDLY_API_URL_COLLETIONS "collections" #endif // FEEDLY_DEFINITIONS_H diff --git a/src/librssguard/services/feedly/feedlynetwork.cpp b/src/librssguard/services/feedly/feedlynetwork.cpp index 52a38acda..9e737ffab 100755 --- a/src/librssguard/services/feedly/feedlynetwork.cpp +++ b/src/librssguard/services/feedly/feedlynetwork.cpp @@ -44,13 +44,64 @@ FeedlyNetwork::FeedlyNetwork(QObject* parent) #endif } -RootItem* FeedlyNetwork::personalCollections(bool obtain_icons, const QNetworkProxy& proxy) { +RootItem* FeedlyNetwork::collections(bool obtain_icons) { QString bear = bearer(); if (bear.isEmpty()) { qCriticalNN << LOGSEC_FEEDLY << "Cannot obtain personal collections, because bearer is empty."; throw NetworkException(QNetworkReply::NetworkError::AuthenticationRequiredError); } + + QString target_url = fullUrl(Service::Collections); + int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt(); + QByteArray output_msgs; + auto result = NetworkFactory::performNetworkOperation(target_url, + timeout, + {}, + output_msgs, + QNetworkAccessManager::Operation::GetOperation, + { bearerHeader(bear) }, + false, + {}, + {}, + m_service->networkProxy()); + + if (result.first != QNetworkReply::NetworkError::NoError) { + throw NetworkException(result.first); + } + + return decodeCollections(output_msgs); +} + +RootItem* FeedlyNetwork::decodeCollections(const QByteArray& json, bool obtain_url) const { + QJsonDocument doc = QJsonDocument::fromJson(json); + auto* parent = new RootItem(); + QList used_feeds; + + for (const QJsonValue& cat : doc.array()) { + QJsonObject cat_obj = cat.toObject(); + auto* category = new Category(parent); + + category->setTitle(cat_obj["label"].toString()); + category->setCustomId(cat_obj["id"].toString()); + + for (const QJsonValue& fee : cat["feeds"].toArray()) { + QJsonObject fee_obj = fee.toObject(); + auto* feed = new FeedlyFeed(category); + + feed->setTitle(fee_obj["title"].toString()); + feed->setDescription(fee_obj["description"].toString()); + feed->setCustomId(fee_obj["id"].toString()); + + if (obtain_url) { + // TODO: TODO + } + } + + parent->appendChild(category); + } + + return parent; } QVariantHash FeedlyNetwork::profile(const QNetworkProxy& network_proxy) { @@ -161,9 +212,12 @@ void FeedlyNetwork::setOauth(OAuth2Service* oauth) { QString FeedlyNetwork::fullUrl(FeedlyNetwork::Service service) const { switch (service) { - case FeedlyNetwork::Service::Profile: + case Service::Profile: return QSL(FEEDLY_API_URL_BASE) + FEEDLY_API_URL_PROFILE; + case Service::Collections: + return QSL(FEEDLY_API_URL_BASE) + FEEDLY_API_URL_COLLETIONS; + default: return FEEDLY_API_URL_BASE; } diff --git a/src/librssguard/services/feedly/feedlynetwork.h b/src/librssguard/services/feedly/feedlynetwork.h index 206008a1b..54bb8736d 100755 --- a/src/librssguard/services/feedly/feedlynetwork.h +++ b/src/librssguard/services/feedly/feedlynetwork.h @@ -23,6 +23,8 @@ class FeedlyNetwork : public QObject { // API operations. QVariantHash profile(const QNetworkProxy& network_proxy); + RootItem* collections(bool obtain_icons); + // Getters and setters. QString username() const; void setUsername(const QString& username); @@ -47,11 +49,13 @@ class FeedlyNetwork : public QObject { private: enum class Service { - Profile + Profile, + Collections }; QString fullUrl(Service service) const; QString bearer() const; + RootItem* decodeCollections(const QByteArray& json, bool obtain_url) const; QPair bearerHeader(const QString& bearer) const; private: