[CSE] New Network Job: DeleteApiJob

This network job does a DELETE http request on a URL. It's the
second class that does basically the same, but this one returns
the http return code, and it's set to do a api call.
This commit is contained in:
Tomaz Canabrava 2017-08-25 14:59:13 +02:00 committed by Roeland Jago Douma
parent e2091bb0a3
commit 5b51346e83
No known key found for this signature in database
GPG key ID: F941078878347C0C
2 changed files with 54 additions and 0 deletions

View file

@ -820,6 +820,7 @@ bool JsonApiJob::finished()
return true;
}
DetermineAuthTypeJob::DetermineAuthTypeJob(AccountPtr account, QObject *parent)
: AbstractNetworkJob(account, QString(), parent)
, _redirects(0)
@ -907,4 +908,36 @@ bool SimpleNetworkJob::finished()
return true;
}
DeleteApiJob::DeleteApiJob(AccountPtr account, const QString &path, QObject *parent)
: AbstractNetworkJob(account, path, parent)
{
}
void DeleteApiJob::start()
{
QNetworkRequest req;
req.setRawHeader("OCS-APIREQUEST", "true");
QUrl url = Utility::concatUrlPath(account()->url(), path());
sendRequest("DELETE", url, req);
AbstractNetworkJob::start();
}
bool DeleteApiJob::finished()
{
qCInfo(lcJsonApiJob) << "JsonApiJob of" << reply()->request().url() << "FINISHED WITH STATUS"
<< reply()->error()
<< (reply()->error() == QNetworkReply::NoError ? QLatin1String("") : errorString());
int statusCode = 0;
if (reply()->error() != QNetworkReply::NoError) {
qCWarning(lcJsonApiJob) << "Network error: " << path() << errorString() << reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute);
emit result(statusCode);
return true;
}
const auto replyData = QString::fromUtf8(reply()->readAll());
qCInfo(lcJsonApiJob()) << "TMX Delete Job" << replyData;
}
} // namespace OCC

View file

@ -41,6 +41,27 @@ private slots:
virtual bool finished() Q_DECL_OVERRIDE;
};
/**
* @brief sends a DELETE http request to a url.
*
* See Nextcloud API usage for the possible DELETE requests.
*
* This does *not* delete files, it does a http request.
*/
class OWNCLOUDSYNC_EXPORT DeleteApiJob : public AbstractNetworkJob
{
Q_OBJECT
public:
explicit DeleteApiJob(AccountPtr account, const QString &path, QObject *parent = 0);
void start() override;
signals:
void result(int httpCode);
private slots:
virtual bool finished() override;
};
struct ExtraFolderInfo {
QByteArray fileId;
qint64 size = -1;