Commit e5d06cc6 authored by Volker Krause's avatar Volker Krause
Browse files

Parse GBFS version discovery data

We yet have to make use of this though, which will require a bit of
restructuring here to be able to re-start the discovery process when
we find a newer feed version.
parent 0c76e62b
......@@ -226,6 +226,9 @@ void GBFSJob::parseData(const QJsonDocument &doc, GBFS::FileType type)
case GBFS::FreeBikeStatus:
parseFreeBikeStatus(doc);
break;
case GBFS::Versions:
parseVersionData(doc);
break;
default:
break;
}
......@@ -334,6 +337,28 @@ void GBFSJob::computeBoundingBox(const QJsonArray &array)
});
}
void GBFSJob::parseVersionData(const QJsonDocument &doc)
{
const auto versions = doc.object().value(QLatin1String("data")).toObject().value(QLatin1String("versions")).toArray();
QJsonObject bestVersion;
for (const auto &verVal : versions) {
const auto version = verVal.toObject();
if (bestVersion.isEmpty()) {
bestVersion = version;
}
if (QVersionNumber::fromString(bestVersion.value(QLatin1String("version")).toString()) < QVersionNumber::fromString(version.value(QLatin1String("version")).toString())) {
bestVersion = version;
}
}
const auto url = QUrl(bestVersion.value(QLatin1String("url")).toString());
if (!url.isEmpty() && m_service.discoveryUrl != url) {
qDebug() << "found newer version:" << url << m_service.discoveryUrl;
m_service.discoveryUrl = url;
// TODO update feed url and restart the job
}
}
void GBFSJob::finalize()
{
if (m_maxLat > m_minLat && m_maxLon > m_minLon) {
......
......@@ -60,6 +60,7 @@ private:
void parseStationInformation(const QJsonDocument &doc);
void parseFreeBikeStatus(const QJsonDocument &doc);
void computeBoundingBox(const QJsonArray &array);
void parseVersionData(const QJsonDocument &doc);
void finalize();
QNetworkAccessManager *m_nam = nullptr;
......
Supports Markdown
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