Initial commit. First draft v0.1
This commit is contained in:
58
yourlsclient.h
Normal file
58
yourlsclient.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#ifndef YOURLSCLIENT_H
|
||||
#define YOURLSCLIENT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
|
||||
class QNetworkAccessManager;
|
||||
|
||||
/**
|
||||
* @brief Small value object describing YOURLS API settings.
|
||||
*/
|
||||
struct YourlsSettings {
|
||||
QString apiUrl;
|
||||
QString signature;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Client responsible for communication with the YOURLS API.
|
||||
*
|
||||
* The class builds a signed YOURLS request, sends it over HTTP(S),
|
||||
* parses the JSON response and returns either a short URL or a detailed
|
||||
* error string.
|
||||
*/
|
||||
class YourlsClient : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs the client.
|
||||
* @param parent QObject parent.
|
||||
*/
|
||||
explicit YourlsClient (QObject *parent = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Requests a short URL from the YOURLS API.
|
||||
* @param settings API endpoint and signature.
|
||||
* @param longUrl Source URL to shorten.
|
||||
*/
|
||||
void shortenUrl (const YourlsSettings &settings, const QUrl &longUrl);
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Emitted when the short URL has been created successfully.
|
||||
* @param shortUrl Generated short URL.
|
||||
*/
|
||||
void shortenSucceeded (const QUrl &shortUrl);
|
||||
|
||||
/**
|
||||
* @brief Emitted when the request fails.
|
||||
* @param details Human-readable error details.
|
||||
*/
|
||||
void shortenFailed (const QString &details);
|
||||
|
||||
private:
|
||||
QNetworkAccessManager *m_networkAccessManager;
|
||||
};
|
||||
|
||||
#endif // YOURLSCLIENT_H
|
||||
Reference in New Issue
Block a user