diff --git a/examples/redditclient/redditwrapper.cpp b/examples/redditclient/redditwrapper.cpp index 02d51c84dd99c0469e0e4c7101a93e7e2c7a7da7..d9e229f5b5d536b59038e41a268e60e14d339923 100644 --- a/examples/redditclient/redditwrapper.cpp +++ b/examples/redditclient/redditwrapper.cpp @@ -49,14 +49,28 @@ const QUrl liveThreadsUrl("https://oauth.reddit.com/live/XXXX/about.json"); RedditWrapper::RedditWrapper(QObject *parent) : QObject(parent) { - init(); + oauth2.setPort(1337); + oauth2.setAuthorizationUrl(QUrl("https://www.reddit.com/api/v1/authorize")); + oauth2.setAccessTokenUrl(QUrl("https://www.reddit.com/api/v1/access_token")); + oauth2.setScope("identity read"); + + connect(&oauth2, &QOAuth2AuthorizationCodeFlow::statusChanged, [=]( + QAbstractOAuth::Status status) { + if (status == QAbstractOAuth::Status::Granted) + emit authenticated(); + }); + oauth2.setModifyParametersFunction([&](QAbstractOAuth::Stage stage, QVariantMap *parameters) { + if (stage == QAbstractOAuth::Stage::RequestingAuthorization && isPermanent()) + parameters->insert("duration", "permanent"); + }); + connect(&oauth2, &QOAuth2AuthorizationCodeFlow::authorizationRequested, + &QDesktopServices::openUrl); } RedditWrapper::RedditWrapper(const QString &clientIdentifier, QObject *parent) - : QObject(parent) + : RedditWrapper(parent) { oauth2.setClientIdentifier(clientIdentifier); - init(); } QNetworkReply *RedditWrapper::requestHotThreads() @@ -120,23 +134,3 @@ void RedditWrapper::subscribeToLiveUpdates() emit subscribed(websocketUrl); }); } - -void RedditWrapper::init() -{ - oauth2.setPort(1337); - oauth2.setAuthorizationUrl(QUrl("https://www.reddit.com/api/v1/authorize")); - oauth2.setAccessTokenUrl(QUrl("https://www.reddit.com/api/v1/access_token")); - oauth2.setScope("identity read"); - - connect(&oauth2, &QOAuth2AuthorizationCodeFlow::statusChanged, [=]( - QAbstractOAuth::Status status) { - if (status == QAbstractOAuth::Status::Granted) - emit authenticated(); - }); - oauth2.setModifyParametersFunction([&](QAbstractOAuth::Stage stage, QVariantMap *parameters) { - if (stage == QAbstractOAuth::Stage::RequestingAuthorization && isPermanent()) - parameters->insert("duration", "permanent"); - }); - connect(&oauth2, &QOAuth2AuthorizationCodeFlow::authorizationRequested, - &QDesktopServices::openUrl); -} diff --git a/examples/redditclient/redditwrapper.h b/examples/redditclient/redditwrapper.h index 0d2dc7a36ab36f0b8b0bdaac1a732db90c153928..ed6325109b0dfc062324ab0a6930f3e1b0a4da45 100644 --- a/examples/redditclient/redditwrapper.h +++ b/examples/redditclient/redditwrapper.h @@ -68,8 +68,6 @@ signals: void subscribed(const QUrl &url); private: - void init(); - QOAuth2AuthorizationCodeFlow oauth2; bool permanent = false; }; diff --git a/examples/twittertimeline/twitter.cpp b/examples/twittertimeline/twitter.cpp index 3cb088262ecd8871e28cf7428c3c512d7f028575..ba336a62ce4a9b8c25aa2a8b03e340a16b5d1770 100644 --- a/examples/twittertimeline/twitter.cpp +++ b/examples/twittertimeline/twitter.cpp @@ -43,32 +43,8 @@ #include <QtCore> #include <QtNetwork> -Twitter::Twitter(QObject *parent) - : QOAuth1(parent) -{ - init(); -} - -Twitter::Twitter(const QPair<QString, QString> &clientCredentials, QObject *parent) - : QOAuth1(parent) -{ - init(); - setClientCredentials(clientCredentials); - grant(); -} - -Twitter::Twitter(const QString &screenName, - const QPair<QString, QString> &clientCredentials, - QObject *parent) - : QOAuth1(parent) -{ - Twitter::screenName = screenName; - init(); - setClientCredentials(clientCredentials); - grant(); -} - -void Twitter::init() +Twitter::Twitter(QObject *parent) : + QOAuth1(parent) { replyHandler = new QOAuthHttpServerReplyHandler(this); setReplyHandler(replyHandler); @@ -89,3 +65,20 @@ void Twitter::init() connect(this, &QOAuth1::granted, this, &Twitter::authenticated); } + +Twitter::Twitter(const QPair<QString, QString> &clientCredentials, QObject *parent) : + Twitter(parent) +{ + setClientCredentials(clientCredentials); + grant(); +} + +Twitter::Twitter(const QString &screenName, + const QPair<QString, QString> &clientCredentials, + QObject *parent) : + Twitter(parent) +{ + Twitter::screenName = screenName; + setClientCredentials(clientCredentials); + grant(); +} diff --git a/examples/twittertimeline/twitter.h b/examples/twittertimeline/twitter.h index d5106ef5537ef509aaef5224393d84b3f792c378..5e48eb42f8cdc93ce88610e58d0b50d03e5b1202 100644 --- a/examples/twittertimeline/twitter.h +++ b/examples/twittertimeline/twitter.h @@ -60,8 +60,6 @@ signals: private: Q_DISABLE_COPY(Twitter) - void init(); - QOAuthHttpServerReplyHandler *replyHandler; QString screenName; };