This repository has been archived by the owner on Mar 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
RedmineClient.cpp
62 lines (48 loc) · 1.5 KB
/
RedmineClient.cpp
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
#include "RedmineClient.hpp"
#include "KeyAuthenticator.hpp"
#include "PasswordAuthenticator.hpp"
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
RedmineClient::RedmineClient(QUrl url, QString apiKey, bool checkSsl, QObject* parent) : QObject(parent), _url(url) {
_authenticator = new KeyAuthenticator(apiKey.toAscii());
init();
}
RedmineClient::RedmineClient(QUrl url, QString login, QString password, bool checkSsl, QObject* parent) : QObject(parent), _url(url) {
_authenticator = new PasswordAuthenticator(login, password);
init();
}
RedmineClient::~RedmineClient() {
delete _nma;
delete _authenticator;
}
void RedmineClient::init() {
_nma = new QNetworkAccessManager;
_ua = "redmine-qt";
}
void RedmineClient::setUserAgent(QByteArray ua) {
_ua = ua;
}
void RedmineClient::sendRequest(QUrl url, EMode mode, const QByteArray& requestData) {
QByteArray postDataSize = QByteArray::number(requestData.size());
QNetworkRequest request(url);
request.setRawHeader("User-Agent", _ua);
request.setRawHeader("X-Custom-User-Agent", _ua);
request.setRawHeader("Content-Type", "text/xml");
request.setRawHeader("Content-Length", postDataSize);
_authenticator->addAuthentication(&request);
QNetworkReply* reply = NULL;
switch (mode) {
case GET:
reply = _nma->get(request);
break;
case POST:
reply = _nma->post(request, requestData);
break;
case PUT:
reply = _nma->put(request, requestData);
break;
case DELETE:
reply = _nma->deleteResource(request);
break;
}
}