-
Notifications
You must be signed in to change notification settings - Fork 1
/
diceapi.h
68 lines (55 loc) · 1.58 KB
/
diceapi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef DICEAPI_H
#define DICEAPI_H
#include <QObject>
#include <QUrl>
#include <QUrlQuery>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QAuthenticator>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QEventLoop>
const QUrl authUrl = QUrl("https://secure.dice.com/oauth/token?grant_type=client_credentials");
const QString apiUrl = "https://api.dice.com/jobs";
const QString userName = "diceHackathon";
const QString password = "9fc52528-080d-4f0c-becd-45acf46bac4e";
const QString APIUserName = "bearer";
class DiceAuthorizer : public QObject
{
Q_OBJECT
private:
QNetworkAccessManager mgr;
QString token;
public:
explicit DiceAuthorizer(QObject* parent = 0);
void authorize(const QUrl &authUrl);
const QString getToken() const;
public slots:
void setCredentials(QNetworkReply *reply, QAuthenticator *authenticator);
void processReply(QNetworkReply*);
};
class DiceAPI : public QObject
{
Q_OBJECT
public:
explicit DiceAPI(QObject* parent = 0);
DiceAPI(QString token, QObject* parent = 0);
QJsonObject getJobsList(const QString& query);
void getJobInfo(const QString& jobId);
void setToken(const QString& token);
signals:
void jobInfoRecevied(const QJsonObject &);
void jobListRecevied(const QJsonObject &);
public slots:
void replyRecieved(QNetworkReply*);
void setCredentials(QNetworkReply*,QAuthenticator*);
private slots:
void onReplyFinished();
private:
QString token;
QJsonObject JSONReply;
QNetworkAccessManager mgr;
};
#endif // DICEAPI_H