work on feedly

This commit is contained in:
Martin Rotter 2021-02-15 12:55:17 +01:00
parent 6f21368e19
commit e1ec6ddadd
5 changed files with 64 additions and 5 deletions

View File

@ -30,7 +30,7 @@
<url type="donation">https://martinrotter.github.io/donate/</url> <url type="donation">https://martinrotter.github.io/donate/</url>
<content_rating type="oars-1.1" /> <content_rating type="oars-1.1" />
<releases> <releases>
<release version="3.8.4" date="2021-02-12"/> <release version="3.8.4" date="2021-02-15"/>
</releases> </releases>
<content_rating type="oars-1.0"> <content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute> <content_attribute id="violence-cartoon">none</content_attribute>

@ -1 +1 @@
Subproject commit 9c10723bfbaf6cb85107d6ee16e0324e9e487749 Subproject commit 47f4125753452eff8800dbd6600c5a05540b15d9

View File

@ -18,5 +18,6 @@
#define FEEDLY_API_URL_AUTH "auth/auth" #define FEEDLY_API_URL_AUTH "auth/auth"
#define FEEDLY_API_URL_TOKEN "auth/token" #define FEEDLY_API_URL_TOKEN "auth/token"
#define FEEDLY_API_URL_PROFILE "profile" #define FEEDLY_API_URL_PROFILE "profile"
#define FEEDLY_API_URL_COLLETIONS "collections"
#endif // FEEDLY_DEFINITIONS_H #endif // FEEDLY_DEFINITIONS_H

View File

@ -44,13 +44,64 @@ FeedlyNetwork::FeedlyNetwork(QObject* parent)
#endif #endif
} }
RootItem* FeedlyNetwork::personalCollections(bool obtain_icons, const QNetworkProxy& proxy) { RootItem* FeedlyNetwork::collections(bool obtain_icons) {
QString bear = bearer(); QString bear = bearer();
if (bear.isEmpty()) { if (bear.isEmpty()) {
qCriticalNN << LOGSEC_FEEDLY << "Cannot obtain personal collections, because bearer is empty."; qCriticalNN << LOGSEC_FEEDLY << "Cannot obtain personal collections, because bearer is empty.";
throw NetworkException(QNetworkReply::NetworkError::AuthenticationRequiredError); 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<QString> 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) { QVariantHash FeedlyNetwork::profile(const QNetworkProxy& network_proxy) {
@ -161,9 +212,12 @@ void FeedlyNetwork::setOauth(OAuth2Service* oauth) {
QString FeedlyNetwork::fullUrl(FeedlyNetwork::Service service) const { QString FeedlyNetwork::fullUrl(FeedlyNetwork::Service service) const {
switch (service) { switch (service) {
case FeedlyNetwork::Service::Profile: case Service::Profile:
return QSL(FEEDLY_API_URL_BASE) + FEEDLY_API_URL_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: default:
return FEEDLY_API_URL_BASE; return FEEDLY_API_URL_BASE;
} }

View File

@ -23,6 +23,8 @@ class FeedlyNetwork : public QObject {
// API operations. // API operations.
QVariantHash profile(const QNetworkProxy& network_proxy); QVariantHash profile(const QNetworkProxy& network_proxy);
RootItem* collections(bool obtain_icons);
// Getters and setters. // Getters and setters.
QString username() const; QString username() const;
void setUsername(const QString& username); void setUsername(const QString& username);
@ -47,11 +49,13 @@ class FeedlyNetwork : public QObject {
private: private:
enum class Service { enum class Service {
Profile Profile,
Collections
}; };
QString fullUrl(Service service) const; QString fullUrl(Service service) const;
QString bearer() const; QString bearer() const;
RootItem* decodeCollections(const QByteArray& json, bool obtain_url) const;
QPair<QByteArray, QByteArray> bearerHeader(const QString& bearer) const; QPair<QByteArray, QByteArray> bearerHeader(const QString& bearer) const;
private: private: