Equipment update on Strava download

This is a simpler and more efficient version of 96c8508, no need to use
getGearById service since SummaryGear is already available in DetailedActivity
This commit is contained in:
Ale Martinez
2021-04-30 21:26:02 -03:00
parent 9ff6d6ab97
commit c9e01353a0
2 changed files with 7 additions and 49 deletions

View File

@@ -686,53 +686,6 @@ Strava::addSamples(RideFile* ret, QString remoteid)
}
}
void
Strava::addEquipment(RideFile* ret, QString gear_id)
{
printd("Strava::addEquipment(%s)\n", gear_id.toStdString().c_str());
// do we have a token ?
QString token = getSetting(GC_STRAVA_TOKEN, "").toString();
if (token == "") return;
// lets connect and get equipment info
QString urlstr = QString("https://www.strava.com/api/v3/gear/%1").arg(gear_id);
QUrl url = QUrl( urlstr );
printd("url:%s\n", url.url().toStdString().c_str());
// request using the bearer token
QNetworkRequest request(url);
request.setRawHeader("Authorization", (QString("Bearer %1").arg(token)).toLatin1());
// put the file
QNetworkReply *reply = nam->get(request);
// blocking request
QEventLoop loop;
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
if (reply->error() != QNetworkReply::NoError) {
qDebug() << "error" << reply->errorString();
return;
}
// did we get a good response ?
QByteArray r = reply->readAll();
printd("response: %s\n", r.toStdString().c_str());
QJsonParseError parseError;
QJsonDocument document = QJsonDocument::fromJson(r, &parseError);
// if path was returned all is good, lets set Equipment
if (parseError.error == QJsonParseError::NoError) {
// Just name, for now
if (!document["name"].isNull()) {
ret->setTag("Equipment", document["name"].toString());
}
}
}
void
Strava:: fixLapSwim(RideFile* ret, QJsonArray laps)
{
@@ -973,6 +926,13 @@ Strava::prepareResponse(QByteArray* data)
ride->setTag("Trainer", each["trainer"].toBool() ? "1" : "0");
}
if (each["gear"].isObject()) {
QJsonObject gear = each["gear"].toObject();
if (gear["name"].isString()) {
ride->setTag("Equipment", gear["name"].toString());
}
}
if (each["manual"].toBool()) {
if (each["distance"].toDouble()>0) {
QMap<QString,QString> map;
@@ -998,7 +958,6 @@ Strava::prepareResponse(QByteArray* data)
} else {
addSamples(ride, QString("%1").arg(each["id"].toVariant().toULongLong()));
if (!each["gear_id"].isNull()) addEquipment(ride, each["gear_id"].toString());
// laps?
if (!each["laps"].isNull()) {
QJsonArray laps = each["laps"].toArray();

View File

@@ -77,7 +77,6 @@ class Strava : public CloudService {
QByteArray* prepareResponse(QByteArray* data);
void addSamples(RideFile* ret, QString remoteid);
void addEquipment(RideFile* ret, QString gear_id);
void fixLapSwim(RideFile* ret, QJsonArray laps);
void fixSmartRecording(RideFile* ret);