added DELETE and PUT methods

This commit is contained in:
Morgan McMillian 2016-09-30 14:21:39 -07:00
parent c3fc131c22
commit e69b3513a4
3 changed files with 21 additions and 6 deletions

View file

@ -228,7 +228,7 @@ void KQOAuthManager::executeRequest(KQOAuthRequest *request) {
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
this, SLOT(slotError(QNetworkReply::NetworkError)));
} else if (request->httpMethod() == KQOAuthRequest::POST) {
} else if (request->httpMethod() == KQOAuthRequest::POST || request->httpMethod() == KQOAuthRequest::DELETE || request->httpMethod() == KQOAuthRequest::PUT) {
networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, request->contentType());
@ -237,7 +237,11 @@ void KQOAuthManager::executeRequest(KQOAuthRequest *request) {
qDebug() << networkRequest.rawHeader("Content-Type");
QNetworkReply *reply;
if (request->contentType() == "application/x-www-form-urlencoded") {
if (request->httpMethod() == KQOAuthRequest::PUT) {
reply = d->networkManager->put(networkRequest, request->requestBody());
} else if (request->httpMethod() == KQOAuthRequest::DELETE) {
reply = d->networkManager->deleteResource(networkRequest);
} else if (request->contentType() == "application/x-www-form-urlencoded") {
reply = d->networkManager->post(networkRequest, request->requestBody());
} else {
reply = d->networkManager->post(networkRequest, request->rawData());
@ -342,8 +346,7 @@ void KQOAuthManager::executeAuthorizedRequest(KQOAuthRequest *request, int id) {
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
this, SLOT(slotError(QNetworkReply::NetworkError)));
} else if (request->httpMethod() == KQOAuthRequest::POST) {
} else if (request->httpMethod() == KQOAuthRequest::POST || request->httpMethod() == KQOAuthRequest::DELETE || request->httpMethod() == KQOAuthRequest::PUT) {
networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, request->contentType());
QByteArray argHeader;
@ -355,7 +358,11 @@ void KQOAuthManager::executeAuthorizedRequest(KQOAuthRequest *request, int id) {
qDebug() << networkRequest.rawHeader("Content-Type");
QNetworkReply *reply;
if (request->contentType() == "application/x-www-form-urlencoded") {
if (request->httpMethod() == KQOAuthRequest::PUT) {
reply = d->networkManager->put(networkRequest, request->requestBody());
} else if (request->httpMethod() == KQOAuthRequest::DELETE) {
reply = d->networkManager->deleteResource(networkRequest);
} else if (request->contentType() == "application/x-www-form-urlencoded") {
reply = d->networkManager->post(networkRequest, request->requestBody());
} else {
reply = d->networkManager->post(networkRequest, request->rawData());

View file

@ -387,6 +387,12 @@ void KQOAuthRequest::setHttpMethod(KQOAuthRequest::RequestHttpMethod httpMethod)
case KQOAuthRequest::POST:
requestHttpMethodString = "POST";
break;
case KQOAuthRequest::PUT:
requestHttpMethodString = "PUT";
break;
case KQOAuthRequest::DELETE:
requestHttpMethodString = "DELETE";
break;
default:
qWarning() << "Invalid HTTP method set.";
break;

View file

@ -54,7 +54,9 @@ public:
enum RequestHttpMethod {
GET = 0,
POST
POST,
PUT,
DELETE
};
enum RequestOAuthMethod {