File indexing completed on 2024-05-12 05:09:27

0001 /***************************************************************************
0002     Copyright (C) 2007-2020 Robby Stephenson <robby@periapsis.org>
0003  ***************************************************************************/
0004 
0005 /***************************************************************************
0006  *                                                                         *
0007  *   This program is free software; you can redistribute it and/or         *
0008  *   modify it under the terms of the GNU General Public License as        *
0009  *   published by the Free Software Foundation; either version 2 of        *
0010  *   the License or (at your option) version 3 or any later version        *
0011  *   accepted by the membership of KDE e.V. (or its successor approved     *
0012  *   by the membership of KDE e.V.), which shall act as a proxy            *
0013  *   defined in Section 14 of version 3 of the license.                    *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful,       *
0016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0018  *   GNU General Public License for more details.                          *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0022  *                                                                         *
0023  ***************************************************************************/
0024 
0025 #ifndef TELLICO_FETCH_AMAZONREQUEST_H
0026 #define TELLICO_FETCH_AMAZONREQUEST_H
0027 
0028 #include <QUrl>
0029 #include <QMap>
0030 
0031 class AmazonFetcherTest;
0032 
0033 namespace Tellico {
0034   namespace Fetch {
0035 
0036 /**
0037  * @author Robby Stephenson
0038  */
0039 class AmazonRequest {
0040 
0041 friend class ::AmazonFetcherTest;
0042 
0043 public:
0044   enum Operation {
0045     SearchItems,
0046     GetItems
0047   };
0048 
0049   AmazonRequest(const QString& accessKey_, const QString& secretKey_);
0050 
0051   void setHost(const QByteArray& host);
0052   void setPath(const QByteArray& path);
0053   void setRegion(const QByteArray& region);
0054   void setOperation(int op);
0055   QMap<QByteArray, QByteArray> headers(const QByteArray& payload);
0056 
0057 private:
0058   QByteArray prepareCanonicalRequest(const QByteArray& payload) const;
0059   QByteArray prepareStringToSign(const QByteArray& canonicalUrl) const;
0060   QByteArray calculateSignature(const QByteArray& stringToSign) const;
0061   QByteArray buildAuthorizationString(const QByteArray& signature) const;
0062   QByteArray toHexHash(const QByteArray& data) const;
0063   QByteArray targetOperation() const;
0064 
0065   QMap<QByteArray, QByteArray> m_headers;
0066   QByteArray m_accessKey;
0067   QByteArray m_secretKey;
0068   QByteArray m_method;
0069   QByteArray m_service;
0070   QByteArray m_host;
0071   QByteArray m_region;
0072   QByteArray m_path;
0073   QByteArray m_amzDate;
0074   Operation m_operation;
0075   mutable QByteArray m_signedHeaders;
0076 };
0077 
0078   } // end Fetch namespace
0079 } // end Tellico namespace
0080 
0081 #endif