Commit fcdb9f99 authored by Jesus Fernandez's avatar Jesus Fernandez

Removed init functions in examples

parent 1eaecb17
......@@ -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);
}
......@@ -68,8 +68,6 @@ signals:
void subscribed(const QUrl &url);
private:
void init();
QOAuth2AuthorizationCodeFlow oauth2;
bool permanent = false;
};
......
......@@ -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();
}
......@@ -60,8 +60,6 @@ signals:
private:
Q_DISABLE_COPY(Twitter)
void init();
QOAuthHttpServerReplyHandler *replyHandler;
QString screenName;
};
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