File indexing completed on 2024-12-22 04:57:53

0001 /*
0002     SPDX-License-Identifier: BSD-2-Clause
0003 */
0004 
0005 #pragma once
0006 
0007 #include <QByteArray>
0008 #include <QNetworkRequest>
0009 #include <QObject>
0010 
0011 #include "o2/o1.h"
0012 
0013 class QNetworkAccessManager;
0014 class QNetworkReply;
0015 class O1;
0016 
0017 /// Makes authenticated requests using OAuth 1.0.
0018 class O1Requestor : public QObject
0019 {
0020     Q_OBJECT
0021 
0022 public:
0023     explicit O1Requestor(QNetworkAccessManager *manager, O1 *authenticator, QObject *parent = nullptr);
0024 
0025 public Q_SLOTS:
0026     /// Make a GET request.
0027     /// @param  req                 Network request.
0028     /// @param  signingParameters   Extra (non-OAuth) parameters participating in signing.
0029     /// @return Reply.
0030     QNetworkReply *get(const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters);
0031 
0032     /// Make a POST request.
0033     /// @param  req                 Network request.
0034     /// @param  signingParameters   Extra (non-OAuth) parameters participating in signing.
0035     /// @param  data                Request payload.
0036     /// @return Reply.
0037     QNetworkReply *post(const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters, const QByteArray &data);
0038 
0039     /// Make a POST request.
0040     /// @param  req                 Network request.
0041     /// @param  signingParameters   Extra (non-OAuth) parameters participating in signing.
0042     /// @param  multiPart           HTTPMultiPart.
0043     /// @return Reply.
0044     QNetworkReply *post(const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters, QHttpMultiPart *multiPart);
0045 
0046     /// Make a PUT request.
0047     /// @param  req                 Network request.
0048     /// @param  signingParameters   Extra (non-OAuth) parameters participating in signing.
0049     /// @param  data                Request payload.
0050     /// @return Reply.
0051     QNetworkReply *put(const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters, const QByteArray &data);
0052 
0053 protected:
0054     /// Return new request based on the original, with the "Authentication:" header added.
0055     QNetworkRequest setup(const QNetworkRequest &request, const QList<O0RequestParameter> &signingParameters, QNetworkAccessManager::Operation operation);
0056 
0057     /// Augment reply with a timer.
0058     QNetworkReply *addTimer(QNetworkReply *reply);
0059 
0060     QNetworkAccessManager *manager_ = nullptr;
0061     O1 *authenticator_ = nullptr;
0062 };