forked from loafle/openapi-generator-original
cpp-qt-client: Fix cppcheck warnings (#10322)
* Fix cppcheck warnings * Improve coding style * Add 4 spaces
This commit is contained in:
parent
86ead27a40
commit
2239ca36fd
@ -11,8 +11,8 @@ namespace {{this}} {
|
||||
{{classname}}::{{classname}}(const int timeOut)
|
||||
: _timeOut(timeOut),
|
||||
_manager(nullptr),
|
||||
isResponseCompressionEnabled(false),
|
||||
isRequestCompressionEnabled(false) {
|
||||
_isResponseCompressionEnabled(false),
|
||||
_isRequestCompressionEnabled(false) {
|
||||
initializeServerConfigs();
|
||||
}
|
||||
|
||||
@ -23,7 +23,9 @@ void {{classname}}::initializeServerConfigs(){
|
||||
//Default server
|
||||
QList<{{prefix}}ServerConfiguration> defaultConf = QList<{{prefix}}ServerConfiguration>();
|
||||
//varying endpoint server
|
||||
{{#servers}}
|
||||
QList<{{prefix}}ServerConfiguration> serverConf = QList<{{prefix}}ServerConfiguration>();
|
||||
{{/servers}}
|
||||
{{#vendorExtensions.x-cpp-global-server-list}}
|
||||
defaultConf.append({{prefix}}ServerConfiguration(
|
||||
QUrl("{{{url}}}"),
|
||||
@ -66,9 +68,10 @@ int {{classname}}::setDefaultServerValue(int serverIndex, const QString &operati
|
||||
return -3;
|
||||
}
|
||||
void {{classname}}::setServerIndex(const QString &operation, int serverIndex) {
|
||||
if(_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size() )
|
||||
if (_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size()) {
|
||||
_serverIndices[operation] = serverIndex;
|
||||
}
|
||||
}
|
||||
|
||||
void {{classname}}::setApiKey(const QString &apiKeyName, const QString &apiKey) {
|
||||
_apiKeys.insert(apiKeyName,apiKey);
|
||||
@ -126,8 +129,8 @@ int {{classname}}::addServerConfiguration(const QString &operation, const QUrl &
|
||||
* @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template.
|
||||
*/
|
||||
void {{classname}}::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap<QString, {{prefix}}ServerVariable> &variables) {
|
||||
for(auto e : _serverIndices.keys()){
|
||||
setServerIndex(e, addServerConfiguration(e, url, description, variables));
|
||||
for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) {
|
||||
setServerIndex(*keyIt, addServerConfiguration(*keyIt, url, description, variables));
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,22 +145,22 @@ void {{classname}}::setNewServer(const QString &operation, const QUrl &url, cons
|
||||
}
|
||||
|
||||
void {{classname}}::addHeaders(const QString &key, const QString &value) {
|
||||
defaultHeaders.insert(key, value);
|
||||
_defaultHeaders.insert(key, value);
|
||||
}
|
||||
|
||||
void {{classname}}::enableRequestCompression() {
|
||||
isRequestCompressionEnabled = true;
|
||||
_isRequestCompressionEnabled = true;
|
||||
}
|
||||
|
||||
void {{classname}}::enableResponseCompression() {
|
||||
isResponseCompressionEnabled = true;
|
||||
_isResponseCompressionEnabled = true;
|
||||
}
|
||||
|
||||
void {{classname}}::abortRequests() {
|
||||
emit abortRequestsSignal();
|
||||
}
|
||||
|
||||
QString {{classname}}::getParamStylePrefix(QString style){
|
||||
QString {{classname}}::getParamStylePrefix(const QString &style) {
|
||||
if (style == "matrix") {
|
||||
return ";";
|
||||
} else if (style == "label") {
|
||||
@ -175,7 +178,7 @@ QString {{classname}}::getParamStylePrefix(QString style){
|
||||
}
|
||||
}
|
||||
|
||||
QString {{classname}}::getParamStyleSuffix(QString style){
|
||||
QString {{classname}}::getParamStyleSuffix(const QString &style) {
|
||||
if (style == "matrix") {
|
||||
return "=";
|
||||
} else if (style == "label") {
|
||||
@ -193,7 +196,7 @@ QString {{classname}}::getParamStyleSuffix(QString style){
|
||||
}
|
||||
}
|
||||
|
||||
QString {{classname}}::getParamStyleDelimiter(QString style, QString name, bool isExplode){
|
||||
QString {{classname}}::getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode) {
|
||||
|
||||
if (style == "matrix") {
|
||||
return (isExplode) ? ";" + name + "=" : ",";
|
||||
@ -474,8 +477,8 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
|
||||
{{prefix}}HttpRequestWorker *worker = new {{prefix}}HttpRequestWorker(this, _manager);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);{{#contentCompression}}
|
||||
worker->setResponseCompressionEnabled(isResponseCompressionEnabled);
|
||||
worker->setRequestCompressionEnabled(isRequestCompressionEnabled);{{/contentCompression}}
|
||||
worker->setResponseCompressionEnabled(_isResponseCompressionEnabled);
|
||||
worker->setRequestCompressionEnabled(_isRequestCompressionEnabled);{{/contentCompression}}
|
||||
{{prefix}}HttpRequestInput input(fullPath, "{{httpMethod}}");
|
||||
|
||||
{{#formParams}}
|
||||
@ -653,11 +656,13 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
|
||||
}
|
||||
}
|
||||
{{/cookieParams}}
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||
}
|
||||
|
||||
connect(worker, &{{prefix}}HttpRequestWorker::on_execution_finished, this, &{{classname}}::{{nickname}}Callback);
|
||||
connect(this, &{{classname}}::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||
connect(worker, &QObject::destroyed, [this](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<{{prefix}}HttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -667,15 +672,11 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
|
||||
}
|
||||
|
||||
void {{classname}}::{{nickname}}Callback({{prefix}}HttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
if (worker->error_type != QNetworkReply::NoError) {
|
||||
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||
}
|
||||
{{#returnType}}
|
||||
{{#isArray}}
|
||||
|
@ -43,9 +43,9 @@ public:
|
||||
void enableRequestCompression();
|
||||
void enableResponseCompression();
|
||||
void abortRequests();
|
||||
QString getParamStylePrefix(QString style);
|
||||
QString getParamStyleSuffix(QString style);
|
||||
QString getParamStyleDelimiter(QString style, QString name, bool isExplode);
|
||||
QString getParamStylePrefix(const QString &style);
|
||||
QString getParamStyleSuffix(const QString &style);
|
||||
QString getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode);
|
||||
{{#operations}}{{#operation}}
|
||||
{{#hasParams}} /**
|
||||
{{#allParams}}
|
||||
@ -70,9 +70,9 @@ private:
|
||||
int _timeOut;
|
||||
QString _workingDirectory;
|
||||
QNetworkAccessManager* _manager;
|
||||
QMap<QString, QString> defaultHeaders;
|
||||
bool isResponseCompressionEnabled;
|
||||
bool isRequestCompressionEnabled;
|
||||
QMap<QString, QString> _defaultHeaders;
|
||||
bool _isResponseCompressionEnabled;
|
||||
bool _isRequestCompressionEnabled;
|
||||
{{#operations}}{{#operation}}
|
||||
void {{nickname}}Callback({{prefix}}HttpRequestWorker *worker);{{/operation}}{{/operations}}
|
||||
|
||||
|
@ -19,8 +19,8 @@ namespace test_namespace {
|
||||
PFXPetApi::PFXPetApi(const int timeOut)
|
||||
: _timeOut(timeOut),
|
||||
_manager(nullptr),
|
||||
isResponseCompressionEnabled(false),
|
||||
isRequestCompressionEnabled(false) {
|
||||
_isResponseCompressionEnabled(false),
|
||||
_isRequestCompressionEnabled(false) {
|
||||
initializeServerConfigs();
|
||||
}
|
||||
|
||||
@ -31,7 +31,6 @@ void PFXPetApi::initializeServerConfigs(){
|
||||
//Default server
|
||||
QList<PFXServerConfiguration> defaultConf = QList<PFXServerConfiguration>();
|
||||
//varying endpoint server
|
||||
QList<PFXServerConfiguration> serverConf = QList<PFXServerConfiguration>();
|
||||
defaultConf.append(PFXServerConfiguration(
|
||||
QUrl("http://petstore.swagger.io/v2"),
|
||||
"No description provided",
|
||||
@ -66,9 +65,10 @@ int PFXPetApi::setDefaultServerValue(int serverIndex, const QString &operation,
|
||||
return -3;
|
||||
}
|
||||
void PFXPetApi::setServerIndex(const QString &operation, int serverIndex) {
|
||||
if(_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size() )
|
||||
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);
|
||||
@ -126,8 +126,8 @@ int PFXPetApi::addServerConfiguration(const QString &operation, const QUrl &url,
|
||||
* @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<QString, PFXServerVariable> &variables) {
|
||||
for(auto e : _serverIndices.keys()){
|
||||
setServerIndex(e, addServerConfiguration(e, url, description, variables));
|
||||
for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) {
|
||||
setServerIndex(*keyIt, addServerConfiguration(*keyIt, url, description, variables));
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,22 +142,22 @@ void PFXPetApi::setNewServer(const QString &operation, const QUrl &url, const QS
|
||||
}
|
||||
|
||||
void PFXPetApi::addHeaders(const QString &key, const QString &value) {
|
||||
defaultHeaders.insert(key, value);
|
||||
_defaultHeaders.insert(key, value);
|
||||
}
|
||||
|
||||
void PFXPetApi::enableRequestCompression() {
|
||||
isRequestCompressionEnabled = true;
|
||||
_isRequestCompressionEnabled = true;
|
||||
}
|
||||
|
||||
void PFXPetApi::enableResponseCompression() {
|
||||
isResponseCompressionEnabled = true;
|
||||
_isResponseCompressionEnabled = true;
|
||||
}
|
||||
|
||||
void PFXPetApi::abortRequests() {
|
||||
emit abortRequestsSignal();
|
||||
}
|
||||
|
||||
QString PFXPetApi::getParamStylePrefix(QString style){
|
||||
QString PFXPetApi::getParamStylePrefix(const QString &style) {
|
||||
if (style == "matrix") {
|
||||
return ";";
|
||||
} else if (style == "label") {
|
||||
@ -175,7 +175,7 @@ QString PFXPetApi::getParamStylePrefix(QString style){
|
||||
}
|
||||
}
|
||||
|
||||
QString PFXPetApi::getParamStyleSuffix(QString style){
|
||||
QString PFXPetApi::getParamStyleSuffix(const QString &style) {
|
||||
if (style == "matrix") {
|
||||
return "=";
|
||||
} else if (style == "label") {
|
||||
@ -193,7 +193,7 @@ QString PFXPetApi::getParamStyleSuffix(QString style){
|
||||
}
|
||||
}
|
||||
|
||||
QString PFXPetApi::getParamStyleDelimiter(QString style, QString name, bool isExplode){
|
||||
QString PFXPetApi::getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode) {
|
||||
|
||||
if (style == "matrix") {
|
||||
return (isExplode) ? ";" + name + "=" : ",";
|
||||
@ -233,11 +233,13 @@ void PFXPetApi::addPet(const PFXPet &body) {
|
||||
QByteArray output = body.asJson().toUtf8();
|
||||
input.request_body.append(output);
|
||||
}
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
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](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -247,15 +249,11 @@ void PFXPetApi::addPet(const PFXPet &body) {
|
||||
}
|
||||
|
||||
void PFXPetApi::addPetCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
if (worker->error_type != QNetworkReply::NoError) {
|
||||
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -297,11 +295,13 @@ void PFXPetApi::deletePet(const qint64 &pet_id, const ::test_namespace::Optional
|
||||
input.headers.insert("api_key", ::test_namespace::toStringValue(api_key.value()));
|
||||
}
|
||||
}
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
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](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -311,15 +311,11 @@ void PFXPetApi::deletePet(const qint64 &pet_id, const ::test_namespace::Optional
|
||||
}
|
||||
|
||||
void PFXPetApi::deletePetCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
if (worker->error_type != QNetworkReply::NoError) {
|
||||
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -427,11 +423,13 @@ void PFXPetApi::findPetsByStatus(const QList<QString> &status) {
|
||||
PFXHttpRequestInput input(fullPath, "GET");
|
||||
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
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](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -441,15 +439,11 @@ void PFXPetApi::findPetsByStatus(const QList<QString> &status) {
|
||||
}
|
||||
|
||||
void PFXPetApi::findPetsByStatusCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
if (worker->error_type != QNetworkReply::NoError) {
|
||||
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||
}
|
||||
QList<PFXPet> output;
|
||||
QString json(worker->response);
|
||||
@ -567,11 +561,13 @@ void PFXPetApi::findPetsByTags(const QList<QString> &tags) {
|
||||
PFXHttpRequestInput input(fullPath, "GET");
|
||||
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
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](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -581,15 +577,11 @@ void PFXPetApi::findPetsByTags(const QList<QString> &tags) {
|
||||
}
|
||||
|
||||
void PFXPetApi::findPetsByTagsCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
if (worker->error_type != QNetworkReply::NoError) {
|
||||
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||
}
|
||||
QList<PFXPet> output;
|
||||
QString json(worker->response);
|
||||
@ -639,11 +631,13 @@ void PFXPetApi::getPetById(const qint64 &pet_id) {
|
||||
PFXHttpRequestInput input(fullPath, "GET");
|
||||
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
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](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -653,15 +647,11 @@ void PFXPetApi::getPetById(const qint64 &pet_id) {
|
||||
}
|
||||
|
||||
void PFXPetApi::getPetByIdCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
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();
|
||||
@ -688,11 +678,13 @@ void PFXPetApi::updatePet(const PFXPet &body) {
|
||||
QByteArray output = body.asJson().toUtf8();
|
||||
input.request_body.append(output);
|
||||
}
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
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](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -702,15 +694,11 @@ void PFXPetApi::updatePet(const PFXPet &body) {
|
||||
}
|
||||
|
||||
void PFXPetApi::updatePetCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
if (worker->error_type != QNetworkReply::NoError) {
|
||||
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -754,11 +742,13 @@ void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const ::test_namespace::
|
||||
input.add_var("status", ::test_namespace::toStringValue(status.value()));
|
||||
}
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
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](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -768,15 +758,11 @@ void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const ::test_namespace::
|
||||
}
|
||||
|
||||
void PFXPetApi::updatePetWithFormCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
if (worker->error_type != QNetworkReply::NoError) {
|
||||
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -820,11 +806,13 @@ void PFXPetApi::uploadFile(const qint64 &pet_id, const ::test_namespace::Optiona
|
||||
input.add_file("file", file.value().local_filename, file.value().request_filename, file.value().mime_type);
|
||||
}
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
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](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -834,15 +822,11 @@ void PFXPetApi::uploadFile(const qint64 &pet_id, const ::test_namespace::Optiona
|
||||
}
|
||||
|
||||
void PFXPetApi::uploadFileCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
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();
|
||||
|
@ -53,9 +53,9 @@ public:
|
||||
void enableRequestCompression();
|
||||
void enableResponseCompression();
|
||||
void abortRequests();
|
||||
QString getParamStylePrefix(QString style);
|
||||
QString getParamStyleSuffix(QString style);
|
||||
QString getParamStyleDelimiter(QString style, QString name, bool isExplode);
|
||||
QString getParamStylePrefix(const QString &style);
|
||||
QString getParamStyleSuffix(const QString &style);
|
||||
QString getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode);
|
||||
|
||||
/**
|
||||
* @param[in] body PFXPet [required]
|
||||
@ -113,9 +113,9 @@ private:
|
||||
int _timeOut;
|
||||
QString _workingDirectory;
|
||||
QNetworkAccessManager* _manager;
|
||||
QMap<QString, QString> defaultHeaders;
|
||||
bool isResponseCompressionEnabled;
|
||||
bool isRequestCompressionEnabled;
|
||||
QMap<QString, QString> _defaultHeaders;
|
||||
bool _isResponseCompressionEnabled;
|
||||
bool _isRequestCompressionEnabled;
|
||||
|
||||
void addPetCallback(PFXHttpRequestWorker *worker);
|
||||
void deletePetCallback(PFXHttpRequestWorker *worker);
|
||||
|
@ -19,8 +19,8 @@ namespace test_namespace {
|
||||
PFXStoreApi::PFXStoreApi(const int timeOut)
|
||||
: _timeOut(timeOut),
|
||||
_manager(nullptr),
|
||||
isResponseCompressionEnabled(false),
|
||||
isRequestCompressionEnabled(false) {
|
||||
_isResponseCompressionEnabled(false),
|
||||
_isRequestCompressionEnabled(false) {
|
||||
initializeServerConfigs();
|
||||
}
|
||||
|
||||
@ -31,7 +31,6 @@ void PFXStoreApi::initializeServerConfigs(){
|
||||
//Default server
|
||||
QList<PFXServerConfiguration> defaultConf = QList<PFXServerConfiguration>();
|
||||
//varying endpoint server
|
||||
QList<PFXServerConfiguration> serverConf = QList<PFXServerConfiguration>();
|
||||
defaultConf.append(PFXServerConfiguration(
|
||||
QUrl("http://petstore.swagger.io/v2"),
|
||||
"No description provided",
|
||||
@ -58,9 +57,10 @@ int PFXStoreApi::setDefaultServerValue(int serverIndex, const QString &operation
|
||||
return -3;
|
||||
}
|
||||
void PFXStoreApi::setServerIndex(const QString &operation, int serverIndex) {
|
||||
if(_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size() )
|
||||
if (_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size()) {
|
||||
_serverIndices[operation] = serverIndex;
|
||||
}
|
||||
}
|
||||
|
||||
void PFXStoreApi::setApiKey(const QString &apiKeyName, const QString &apiKey) {
|
||||
_apiKeys.insert(apiKeyName,apiKey);
|
||||
@ -118,8 +118,8 @@ int PFXStoreApi::addServerConfiguration(const QString &operation, const QUrl &ur
|
||||
* @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template.
|
||||
*/
|
||||
void PFXStoreApi::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap<QString, PFXServerVariable> &variables) {
|
||||
for(auto e : _serverIndices.keys()){
|
||||
setServerIndex(e, addServerConfiguration(e, url, description, variables));
|
||||
for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) {
|
||||
setServerIndex(*keyIt, addServerConfiguration(*keyIt, url, description, variables));
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,22 +134,22 @@ void PFXStoreApi::setNewServer(const QString &operation, const QUrl &url, const
|
||||
}
|
||||
|
||||
void PFXStoreApi::addHeaders(const QString &key, const QString &value) {
|
||||
defaultHeaders.insert(key, value);
|
||||
_defaultHeaders.insert(key, value);
|
||||
}
|
||||
|
||||
void PFXStoreApi::enableRequestCompression() {
|
||||
isRequestCompressionEnabled = true;
|
||||
_isRequestCompressionEnabled = true;
|
||||
}
|
||||
|
||||
void PFXStoreApi::enableResponseCompression() {
|
||||
isResponseCompressionEnabled = true;
|
||||
_isResponseCompressionEnabled = true;
|
||||
}
|
||||
|
||||
void PFXStoreApi::abortRequests() {
|
||||
emit abortRequestsSignal();
|
||||
}
|
||||
|
||||
QString PFXStoreApi::getParamStylePrefix(QString style){
|
||||
QString PFXStoreApi::getParamStylePrefix(const QString &style) {
|
||||
if (style == "matrix") {
|
||||
return ";";
|
||||
} else if (style == "label") {
|
||||
@ -167,7 +167,7 @@ QString PFXStoreApi::getParamStylePrefix(QString style){
|
||||
}
|
||||
}
|
||||
|
||||
QString PFXStoreApi::getParamStyleSuffix(QString style){
|
||||
QString PFXStoreApi::getParamStyleSuffix(const QString &style) {
|
||||
if (style == "matrix") {
|
||||
return "=";
|
||||
} else if (style == "label") {
|
||||
@ -185,7 +185,7 @@ QString PFXStoreApi::getParamStyleSuffix(QString style){
|
||||
}
|
||||
}
|
||||
|
||||
QString PFXStoreApi::getParamStyleDelimiter(QString style, QString name, bool isExplode){
|
||||
QString PFXStoreApi::getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode) {
|
||||
|
||||
if (style == "matrix") {
|
||||
return (isExplode) ? ";" + name + "=" : ",";
|
||||
@ -235,11 +235,13 @@ void PFXStoreApi::deleteOrder(const QString &order_id) {
|
||||
PFXHttpRequestInput input(fullPath, "DELETE");
|
||||
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||
}
|
||||
|
||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::deleteOrderCallback);
|
||||
connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||
connect(worker, &QObject::destroyed, [this](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -249,15 +251,11 @@ void PFXStoreApi::deleteOrder(const QString &order_id) {
|
||||
}
|
||||
|
||||
void PFXStoreApi::deleteOrderCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
if (worker->error_type != QNetworkReply::NoError) {
|
||||
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -283,11 +281,13 @@ void PFXStoreApi::getInventory() {
|
||||
PFXHttpRequestInput input(fullPath, "GET");
|
||||
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||
}
|
||||
|
||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::getInventoryCallback);
|
||||
connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||
connect(worker, &QObject::destroyed, [this](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -297,15 +297,11 @@ void PFXStoreApi::getInventory() {
|
||||
}
|
||||
|
||||
void PFXStoreApi::getInventoryCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
if (worker->error_type != QNetworkReply::NoError) {
|
||||
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||
}
|
||||
QMap<QString, qint32> output;
|
||||
QString json(worker->response);
|
||||
@ -351,11 +347,13 @@ void PFXStoreApi::getOrderById(const qint64 &order_id) {
|
||||
PFXHttpRequestInput input(fullPath, "GET");
|
||||
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||
}
|
||||
|
||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::getOrderByIdCallback);
|
||||
connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||
connect(worker, &QObject::destroyed, [this](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -365,15 +363,11 @@ void PFXStoreApi::getOrderById(const qint64 &order_id) {
|
||||
}
|
||||
|
||||
void PFXStoreApi::getOrderByIdCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
if (worker->error_type != QNetworkReply::NoError) {
|
||||
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||
}
|
||||
PFXOrder output(QString(worker->response));
|
||||
worker->deleteLater();
|
||||
@ -400,11 +394,13 @@ void PFXStoreApi::placeOrder(const PFXOrder &body) {
|
||||
QByteArray output = body.asJson().toUtf8();
|
||||
input.request_body.append(output);
|
||||
}
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||
}
|
||||
|
||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::placeOrderCallback);
|
||||
connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||
connect(worker, &QObject::destroyed, [this](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -414,15 +410,11 @@ void PFXStoreApi::placeOrder(const PFXOrder &body) {
|
||||
}
|
||||
|
||||
void PFXStoreApi::placeOrderCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
if (worker->error_type != QNetworkReply::NoError) {
|
||||
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||
}
|
||||
PFXOrder output(QString(worker->response));
|
||||
worker->deleteLater();
|
||||
|
@ -52,9 +52,9 @@ public:
|
||||
void enableRequestCompression();
|
||||
void enableResponseCompression();
|
||||
void abortRequests();
|
||||
QString getParamStylePrefix(QString style);
|
||||
QString getParamStyleSuffix(QString style);
|
||||
QString getParamStyleDelimiter(QString style, QString name, bool isExplode);
|
||||
QString getParamStylePrefix(const QString &style);
|
||||
QString getParamStyleSuffix(const QString &style);
|
||||
QString getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode);
|
||||
|
||||
/**
|
||||
* @param[in] order_id QString [required]
|
||||
@ -85,9 +85,9 @@ private:
|
||||
int _timeOut;
|
||||
QString _workingDirectory;
|
||||
QNetworkAccessManager* _manager;
|
||||
QMap<QString, QString> defaultHeaders;
|
||||
bool isResponseCompressionEnabled;
|
||||
bool isRequestCompressionEnabled;
|
||||
QMap<QString, QString> _defaultHeaders;
|
||||
bool _isResponseCompressionEnabled;
|
||||
bool _isRequestCompressionEnabled;
|
||||
|
||||
void deleteOrderCallback(PFXHttpRequestWorker *worker);
|
||||
void getInventoryCallback(PFXHttpRequestWorker *worker);
|
||||
|
@ -19,8 +19,8 @@ namespace test_namespace {
|
||||
PFXUserApi::PFXUserApi(const int timeOut)
|
||||
: _timeOut(timeOut),
|
||||
_manager(nullptr),
|
||||
isResponseCompressionEnabled(false),
|
||||
isRequestCompressionEnabled(false) {
|
||||
_isResponseCompressionEnabled(false),
|
||||
_isRequestCompressionEnabled(false) {
|
||||
initializeServerConfigs();
|
||||
}
|
||||
|
||||
@ -31,7 +31,6 @@ void PFXUserApi::initializeServerConfigs(){
|
||||
//Default server
|
||||
QList<PFXServerConfiguration> defaultConf = QList<PFXServerConfiguration>();
|
||||
//varying endpoint server
|
||||
QList<PFXServerConfiguration> serverConf = QList<PFXServerConfiguration>();
|
||||
defaultConf.append(PFXServerConfiguration(
|
||||
QUrl("http://petstore.swagger.io/v2"),
|
||||
"No description provided",
|
||||
@ -66,9 +65,10 @@ int PFXUserApi::setDefaultServerValue(int serverIndex, const QString &operation,
|
||||
return -3;
|
||||
}
|
||||
void PFXUserApi::setServerIndex(const QString &operation, int serverIndex) {
|
||||
if(_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size() )
|
||||
if (_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size()) {
|
||||
_serverIndices[operation] = serverIndex;
|
||||
}
|
||||
}
|
||||
|
||||
void PFXUserApi::setApiKey(const QString &apiKeyName, const QString &apiKey) {
|
||||
_apiKeys.insert(apiKeyName,apiKey);
|
||||
@ -126,8 +126,8 @@ int PFXUserApi::addServerConfiguration(const QString &operation, const QUrl &url
|
||||
* @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template.
|
||||
*/
|
||||
void PFXUserApi::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap<QString, PFXServerVariable> &variables) {
|
||||
for(auto e : _serverIndices.keys()){
|
||||
setServerIndex(e, addServerConfiguration(e, url, description, variables));
|
||||
for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) {
|
||||
setServerIndex(*keyIt, addServerConfiguration(*keyIt, url, description, variables));
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,22 +142,22 @@ void PFXUserApi::setNewServer(const QString &operation, const QUrl &url, const Q
|
||||
}
|
||||
|
||||
void PFXUserApi::addHeaders(const QString &key, const QString &value) {
|
||||
defaultHeaders.insert(key, value);
|
||||
_defaultHeaders.insert(key, value);
|
||||
}
|
||||
|
||||
void PFXUserApi::enableRequestCompression() {
|
||||
isRequestCompressionEnabled = true;
|
||||
_isRequestCompressionEnabled = true;
|
||||
}
|
||||
|
||||
void PFXUserApi::enableResponseCompression() {
|
||||
isResponseCompressionEnabled = true;
|
||||
_isResponseCompressionEnabled = true;
|
||||
}
|
||||
|
||||
void PFXUserApi::abortRequests() {
|
||||
emit abortRequestsSignal();
|
||||
}
|
||||
|
||||
QString PFXUserApi::getParamStylePrefix(QString style){
|
||||
QString PFXUserApi::getParamStylePrefix(const QString &style) {
|
||||
if (style == "matrix") {
|
||||
return ";";
|
||||
} else if (style == "label") {
|
||||
@ -175,7 +175,7 @@ QString PFXUserApi::getParamStylePrefix(QString style){
|
||||
}
|
||||
}
|
||||
|
||||
QString PFXUserApi::getParamStyleSuffix(QString style){
|
||||
QString PFXUserApi::getParamStyleSuffix(const QString &style) {
|
||||
if (style == "matrix") {
|
||||
return "=";
|
||||
} else if (style == "label") {
|
||||
@ -193,7 +193,7 @@ QString PFXUserApi::getParamStyleSuffix(QString style){
|
||||
}
|
||||
}
|
||||
|
||||
QString PFXUserApi::getParamStyleDelimiter(QString style, QString name, bool isExplode){
|
||||
QString PFXUserApi::getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode) {
|
||||
|
||||
if (style == "matrix") {
|
||||
return (isExplode) ? ";" + name + "=" : ",";
|
||||
@ -233,11 +233,13 @@ void PFXUserApi::createUser(const PFXUser &body) {
|
||||
QByteArray output = body.asJson().toUtf8();
|
||||
input.request_body.append(output);
|
||||
}
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||
}
|
||||
|
||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::createUserCallback);
|
||||
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||
connect(worker, &QObject::destroyed, [this](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -247,15 +249,11 @@ void PFXUserApi::createUser(const PFXUser &body) {
|
||||
}
|
||||
|
||||
void PFXUserApi::createUserCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
if (worker->error_type != QNetworkReply::NoError) {
|
||||
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -281,11 +279,13 @@ void PFXUserApi::createUsersWithArrayInput(const QList<PFXUser> &body) {
|
||||
QByteArray bytes = doc.toJson();
|
||||
input.request_body.append(bytes);
|
||||
}
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||
}
|
||||
|
||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::createUsersWithArrayInputCallback);
|
||||
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||
connect(worker, &QObject::destroyed, [this](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -295,15 +295,11 @@ void PFXUserApi::createUsersWithArrayInput(const QList<PFXUser> &body) {
|
||||
}
|
||||
|
||||
void PFXUserApi::createUsersWithArrayInputCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
if (worker->error_type != QNetworkReply::NoError) {
|
||||
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -329,11 +325,13 @@ void PFXUserApi::createUsersWithListInput(const QList<PFXUser> &body) {
|
||||
QByteArray bytes = doc.toJson();
|
||||
input.request_body.append(bytes);
|
||||
}
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||
}
|
||||
|
||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::createUsersWithListInputCallback);
|
||||
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||
connect(worker, &QObject::destroyed, [this](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -343,15 +341,11 @@ void PFXUserApi::createUsersWithListInput(const QList<PFXUser> &body) {
|
||||
}
|
||||
|
||||
void PFXUserApi::createUsersWithListInputCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
if (worker->error_type != QNetworkReply::NoError) {
|
||||
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -387,11 +381,13 @@ void PFXUserApi::deleteUser(const QString &username) {
|
||||
PFXHttpRequestInput input(fullPath, "DELETE");
|
||||
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||
}
|
||||
|
||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::deleteUserCallback);
|
||||
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||
connect(worker, &QObject::destroyed, [this](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -401,15 +397,11 @@ void PFXUserApi::deleteUser(const QString &username) {
|
||||
}
|
||||
|
||||
void PFXUserApi::deleteUserCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
if (worker->error_type != QNetworkReply::NoError) {
|
||||
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -445,11 +437,13 @@ void PFXUserApi::getUserByName(const QString &username) {
|
||||
PFXHttpRequestInput input(fullPath, "GET");
|
||||
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||
}
|
||||
|
||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::getUserByNameCallback);
|
||||
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||
connect(worker, &QObject::destroyed, [this](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -459,15 +453,11 @@ void PFXUserApi::getUserByName(const QString &username) {
|
||||
}
|
||||
|
||||
void PFXUserApi::getUserByNameCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
if (worker->error_type != QNetworkReply::NoError) {
|
||||
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||
}
|
||||
PFXUser output(QString(worker->response));
|
||||
worker->deleteLater();
|
||||
@ -521,11 +511,13 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) {
|
||||
PFXHttpRequestInput input(fullPath, "GET");
|
||||
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||
}
|
||||
|
||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::loginUserCallback);
|
||||
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||
connect(worker, &QObject::destroyed, [this](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -535,15 +527,11 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) {
|
||||
}
|
||||
|
||||
void PFXUserApi::loginUserCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
if (worker->error_type != QNetworkReply::NoError) {
|
||||
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||
}
|
||||
QString output;
|
||||
::test_namespace::fromStringValue(QString(worker->response), output);
|
||||
@ -567,11 +555,13 @@ void PFXUserApi::logoutUser() {
|
||||
PFXHttpRequestInput input(fullPath, "GET");
|
||||
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||
}
|
||||
|
||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::logoutUserCallback);
|
||||
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||
connect(worker, &QObject::destroyed, [this](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -581,15 +571,11 @@ void PFXUserApi::logoutUser() {
|
||||
}
|
||||
|
||||
void PFXUserApi::logoutUserCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
if (worker->error_type != QNetworkReply::NoError) {
|
||||
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -629,11 +615,13 @@ void PFXUserApi::updateUser(const QString &username, const PFXUser &body) {
|
||||
QByteArray output = body.asJson().toUtf8();
|
||||
input.request_body.append(output);
|
||||
}
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||
}
|
||||
|
||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::updateUserCallback);
|
||||
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||
connect(worker, &QObject::destroyed, [this](){
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||
emit allPendingRequestsCompleted();
|
||||
}
|
||||
@ -643,15 +631,11 @@ void PFXUserApi::updateUser(const QString &username, const PFXUser &body) {
|
||||
}
|
||||
|
||||
void PFXUserApi::updateUserCallback(PFXHttpRequestWorker *worker) {
|
||||
QString msg;
|
||||
QString error_str = worker->error_str;
|
||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
if (worker->error_type != QNetworkReply::NoError) {
|
||||
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
|
@ -52,9 +52,9 @@ public:
|
||||
void enableRequestCompression();
|
||||
void enableResponseCompression();
|
||||
void abortRequests();
|
||||
QString getParamStylePrefix(QString style);
|
||||
QString getParamStyleSuffix(QString style);
|
||||
QString getParamStyleDelimiter(QString style, QString name, bool isExplode);
|
||||
QString getParamStylePrefix(const QString &style);
|
||||
QString getParamStyleSuffix(const QString &style);
|
||||
QString getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode);
|
||||
|
||||
/**
|
||||
* @param[in] body PFXUser [required]
|
||||
@ -107,9 +107,9 @@ private:
|
||||
int _timeOut;
|
||||
QString _workingDirectory;
|
||||
QNetworkAccessManager* _manager;
|
||||
QMap<QString, QString> defaultHeaders;
|
||||
bool isResponseCompressionEnabled;
|
||||
bool isRequestCompressionEnabled;
|
||||
QMap<QString, QString> _defaultHeaders;
|
||||
bool _isResponseCompressionEnabled;
|
||||
bool _isRequestCompressionEnabled;
|
||||
|
||||
void createUserCallback(PFXHttpRequestWorker *worker);
|
||||
void createUsersWithArrayInputCallback(PFXHttpRequestWorker *worker);
|
||||
|
Loading…
x
Reference in New Issue
Block a user