/** * OpenAPI Petstore * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. * * The version of the OpenAPI document: 1.0.0 * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ #include "PFXPetApi.h" #include "PFXServerConfiguration.h" #include #include namespace test_namespace { PFXPetApi::PFXPetApi(const int timeOut) : _timeOut(timeOut), _manager(nullptr), _isResponseCompressionEnabled(false), _isRequestCompressionEnabled(false) { initializeServerConfigs(); } PFXPetApi::~PFXPetApi() { } void PFXPetApi::initializeServerConfigs() { //Default server QList defaultConf = QList(); //varying endpoint server defaultConf.append(PFXServerConfiguration( QUrl("http://petstore.swagger.io/v2"), "No description provided", QMap())); defaultConf.append(PFXServerConfiguration( QUrl("http://localhost:8080/v2"), "No description provided", QMap())); _serverConfigs.insert("addPet", defaultConf); _serverIndices.insert("addPet", 0); _serverConfigs.insert("allPets", defaultConf); _serverIndices.insert("allPets", 0); _serverConfigs.insert("deletePet", defaultConf); _serverIndices.insert("deletePet", 0); _serverConfigs.insert("findPetsByStatus", defaultConf); _serverIndices.insert("findPetsByStatus", 0); _serverConfigs.insert("findPetsByTags", defaultConf); _serverIndices.insert("findPetsByTags", 0); _serverConfigs.insert("getPetById", defaultConf); _serverIndices.insert("getPetById", 0); _serverConfigs.insert("updatePet", defaultConf); _serverIndices.insert("updatePet", 0); _serverConfigs.insert("updatePetWithForm", defaultConf); _serverIndices.insert("updatePetWithForm", 0); _serverConfigs.insert("uploadFile", defaultConf); _serverIndices.insert("uploadFile", 0); } /** * returns 0 on success and -1, -2 or -3 on failure. * -1 when the variable does not exist and -2 if the value is not defined in the enum and -3 if the operation or server index is not found */ int PFXPetApi::setDefaultServerValue(int serverIndex, const QString &operation, const QString &variable, const QString &value) { auto it = _serverConfigs.find(operation); if (it != _serverConfigs.end() && serverIndex < it.value().size()) { return _serverConfigs[operation][serverIndex].setDefaultValue(variable,value); } return -3; } void PFXPetApi::setServerIndex(const QString &operation, int serverIndex) { if (_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size()) { _serverIndices[operation] = serverIndex; } } void PFXPetApi::setApiKey(const QString &apiKeyName, const QString &apiKey) { _apiKeys.insert(apiKeyName, apiKey); } void PFXPetApi::setBearerToken(const QString &token) { _bearerToken = token; } void PFXPetApi::setUsername(const QString &username) { _username = username; } void PFXPetApi::setPassword(const QString &password) { _password = password; } void PFXPetApi::setTimeOut(const int timeOut) { _timeOut = timeOut; } void PFXPetApi::setWorkingDirectory(const QString &path) { _workingDirectory = path; } void PFXPetApi::setNetworkAccessManager(QNetworkAccessManager* manager) { _manager = manager; } /** * Appends a new ServerConfiguration to the config map for a specific operation. * @param operation The id to the target operation. * @param url A string that contains the URL of the server * @param description A String that describes the server * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. * returns the index of the new server config on success and -1 if the operation is not found */ int PFXPetApi::addServerConfiguration(const QString &operation, const QUrl &url, const QString &description, const QMap &variables) { if (_serverConfigs.contains(operation)) { _serverConfigs[operation].append(PFXServerConfiguration( url, description, variables)); return _serverConfigs[operation].size()-1; } else { return -1; } } /** * Appends a new ServerConfiguration to the config map for a all operations and sets the index to that server. * @param url A string that contains the URL of the server * @param description A String that describes the server * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. */ void PFXPetApi::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap &variables) { for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) { setServerIndex(*keyIt, addServerConfiguration(*keyIt, url, description, variables)); } } /** * Appends a new ServerConfiguration to the config map for an operations and sets the index to that server. * @param URL A string that contains the URL of the server * @param description A String that describes the server * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. */ void PFXPetApi::setNewServer(const QString &operation, const QUrl &url, const QString &description, const QMap &variables) { setServerIndex(operation, addServerConfiguration(operation, url, description, variables)); } void PFXPetApi::addHeaders(const QString &key, const QString &value) { _defaultHeaders.insert(key, value); } void PFXPetApi::enableRequestCompression() { _isRequestCompressionEnabled = true; } void PFXPetApi::enableResponseCompression() { _isResponseCompressionEnabled = true; } void PFXPetApi::abortRequests() { Q_EMIT abortRequestsSignal(); } QString PFXPetApi::getParamStylePrefix(const QString &style) { if (style == "matrix") { return ";"; } else if (style == "label") { return "."; } else if (style == "form") { return "&"; } else if (style == "simple") { return ""; } else if (style == "spaceDelimited") { return "&"; } else if (style == "pipeDelimited") { return "&"; } else { return "none"; } } QString PFXPetApi::getParamStyleSuffix(const QString &style) { if (style == "matrix") { return "="; } else if (style == "label") { return ""; } else if (style == "form") { return "="; } else if (style == "simple") { return ""; } else if (style == "spaceDelimited") { return "="; } else if (style == "pipeDelimited") { return "="; } else { return "none"; } } QString PFXPetApi::getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode) { if (style == "matrix") { return (isExplode) ? ";" + name + "=" : ","; } else if (style == "label") { return (isExplode) ? "." : ","; } else if (style == "form") { return (isExplode) ? "&" + name + "=" : ","; } else if (style == "simple") { return ","; } else if (style == "spaceDelimited") { return (isExplode) ? "&" + name + "=" : " "; } else if (style == "pipeDelimited") { return (isExplode) ? "&" + name + "=" : "|"; } else if (style == "deepObject") { return (isExplode) ? "&" : "none"; } else { return "none"; } } void PFXPetApi::addPet(const PFXPet &pfx_pet) { QString fullPath = QString(_serverConfigs["addPet"][_serverIndices.value("addPet")].URL()+"/pet"); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "POST"); { QByteArray output = pfx_pet.asJson().toUtf8(); input.request_body.append(output); } for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) { input.headers.insert(keyValueIt->first, keyValueIt->second); } connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::addPetCallback); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); connect(worker, &QObject::destroyed, this, [this] { if (findChildren().count() == 0) { Q_EMIT allPendingRequestsCompleted(); } }); _OauthMethod = 1; _implicitFlow.link(); _passwordFlow.unlink(); _authFlow.unlink(); _credentialFlow.unlink(); QStringList scope; scope.append("write:pets"); scope.append("read:pets"); auto token = _implicitFlow.getToken(scope.join(" ")); if(token.isValid()) input.headers.insert("Authorization", "Bearer " + token.getToken()); _latestWorker = new PFXHttpRequestWorker(this, _manager); _latestWorker->setTimeOut(_timeOut); _latestWorker->setWorkingDirectory(_workingDirectory); connect(_latestWorker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::addPetCallback); connect(this, &PFXPetApi::abortRequestsSignal, _latestWorker, &QObject::deleteLater); connect(_latestWorker, &QObject::destroyed, this, [this] { if(findChildren().count() == 0){ Q_EMIT allPendingRequestsCompleted(); } }); _latestInput = input; _latestScope = scope; worker->execute(&input); } void PFXPetApi::addPetCallback(PFXHttpRequestWorker *worker) { QString error_str = worker->error_str; QNetworkReply::NetworkError error_type = worker->error_type; if (worker->error_type != QNetworkReply::NoError) { error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response)); } worker->deleteLater(); if (worker->error_type == QNetworkReply::NoError) { Q_EMIT addPetSignal(); Q_EMIT addPetSignalFull(worker); } else if(worker->error_type == QNetworkReply::AuthenticationRequiredError){ connect(&_implicitFlow, SIGNAL(tokenReceived()), this, SLOT(tokenAvailable())); QStringList scope; scope.append("write:pets"); scope.append("read:pets"); QString scopeStr = scope.join(" "); QString authorizationUrl("http://petstore.swagger.io/api/oauth/dialog"); //TODO get clientID and Secret and state in the config? https://swagger.io/docs/specification/authentication/oauth2/ states that you should do as you like _implicitFlow.setVariables(authorizationUrl, scopeStr, "state" , "http://127.0.0.1:9999", "clientId"); Q_EMIT _implicitFlow.authenticationNeeded(); } else { #if defined(_MSC_VER) // For MSVC #pragma warning(push) #pragma warning(disable : 4996) #elif defined(__clang__) // For Clang #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" #elif defined(__GNUC__) // For GCC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif Q_EMIT addPetSignalE(error_type, error_str); Q_EMIT addPetSignalEFull(worker, error_type, error_str); #if defined(_MSC_VER) #pragma warning(pop) #elif defined(__clang__) #pragma clang diagnostic pop #elif defined(__GNUC__) #pragma GCC diagnostic pop #endif Q_EMIT addPetSignalError(error_type, error_str); Q_EMIT addPetSignalErrorFull(worker, error_type, error_str); } } void PFXPetApi::allPets() { QString fullPath = QString(_serverConfigs["allPets"][_serverIndices.value("allPets")].URL()+"/pet/all"); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "GET"); for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) { input.headers.insert(keyValueIt->first, keyValueIt->second); } connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::allPetsCallback); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); connect(worker, &QObject::destroyed, this, [this] { if (findChildren().count() == 0) { Q_EMIT allPendingRequestsCompleted(); } }); worker->execute(&input); } void PFXPetApi::allPetsCallback(PFXHttpRequestWorker *worker) { QString error_str = worker->error_str; QNetworkReply::NetworkError error_type = worker->error_type; if (worker->error_type != QNetworkReply::NoError) { error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response)); } QSet output; QString json(worker->response); QByteArray array(json.toStdString().c_str()); QJsonDocument doc = QJsonDocument::fromJson(array); QJsonArray jsonArray = doc.array(); for (QJsonValue obj : jsonArray) { PFXPet val; ::test_namespace::fromJsonValue(val, obj); output.insert(val); } worker->deleteLater(); if (worker->error_type == QNetworkReply::NoError) { Q_EMIT allPetsSignal(output); Q_EMIT allPetsSignalFull(worker, output); } else { #if defined(_MSC_VER) // For MSVC #pragma warning(push) #pragma warning(disable : 4996) #elif defined(__clang__) // For Clang #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" #elif defined(__GNUC__) // For GCC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif Q_EMIT allPetsSignalE(output, error_type, error_str); Q_EMIT allPetsSignalEFull(worker, error_type, error_str); #if defined(_MSC_VER) #pragma warning(pop) #elif defined(__clang__) #pragma clang diagnostic pop #elif defined(__GNUC__) #pragma GCC diagnostic pop #endif Q_EMIT allPetsSignalError(output, error_type, error_str); Q_EMIT allPetsSignalErrorFull(worker, error_type, error_str); } } void PFXPetApi::deletePet(const qint64 &pet_id, const ::test_namespace::OptionalParam &api_key) { QString fullPath = QString(_serverConfigs["deletePet"][_serverIndices.value("deletePet")].URL()+"/pet/{petId}"); { QString pet_idPathParam("{"); pet_idPathParam.append("petId").append("}"); QString pathPrefix, pathSuffix, pathDelimiter; QString pathStyle = "simple"; if (pathStyle == "") pathStyle = "simple"; pathPrefix = getParamStylePrefix(pathStyle); pathSuffix = getParamStyleSuffix(pathStyle); pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false); QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix; fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); } PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "DELETE"); if (api_key.hasValue()) { if (!::test_namespace::toStringValue(api_key.value()).isEmpty()) { input.headers.insert("api_key", ::test_namespace::toStringValue(api_key.value())); } } for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) { input.headers.insert(keyValueIt->first, keyValueIt->second); } connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::deletePetCallback); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); connect(worker, &QObject::destroyed, this, [this] { if (findChildren().count() == 0) { Q_EMIT allPendingRequestsCompleted(); } }); _OauthMethod = 1; _implicitFlow.link(); _passwordFlow.unlink(); _authFlow.unlink(); _credentialFlow.unlink(); QStringList scope; scope.append("write:pets"); scope.append("read:pets"); auto token = _implicitFlow.getToken(scope.join(" ")); if(token.isValid()) input.headers.insert("Authorization", "Bearer " + token.getToken()); _latestWorker = new PFXHttpRequestWorker(this, _manager); _latestWorker->setTimeOut(_timeOut); _latestWorker->setWorkingDirectory(_workingDirectory); connect(_latestWorker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::deletePetCallback); connect(this, &PFXPetApi::abortRequestsSignal, _latestWorker, &QObject::deleteLater); connect(_latestWorker, &QObject::destroyed, this, [this] { if(findChildren().count() == 0){ Q_EMIT allPendingRequestsCompleted(); } }); _latestInput = input; _latestScope = scope; worker->execute(&input); } void PFXPetApi::deletePetCallback(PFXHttpRequestWorker *worker) { QString error_str = worker->error_str; QNetworkReply::NetworkError error_type = worker->error_type; if (worker->error_type != QNetworkReply::NoError) { error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response)); } worker->deleteLater(); if (worker->error_type == QNetworkReply::NoError) { Q_EMIT deletePetSignal(); Q_EMIT deletePetSignalFull(worker); } else if(worker->error_type == QNetworkReply::AuthenticationRequiredError){ connect(&_implicitFlow, SIGNAL(tokenReceived()), this, SLOT(tokenAvailable())); QStringList scope; scope.append("write:pets"); scope.append("read:pets"); QString scopeStr = scope.join(" "); QString authorizationUrl("http://petstore.swagger.io/api/oauth/dialog"); //TODO get clientID and Secret and state in the config? https://swagger.io/docs/specification/authentication/oauth2/ states that you should do as you like _implicitFlow.setVariables(authorizationUrl, scopeStr, "state" , "http://127.0.0.1:9999", "clientId"); Q_EMIT _implicitFlow.authenticationNeeded(); } else { #if defined(_MSC_VER) // For MSVC #pragma warning(push) #pragma warning(disable : 4996) #elif defined(__clang__) // For Clang #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" #elif defined(__GNUC__) // For GCC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif Q_EMIT deletePetSignalE(error_type, error_str); Q_EMIT deletePetSignalEFull(worker, error_type, error_str); #if defined(_MSC_VER) #pragma warning(pop) #elif defined(__clang__) #pragma clang diagnostic pop #elif defined(__GNUC__) #pragma GCC diagnostic pop #endif Q_EMIT deletePetSignalError(error_type, error_str); Q_EMIT deletePetSignalErrorFull(worker, error_type, error_str); } } void PFXPetApi::findPetsByStatus(const QList &status) { QString fullPath = QString(_serverConfigs["findPetsByStatus"][_serverIndices.value("findPetsByStatus")].URL()+"/pet/findByStatus"); QString queryPrefix, querySuffix, queryDelimiter, queryStyle; { queryStyle = "form"; if (queryStyle == "") queryStyle = "form"; queryPrefix = getParamStylePrefix(queryStyle); querySuffix = getParamStyleSuffix(queryStyle); queryDelimiter = getParamStyleDelimiter(queryStyle, "status", false); if (status.size() > 0) { if (QString("csv").indexOf("multi") == 0) { for (QString t : status) { if (fullPath.indexOf("?") > 0) fullPath.append(queryPrefix); else fullPath.append("?"); fullPath.append("status=").append(::test_namespace::toStringValue(t)); } } else if (QString("csv").indexOf("ssv") == 0) { if (fullPath.indexOf("?") > 0) fullPath.append("&"); else fullPath.append("?").append(queryPrefix).append("status").append(querySuffix); qint32 count = 0; for (QString t : status) { if (count > 0) { fullPath.append((false)? queryDelimiter : QUrl::toPercentEncoding(queryDelimiter)); } fullPath.append(::test_namespace::toStringValue(t)); count++; } } else if (QString("csv").indexOf("tsv") == 0) { if (fullPath.indexOf("?") > 0) fullPath.append("&"); else fullPath.append("?").append(queryPrefix).append("status").append(querySuffix); qint32 count = 0; for (QString t : status) { if (count > 0) { fullPath.append("\t"); } fullPath.append(::test_namespace::toStringValue(t)); count++; } } else if (QString("csv").indexOf("csv") == 0) { if (fullPath.indexOf("?") > 0) fullPath.append("&"); else fullPath.append("?").append(queryPrefix).append("status").append(querySuffix); qint32 count = 0; for (QString t : status) { if (count > 0) { fullPath.append(queryDelimiter); } fullPath.append(::test_namespace::toStringValue(t)); count++; } } else if (QString("csv").indexOf("pipes") == 0) { if (fullPath.indexOf("?") > 0) fullPath.append("&"); else fullPath.append("?").append(queryPrefix).append("status").append(querySuffix); qint32 count = 0; for (QString t : status) { if (count > 0) { fullPath.append(queryDelimiter); } fullPath.append(::test_namespace::toStringValue(t)); count++; } } else if (QString("csv").indexOf("deepObject") == 0) { if (fullPath.indexOf("?") > 0) fullPath.append("&"); else fullPath.append("?").append(queryPrefix).append("status").append(querySuffix); qint32 count = 0; for (QString t : status) { if (count > 0) { fullPath.append(queryDelimiter); } fullPath.append(::test_namespace::toStringValue(t)); count++; } } } } PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "GET"); for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) { input.headers.insert(keyValueIt->first, keyValueIt->second); } connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByStatusCallback); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); connect(worker, &QObject::destroyed, this, [this] { if (findChildren().count() == 0) { Q_EMIT allPendingRequestsCompleted(); } }); _OauthMethod = 1; _implicitFlow.link(); _passwordFlow.unlink(); _authFlow.unlink(); _credentialFlow.unlink(); QStringList scope; scope.append("write:pets"); scope.append("read:pets"); auto token = _implicitFlow.getToken(scope.join(" ")); if(token.isValid()) input.headers.insert("Authorization", "Bearer " + token.getToken()); _latestWorker = new PFXHttpRequestWorker(this, _manager); _latestWorker->setTimeOut(_timeOut); _latestWorker->setWorkingDirectory(_workingDirectory); connect(_latestWorker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByStatusCallback); connect(this, &PFXPetApi::abortRequestsSignal, _latestWorker, &QObject::deleteLater); connect(_latestWorker, &QObject::destroyed, this, [this] { if(findChildren().count() == 0){ Q_EMIT allPendingRequestsCompleted(); } }); _latestInput = input; _latestScope = scope; worker->execute(&input); } void PFXPetApi::findPetsByStatusCallback(PFXHttpRequestWorker *worker) { QString error_str = worker->error_str; QNetworkReply::NetworkError error_type = worker->error_type; if (worker->error_type != QNetworkReply::NoError) { error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response)); } QList output; QString json(worker->response); QByteArray array(json.toStdString().c_str()); QJsonDocument doc = QJsonDocument::fromJson(array); QJsonArray jsonArray = doc.array(); for (QJsonValue obj : jsonArray) { PFXPet val; ::test_namespace::fromJsonValue(val, obj); output.append(val); } worker->deleteLater(); if (worker->error_type == QNetworkReply::NoError) { Q_EMIT findPetsByStatusSignal(output); Q_EMIT findPetsByStatusSignalFull(worker, output); } else if(worker->error_type == QNetworkReply::AuthenticationRequiredError){ connect(&_implicitFlow, SIGNAL(tokenReceived()), this, SLOT(tokenAvailable())); QStringList scope; scope.append("write:pets"); scope.append("read:pets"); QString scopeStr = scope.join(" "); QString authorizationUrl("http://petstore.swagger.io/api/oauth/dialog"); //TODO get clientID and Secret and state in the config? https://swagger.io/docs/specification/authentication/oauth2/ states that you should do as you like _implicitFlow.setVariables(authorizationUrl, scopeStr, "state" , "http://127.0.0.1:9999", "clientId"); Q_EMIT _implicitFlow.authenticationNeeded(); } else { #if defined(_MSC_VER) // For MSVC #pragma warning(push) #pragma warning(disable : 4996) #elif defined(__clang__) // For Clang #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" #elif defined(__GNUC__) // For GCC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif Q_EMIT findPetsByStatusSignalE(output, error_type, error_str); Q_EMIT findPetsByStatusSignalEFull(worker, error_type, error_str); #if defined(_MSC_VER) #pragma warning(pop) #elif defined(__clang__) #pragma clang diagnostic pop #elif defined(__GNUC__) #pragma GCC diagnostic pop #endif Q_EMIT findPetsByStatusSignalError(output, error_type, error_str); Q_EMIT findPetsByStatusSignalErrorFull(worker, error_type, error_str); } } void PFXPetApi::findPetsByTags(const QList &tags) { QString fullPath = QString(_serverConfigs["findPetsByTags"][_serverIndices.value("findPetsByTags")].URL()+"/pet/findByTags"); QString queryPrefix, querySuffix, queryDelimiter, queryStyle; { queryStyle = "form"; if (queryStyle == "") queryStyle = "form"; queryPrefix = getParamStylePrefix(queryStyle); querySuffix = getParamStyleSuffix(queryStyle); queryDelimiter = getParamStyleDelimiter(queryStyle, "tags", false); if (tags.size() > 0) { if (QString("csv").indexOf("multi") == 0) { for (QString t : tags) { if (fullPath.indexOf("?") > 0) fullPath.append(queryPrefix); else fullPath.append("?"); fullPath.append("tags=").append(::test_namespace::toStringValue(t)); } } else if (QString("csv").indexOf("ssv") == 0) { if (fullPath.indexOf("?") > 0) fullPath.append("&"); else fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix); qint32 count = 0; for (QString t : tags) { if (count > 0) { fullPath.append((false)? queryDelimiter : QUrl::toPercentEncoding(queryDelimiter)); } fullPath.append(::test_namespace::toStringValue(t)); count++; } } else if (QString("csv").indexOf("tsv") == 0) { if (fullPath.indexOf("?") > 0) fullPath.append("&"); else fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix); qint32 count = 0; for (QString t : tags) { if (count > 0) { fullPath.append("\t"); } fullPath.append(::test_namespace::toStringValue(t)); count++; } } else if (QString("csv").indexOf("csv") == 0) { if (fullPath.indexOf("?") > 0) fullPath.append("&"); else fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix); qint32 count = 0; for (QString t : tags) { if (count > 0) { fullPath.append(queryDelimiter); } fullPath.append(::test_namespace::toStringValue(t)); count++; } } else if (QString("csv").indexOf("pipes") == 0) { if (fullPath.indexOf("?") > 0) fullPath.append("&"); else fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix); qint32 count = 0; for (QString t : tags) { if (count > 0) { fullPath.append(queryDelimiter); } fullPath.append(::test_namespace::toStringValue(t)); count++; } } else if (QString("csv").indexOf("deepObject") == 0) { if (fullPath.indexOf("?") > 0) fullPath.append("&"); else fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix); qint32 count = 0; for (QString t : tags) { if (count > 0) { fullPath.append(queryDelimiter); } fullPath.append(::test_namespace::toStringValue(t)); count++; } } } } PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "GET"); for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) { input.headers.insert(keyValueIt->first, keyValueIt->second); } connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByTagsCallback); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); connect(worker, &QObject::destroyed, this, [this] { if (findChildren().count() == 0) { Q_EMIT allPendingRequestsCompleted(); } }); _OauthMethod = 1; _implicitFlow.link(); _passwordFlow.unlink(); _authFlow.unlink(); _credentialFlow.unlink(); QStringList scope; scope.append("write:pets"); scope.append("read:pets"); auto token = _implicitFlow.getToken(scope.join(" ")); if(token.isValid()) input.headers.insert("Authorization", "Bearer " + token.getToken()); _latestWorker = new PFXHttpRequestWorker(this, _manager); _latestWorker->setTimeOut(_timeOut); _latestWorker->setWorkingDirectory(_workingDirectory); connect(_latestWorker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByTagsCallback); connect(this, &PFXPetApi::abortRequestsSignal, _latestWorker, &QObject::deleteLater); connect(_latestWorker, &QObject::destroyed, this, [this] { if(findChildren().count() == 0){ Q_EMIT allPendingRequestsCompleted(); } }); _latestInput = input; _latestScope = scope; worker->execute(&input); } void PFXPetApi::findPetsByTagsCallback(PFXHttpRequestWorker *worker) { QString error_str = worker->error_str; QNetworkReply::NetworkError error_type = worker->error_type; if (worker->error_type != QNetworkReply::NoError) { error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response)); } QList output; QString json(worker->response); QByteArray array(json.toStdString().c_str()); QJsonDocument doc = QJsonDocument::fromJson(array); QJsonArray jsonArray = doc.array(); for (QJsonValue obj : jsonArray) { PFXPet val; ::test_namespace::fromJsonValue(val, obj); output.append(val); } worker->deleteLater(); if (worker->error_type == QNetworkReply::NoError) { Q_EMIT findPetsByTagsSignal(output); Q_EMIT findPetsByTagsSignalFull(worker, output); } else if(worker->error_type == QNetworkReply::AuthenticationRequiredError){ connect(&_implicitFlow, SIGNAL(tokenReceived()), this, SLOT(tokenAvailable())); QStringList scope; scope.append("write:pets"); scope.append("read:pets"); QString scopeStr = scope.join(" "); QString authorizationUrl("http://petstore.swagger.io/api/oauth/dialog"); //TODO get clientID and Secret and state in the config? https://swagger.io/docs/specification/authentication/oauth2/ states that you should do as you like _implicitFlow.setVariables(authorizationUrl, scopeStr, "state" , "http://127.0.0.1:9999", "clientId"); Q_EMIT _implicitFlow.authenticationNeeded(); } else { #if defined(_MSC_VER) // For MSVC #pragma warning(push) #pragma warning(disable : 4996) #elif defined(__clang__) // For Clang #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" #elif defined(__GNUC__) // For GCC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif Q_EMIT findPetsByTagsSignalE(output, error_type, error_str); Q_EMIT findPetsByTagsSignalEFull(worker, error_type, error_str); #if defined(_MSC_VER) #pragma warning(pop) #elif defined(__clang__) #pragma clang diagnostic pop #elif defined(__GNUC__) #pragma GCC diagnostic pop #endif Q_EMIT findPetsByTagsSignalError(output, error_type, error_str); Q_EMIT findPetsByTagsSignalErrorFull(worker, error_type, error_str); } } void PFXPetApi::getPetById(const qint64 &pet_id) { QString fullPath = QString(_serverConfigs["getPetById"][_serverIndices.value("getPetById")].URL()+"/pet/{petId}"); if (_apiKeys.contains("api_key")) { addHeaders("api_key",_apiKeys.find("api_key").value()); } { QString pet_idPathParam("{"); pet_idPathParam.append("petId").append("}"); QString pathPrefix, pathSuffix, pathDelimiter; QString pathStyle = "simple"; if (pathStyle == "") pathStyle = "simple"; pathPrefix = getParamStylePrefix(pathStyle); pathSuffix = getParamStyleSuffix(pathStyle); pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false); QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix; fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); } PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "GET"); for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) { input.headers.insert(keyValueIt->first, keyValueIt->second); } connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::getPetByIdCallback); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); connect(worker, &QObject::destroyed, this, [this] { if (findChildren().count() == 0) { Q_EMIT allPendingRequestsCompleted(); } }); worker->execute(&input); } void PFXPetApi::getPetByIdCallback(PFXHttpRequestWorker *worker) { QString error_str = worker->error_str; QNetworkReply::NetworkError error_type = worker->error_type; if (worker->error_type != QNetworkReply::NoError) { error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response)); } PFXPet output(QString(worker->response)); worker->deleteLater(); if (worker->error_type == QNetworkReply::NoError) { Q_EMIT getPetByIdSignal(output); Q_EMIT getPetByIdSignalFull(worker, output); } else { #if defined(_MSC_VER) // For MSVC #pragma warning(push) #pragma warning(disable : 4996) #elif defined(__clang__) // For Clang #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" #elif defined(__GNUC__) // For GCC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif Q_EMIT getPetByIdSignalE(output, error_type, error_str); Q_EMIT getPetByIdSignalEFull(worker, error_type, error_str); #if defined(_MSC_VER) #pragma warning(pop) #elif defined(__clang__) #pragma clang diagnostic pop #elif defined(__GNUC__) #pragma GCC diagnostic pop #endif Q_EMIT getPetByIdSignalError(output, error_type, error_str); Q_EMIT getPetByIdSignalErrorFull(worker, error_type, error_str); } } void PFXPetApi::updatePet(const PFXPet &pfx_pet) { QString fullPath = QString(_serverConfigs["updatePet"][_serverIndices.value("updatePet")].URL()+"/pet"); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "PUT"); { QByteArray output = pfx_pet.asJson().toUtf8(); input.request_body.append(output); } for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) { input.headers.insert(keyValueIt->first, keyValueIt->second); } connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetCallback); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); connect(worker, &QObject::destroyed, this, [this] { if (findChildren().count() == 0) { Q_EMIT allPendingRequestsCompleted(); } }); _OauthMethod = 1; _implicitFlow.link(); _passwordFlow.unlink(); _authFlow.unlink(); _credentialFlow.unlink(); QStringList scope; scope.append("write:pets"); scope.append("read:pets"); auto token = _implicitFlow.getToken(scope.join(" ")); if(token.isValid()) input.headers.insert("Authorization", "Bearer " + token.getToken()); _latestWorker = new PFXHttpRequestWorker(this, _manager); _latestWorker->setTimeOut(_timeOut); _latestWorker->setWorkingDirectory(_workingDirectory); connect(_latestWorker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetCallback); connect(this, &PFXPetApi::abortRequestsSignal, _latestWorker, &QObject::deleteLater); connect(_latestWorker, &QObject::destroyed, this, [this] { if(findChildren().count() == 0){ Q_EMIT allPendingRequestsCompleted(); } }); _latestInput = input; _latestScope = scope; worker->execute(&input); } void PFXPetApi::updatePetCallback(PFXHttpRequestWorker *worker) { QString error_str = worker->error_str; QNetworkReply::NetworkError error_type = worker->error_type; if (worker->error_type != QNetworkReply::NoError) { error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response)); } worker->deleteLater(); if (worker->error_type == QNetworkReply::NoError) { Q_EMIT updatePetSignal(); Q_EMIT updatePetSignalFull(worker); } else if(worker->error_type == QNetworkReply::AuthenticationRequiredError){ connect(&_implicitFlow, SIGNAL(tokenReceived()), this, SLOT(tokenAvailable())); QStringList scope; scope.append("write:pets"); scope.append("read:pets"); QString scopeStr = scope.join(" "); QString authorizationUrl("http://petstore.swagger.io/api/oauth/dialog"); //TODO get clientID and Secret and state in the config? https://swagger.io/docs/specification/authentication/oauth2/ states that you should do as you like _implicitFlow.setVariables(authorizationUrl, scopeStr, "state" , "http://127.0.0.1:9999", "clientId"); Q_EMIT _implicitFlow.authenticationNeeded(); } else { #if defined(_MSC_VER) // For MSVC #pragma warning(push) #pragma warning(disable : 4996) #elif defined(__clang__) // For Clang #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" #elif defined(__GNUC__) // For GCC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif Q_EMIT updatePetSignalE(error_type, error_str); Q_EMIT updatePetSignalEFull(worker, error_type, error_str); #if defined(_MSC_VER) #pragma warning(pop) #elif defined(__clang__) #pragma clang diagnostic pop #elif defined(__GNUC__) #pragma GCC diagnostic pop #endif Q_EMIT updatePetSignalError(error_type, error_str); Q_EMIT updatePetSignalErrorFull(worker, error_type, error_str); } } void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const ::test_namespace::OptionalParam &name, const ::test_namespace::OptionalParam &status) { QString fullPath = QString(_serverConfigs["updatePetWithForm"][_serverIndices.value("updatePetWithForm")].URL()+"/pet/{petId}"); { QString pet_idPathParam("{"); pet_idPathParam.append("petId").append("}"); QString pathPrefix, pathSuffix, pathDelimiter; QString pathStyle = "simple"; if (pathStyle == "") pathStyle = "simple"; pathPrefix = getParamStylePrefix(pathStyle); pathSuffix = getParamStyleSuffix(pathStyle); pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false); QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix; fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); } PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "POST"); if (name.hasValue()) { input.add_var("name", ::test_namespace::toStringValue(name.value())); } if (status.hasValue()) { input.add_var("status", ::test_namespace::toStringValue(status.value())); } for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) { input.headers.insert(keyValueIt->first, keyValueIt->second); } connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetWithFormCallback); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); connect(worker, &QObject::destroyed, this, [this] { if (findChildren().count() == 0) { Q_EMIT allPendingRequestsCompleted(); } }); _OauthMethod = 1; _implicitFlow.link(); _passwordFlow.unlink(); _authFlow.unlink(); _credentialFlow.unlink(); QStringList scope; scope.append("write:pets"); scope.append("read:pets"); auto token = _implicitFlow.getToken(scope.join(" ")); if(token.isValid()) input.headers.insert("Authorization", "Bearer " + token.getToken()); _latestWorker = new PFXHttpRequestWorker(this, _manager); _latestWorker->setTimeOut(_timeOut); _latestWorker->setWorkingDirectory(_workingDirectory); connect(_latestWorker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetWithFormCallback); connect(this, &PFXPetApi::abortRequestsSignal, _latestWorker, &QObject::deleteLater); connect(_latestWorker, &QObject::destroyed, this, [this] { if(findChildren().count() == 0){ Q_EMIT allPendingRequestsCompleted(); } }); _latestInput = input; _latestScope = scope; worker->execute(&input); } void PFXPetApi::updatePetWithFormCallback(PFXHttpRequestWorker *worker) { QString error_str = worker->error_str; QNetworkReply::NetworkError error_type = worker->error_type; if (worker->error_type != QNetworkReply::NoError) { error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response)); } worker->deleteLater(); if (worker->error_type == QNetworkReply::NoError) { Q_EMIT updatePetWithFormSignal(); Q_EMIT updatePetWithFormSignalFull(worker); } else if(worker->error_type == QNetworkReply::AuthenticationRequiredError){ connect(&_implicitFlow, SIGNAL(tokenReceived()), this, SLOT(tokenAvailable())); QStringList scope; scope.append("write:pets"); scope.append("read:pets"); QString scopeStr = scope.join(" "); QString authorizationUrl("http://petstore.swagger.io/api/oauth/dialog"); //TODO get clientID and Secret and state in the config? https://swagger.io/docs/specification/authentication/oauth2/ states that you should do as you like _implicitFlow.setVariables(authorizationUrl, scopeStr, "state" , "http://127.0.0.1:9999", "clientId"); Q_EMIT _implicitFlow.authenticationNeeded(); } else { #if defined(_MSC_VER) // For MSVC #pragma warning(push) #pragma warning(disable : 4996) #elif defined(__clang__) // For Clang #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" #elif defined(__GNUC__) // For GCC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif Q_EMIT updatePetWithFormSignalE(error_type, error_str); Q_EMIT updatePetWithFormSignalEFull(worker, error_type, error_str); #if defined(_MSC_VER) #pragma warning(pop) #elif defined(__clang__) #pragma clang diagnostic pop #elif defined(__GNUC__) #pragma GCC diagnostic pop #endif Q_EMIT updatePetWithFormSignalError(error_type, error_str); Q_EMIT updatePetWithFormSignalErrorFull(worker, error_type, error_str); } } void PFXPetApi::uploadFile(const qint64 &pet_id, const ::test_namespace::OptionalParam &additional_metadata, const ::test_namespace::OptionalParam &file) { QString fullPath = QString(_serverConfigs["uploadFile"][_serverIndices.value("uploadFile")].URL()+"/pet/{petId}/uploadImage"); { QString pet_idPathParam("{"); pet_idPathParam.append("petId").append("}"); QString pathPrefix, pathSuffix, pathDelimiter; QString pathStyle = "simple"; if (pathStyle == "") pathStyle = "simple"; pathPrefix = getParamStylePrefix(pathStyle); pathSuffix = getParamStyleSuffix(pathStyle); pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false); QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix; fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); } PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "POST"); if (additional_metadata.hasValue()) { input.add_var("additionalMetadata", ::test_namespace::toStringValue(additional_metadata.value())); } if (file.hasValue()) { input.add_file("file", file.value().local_filename, file.value().request_filename, file.value().mime_type); } for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) { input.headers.insert(keyValueIt->first, keyValueIt->second); } connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::uploadFileCallback); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); connect(worker, &QObject::destroyed, this, [this] { if (findChildren().count() == 0) { Q_EMIT allPendingRequestsCompleted(); } }); _OauthMethod = 1; _implicitFlow.link(); _passwordFlow.unlink(); _authFlow.unlink(); _credentialFlow.unlink(); QStringList scope; scope.append("write:pets"); scope.append("read:pets"); auto token = _implicitFlow.getToken(scope.join(" ")); if(token.isValid()) input.headers.insert("Authorization", "Bearer " + token.getToken()); _latestWorker = new PFXHttpRequestWorker(this, _manager); _latestWorker->setTimeOut(_timeOut); _latestWorker->setWorkingDirectory(_workingDirectory); connect(_latestWorker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::uploadFileCallback); connect(this, &PFXPetApi::abortRequestsSignal, _latestWorker, &QObject::deleteLater); connect(_latestWorker, &QObject::destroyed, this, [this] { if(findChildren().count() == 0){ Q_EMIT allPendingRequestsCompleted(); } }); _latestInput = input; _latestScope = scope; worker->execute(&input); } void PFXPetApi::uploadFileCallback(PFXHttpRequestWorker *worker) { QString error_str = worker->error_str; QNetworkReply::NetworkError error_type = worker->error_type; if (worker->error_type != QNetworkReply::NoError) { error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response)); } PFXApiResponse output(QString(worker->response)); worker->deleteLater(); if (worker->error_type == QNetworkReply::NoError) { Q_EMIT uploadFileSignal(output); Q_EMIT uploadFileSignalFull(worker, output); } else if(worker->error_type == QNetworkReply::AuthenticationRequiredError){ connect(&_implicitFlow, SIGNAL(tokenReceived()), this, SLOT(tokenAvailable())); QStringList scope; scope.append("write:pets"); scope.append("read:pets"); QString scopeStr = scope.join(" "); QString authorizationUrl("http://petstore.swagger.io/api/oauth/dialog"); //TODO get clientID and Secret and state in the config? https://swagger.io/docs/specification/authentication/oauth2/ states that you should do as you like _implicitFlow.setVariables(authorizationUrl, scopeStr, "state" , "http://127.0.0.1:9999", "clientId"); Q_EMIT _implicitFlow.authenticationNeeded(); } else { #if defined(_MSC_VER) // For MSVC #pragma warning(push) #pragma warning(disable : 4996) #elif defined(__clang__) // For Clang #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" #elif defined(__GNUC__) // For GCC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif Q_EMIT uploadFileSignalE(output, error_type, error_str); Q_EMIT uploadFileSignalEFull(worker, error_type, error_str); #if defined(_MSC_VER) #pragma warning(pop) #elif defined(__clang__) #pragma clang diagnostic pop #elif defined(__GNUC__) #pragma GCC diagnostic pop #endif Q_EMIT uploadFileSignalError(output, error_type, error_str); Q_EMIT uploadFileSignalErrorFull(worker, error_type, error_str); } } void PFXPetApi::tokenAvailable(){ oauthToken token; switch (_OauthMethod) { case 1: //implicit flow token = _implicitFlow.getToken(_latestScope.join(" ")); if(token.isValid()){ _latestInput.headers.insert("Authorization", "Bearer " + token.getToken()); _latestWorker->execute(&_latestInput); }else{ _implicitFlow.removeToken(_latestScope.join(" ")); qDebug() << "Could not retrieve a valid token"; } break; case 2: //authorization flow token = _authFlow.getToken(_latestScope.join(" ")); if(token.isValid()){ _latestInput.headers.insert("Authorization", "Bearer " + token.getToken()); _latestWorker->execute(&_latestInput); }else{ _authFlow.removeToken(_latestScope.join(" ")); qDebug() << "Could not retrieve a valid token"; } break; case 3: //client credentials flow token = _credentialFlow.getToken(_latestScope.join(" ")); if(token.isValid()){ _latestInput.headers.insert("Authorization", "Bearer " + token.getToken()); _latestWorker->execute(&_latestInput); }else{ _credentialFlow.removeToken(_latestScope.join(" ")); qDebug() << "Could not retrieve a valid token"; } break; case 4: //resource owner password flow token = _passwordFlow.getToken(_latestScope.join(" ")); if(token.isValid()){ _latestInput.headers.insert("Authorization", "Bearer " + token.getToken()); _latestWorker->execute(&_latestInput); }else{ _credentialFlow.removeToken(_latestScope.join(" ")); qDebug() << "Could not retrieve a valid token"; } break; default: qDebug() << "No Oauth method set!"; break; } } } // namespace test_namespace