Commit 7f9d16d8 authored by Volker Krause's avatar Volker Krause
Browse files

Cleanup handling of pass update URLs

parent 6deb3479
......@@ -154,10 +154,7 @@ void PkPassManager::updatePass(const QString& passId)
if (relevantDate(p) < QDateTime::currentDateTimeUtc()) // TODO check expiration date and voided property
return;
QUrl url(p->webServiceUrl());
url.setPath(url.path() + QLatin1String("/v1/passes/") + p->passTypeIdentifier() + QLatin1Char('/') + p->serialNumber());
qCDebug(Log) << "GET" << url;
QNetworkRequest req(url);
QNetworkRequest req(p->passUpdateUrl());
req.setRawHeader("Authorization", "ApplePass " + p->authenticationToken().toUtf8());
req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
auto reply = m_nam->get(req);
......
......@@ -36,6 +36,7 @@
#include <QLocale>
#include <QTextCodec>
#include <QImage>
#include <QUrl>
using namespace KPkPass;
......@@ -373,9 +374,19 @@ QString Pass::authenticationToken() const
return d->passObj.value(QLatin1String("authenticationToken")).toString();
}
QString Pass::webServiceUrl() const
QUrl Pass::webServiceUrl() const
{
return d->passObj.value(QLatin1String("webServiceURL")).toString();
return QUrl(d->passObj.value(QLatin1String("webServiceURL")).toString());
}
QUrl Pass::passUpdateUrl() const
{
QUrl url(webServiceUrl());
if (!url.isValid()) {
return {};
}
url.setPath(url.path() + QLatin1String("/v1/passes/") + passTypeIdentifier() + QLatin1Char('/') + serialNumber());
return url;
}
QVector<Barcode> Pass::barcodes() const
......
......@@ -33,6 +33,7 @@
class QByteArray;
class QString;
class QUrl;
namespace KPkPass {
......@@ -64,9 +65,6 @@ class KPKPASS_EXPORT Pass : public QObject
Q_PROPERTY(QColor labelColor READ labelColor CONSTANT)
Q_PROPERTY(QString logoText READ logoText CONSTANT)
Q_PROPERTY(QString authenticationToken READ authenticationToken CONSTANT)
Q_PROPERTY(QString webServiceUrl READ webServiceUrl CONSTANT)
// needs to be QVariantList just for QML (Grantlee would also work with QVector<Field>
Q_PROPERTY(QVariantList barcodes READ barcodesVariant CONSTANT)
Q_PROPERTY(QVariantList auxiliaryFields READ auxiliaryFieldsVariant CONSTANT)
......@@ -127,7 +125,11 @@ public:
// web service keys
QString authenticationToken() const;
QString webServiceUrl() const;
QUrl webServiceUrl() const;
/** Pass update URL.
* @see https://developer.apple.com/library/content/documentation/PassKit/Reference/PassKit_WebService/WebService.html
*/
QUrl passUpdateUrl() const;
QVector<Field> auxiliaryFields() const;
QVector<Field> backFields() const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment