1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-17 12:02:48 +01:00

Use the new DI.fm/SKY.fm authentication API. Fixes issue 2909

This commit is contained in:
David Sansome 2012-05-13 15:44:11 +01:00
parent 0de061722b
commit c3fe642779

View File

@ -16,6 +16,7 @@
*/ */
#include "digitallyimportedclient.h" #include "digitallyimportedclient.h"
#include "core/logging.h"
#include "core/network.h" #include "core/network.h"
#include <qjson/parser.h> #include <qjson/parser.h>
@ -31,7 +32,7 @@ const char* DigitallyImportedClient::kApiUsername = "ephemeron";
const char* DigitallyImportedClient::kApiPassword = "dayeiph0ne@pp"; const char* DigitallyImportedClient::kApiPassword = "dayeiph0ne@pp";
const char* DigitallyImportedClient::kAuthUrl = const char* DigitallyImportedClient::kAuthUrl =
"http://api.audioaddict.com/%1/premium/auth"; "http://api.audioaddict.com/v1/%1/members/authenticate";
const char* DigitallyImportedClient::kChannelListUrl = const char* DigitallyImportedClient::kChannelListUrl =
"http://api.v2.audioaddict.com/v1/%1/mobile/batch_update?asset_group_key=mobile_icons&stream_set_key="; "http://api.v2.audioaddict.com/v1/%1/mobile/batch_update?asset_group_key=mobile_icons&stream_set_key=";
@ -67,27 +68,39 @@ DigitallyImportedClient::ParseAuthReply(QNetworkReply* reply) const {
ret.success_ = false; ret.success_ = false;
ret.error_reason_ = tr("Unknown error"); ret.error_reason_ = tr("Unknown error");
QJson::Parser parser; const int http_status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QVariantMap data = parser.parse(reply).toMap(); if (http_status == 403) {
ret.error_reason_ = reply->readAll();
if (data.value("status", QString()).toString() != "OK" || return ret;
!data.contains("user")) { } else if (http_status != 200) {
ret.error_reason_ = data.value("reason", ret.error_reason_).toString();
return ret; return ret;
} }
QVariantMap user = data["user"].toMap(); QJson::Parser parser;
if (!user.contains("first_name") || QVariantMap data = parser.parse(reply).toMap();
!user.contains("last_name") ||
!user.contains("expires") || if (!data.contains("subscriptions")) {
!user.contains("listen_hash")) return ret;
}
QVariantList subscriptions = data.value("subscriptions", QVariantList()).toList();
if (subscriptions.isEmpty() ||
subscriptions[0].toMap().value("status").toString() != "active") {
ret.error_reason_ = tr("You do not have an active subscription");
return ret;
}
if (!data.contains("first_name") ||
!data.contains("last_name") ||
!subscriptions[0].toMap().contains("expires_on") ||
!data.contains("listen_key"))
return ret; return ret;
ret.success_ = true; ret.success_ = true;
ret.first_name_ = user["first_name"].toString(); ret.first_name_ = data["first_name"].toString();
ret.last_name_ = user["last_name"].toString(); ret.last_name_ = data["last_name"].toString();
ret.expires_ = QDateTime::fromString(user["expires"].toString(), Qt::ISODate); ret.expires_ = QDateTime::fromString(subscriptions[0].toMap()["expires_on"].toString(), Qt::ISODate);
ret.listen_hash_ = user["listen_hash"].toString(); ret.listen_hash_ = data["listen_key"].toString();
return ret; return ret;
} }