|
1 | 1 | #pragma once
|
2 | 2 |
|
3 |
| -#include <QNetworkAccessManager> |
4 |
| -#include <QNetworkCookieJar> |
| 3 | +#include <QJsonArray> |
5 | 4 | #include <QJsonDocument>
|
6 | 5 | #include <QJsonObject>
|
7 |
| -#include <QJsonArray> |
8 |
| -#include <QTimer> |
| 6 | +#include <QNetworkAccessManager> |
| 7 | +#include <QNetworkCookieJar> |
9 | 8 | #include <QNetworkReply>
|
| 9 | +#include <QTimer> |
10 | 10 | #include <functional>
|
11 | 11 |
|
12 | 12 | class GitHubException : public std::exception
|
13 | 13 | {
|
14 | 14 | public:
|
15 |
| - GitHubException(const QJsonObject &errorObj) |
16 |
| - : std::exception() |
| 15 | + GitHubException(const QJsonObject& errorObj) : std::exception() |
17 | 16 | {
|
18 | 17 | initMessage(errorObj);
|
19 | 18 | }
|
20 | 19 |
|
21 | 20 | virtual ~GitHubException() throw() override {}
|
22 | 21 |
|
23 |
| - virtual const char *what() const throw() |
24 |
| - { |
25 |
| - return m_Message.constData(); |
26 |
| - } |
| 22 | + virtual const char* what() const throw() { return m_Message.constData(); } |
27 | 23 |
|
28 | 24 | private:
|
29 |
| - void initMessage(const QJsonObject &obj) |
| 25 | + void initMessage(const QJsonObject& obj) |
30 | 26 | {
|
31 | 27 | if (obj.contains("http_status")) {
|
32 | 28 | m_Message = QString("HTTP Status %1: %2")
|
@@ -55,48 +51,51 @@ class GitHub : public QObject
|
55 | 51 | Q_OBJECT
|
56 | 52 |
|
57 | 53 | public:
|
58 |
| - enum class Method { GET, POST }; |
| 54 | + enum class Method |
| 55 | + { |
| 56 | + GET, |
| 57 | + POST |
| 58 | + }; |
59 | 59 |
|
60 |
| - struct Repository { |
61 |
| - Repository(const QString &owner, const QString &project) |
62 |
| - : owner(owner) |
63 |
| - , project(project) |
64 |
| - { |
65 |
| - } |
| 60 | + struct Repository |
| 61 | + { |
| 62 | + Repository(const QString& owner, const QString& project) |
| 63 | + : owner(owner), project(project) |
| 64 | + {} |
66 | 65 | QString owner;
|
67 | 66 | QString project;
|
68 | 67 | };
|
69 | 68 |
|
70 | 69 | public:
|
71 |
| - GitHub(const char *clientId = nullptr); |
| 70 | + GitHub(const char* clientId = nullptr); |
72 | 71 | ~GitHub();
|
73 | 72 |
|
74 |
| - QJsonArray releases(const Repository &repo); |
75 |
| - void releases(const Repository &repo, |
76 |
| - const std::function<void (const QJsonArray &)> &callback); |
| 73 | + QJsonArray releases(const Repository& repo); |
| 74 | + void releases(const Repository& repo, |
| 75 | + const std::function<void(const QJsonArray&)>& callback); |
77 | 76 |
|
78 | 77 | private:
|
79 |
| - QJsonDocument request(Method method, const QString &path, |
80 |
| - const QByteArray &data, bool relative); |
81 |
| - void request(Method method, const QString &path, const QByteArray &data, |
82 |
| - const std::function<void (const QJsonDocument &)> &callback, |
| 78 | + QJsonDocument request(Method method, const QString& path, const QByteArray& data, |
| 79 | + bool relative); |
| 80 | + void request(Method method, const QString& path, const QByteArray& data, |
| 81 | + const std::function<void(const QJsonDocument&)>& callback, |
83 | 82 | bool relative);
|
84 | 83 |
|
85 |
| - QJsonDocument handleReply(QNetworkReply *reply); |
86 |
| - QNetworkReply *genReply(Method method, const QString &path, |
87 |
| - const QByteArray &data, bool relative); |
| 84 | + QJsonDocument handleReply(QNetworkReply* reply); |
| 85 | + QNetworkReply* genReply(Method method, const QString& path, const QByteArray& data, |
| 86 | + bool relative); |
88 | 87 |
|
89 | 88 | private:
|
90 | 89 | struct Request
|
91 | 90 | {
|
92 | 91 | Method method = Method::GET;
|
93 | 92 | QByteArray data;
|
94 |
| - std::function<void (const QJsonDocument &)> callback; |
95 |
| - QTimer* timer = nullptr; |
| 93 | + std::function<void(const QJsonDocument&)> callback; |
| 94 | + QTimer* timer = nullptr; |
96 | 95 | QNetworkReply* reply = nullptr;
|
97 | 96 | };
|
98 | 97 |
|
99 |
| - QNetworkAccessManager *m_AccessManager; |
| 98 | + QNetworkAccessManager* m_AccessManager; |
100 | 99 |
|
101 | 100 | // remember the replies that are in flight and delete them in the destructor
|
102 | 101 | std::vector<QNetworkReply*> m_replies;
|
|
0 commit comments