Skip to content

Commit

Permalink
Fixed GetTop commands from the Tag Api to match Lastfm's official res…
Browse files Browse the repository at this point in the history
…ponse schemas
  • Loading branch information
eivanmariscal committed Oct 5, 2023
1 parent 902b6e6 commit 0f2832e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"topalbums": {
"albums": {
"album": {
"name": "Number Ones",
"mbid": "12cc16cb-5649-4e1a-bd10-a8a496280990",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"topalbums": {
"albums": {
"album": [
{
"name": "Number Ones",
Expand Down
2 changes: 1 addition & 1 deletion src/IF.Lastfm.Core/Api/Commands/Tag/GetTopAlbumsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override async Task<PageResponse<LastAlbum>> HandleResponse(HttpResponseM
if (LastFm.IsResponseValid(json, out status) && response.IsSuccessStatusCode)
{
var jtoken = JsonConvert.DeserializeObject<JToken>(json);
var resultsToken = jtoken.SelectToken("topalbums");
var resultsToken = jtoken.SelectToken("albums");
var itemsToken = resultsToken.SelectToken("album");

return PageResponse<LastAlbum>.CreateSuccessResponse(itemsToken, resultsToken, LastAlbum.ParseJToken, LastPageResultsType.Attr);
Expand Down
2 changes: 1 addition & 1 deletion src/IF.Lastfm.Core/Api/Commands/Tag/GetTopTracksCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override async Task<PageResponse<LastTrack>> HandleResponse(HttpResponseM
if (LastFm.IsResponseValid(json, out status) && response.IsSuccessStatusCode)
{
var jtoken = JsonConvert.DeserializeObject<JToken>(json);
var resultsToken = jtoken.SelectToken("toptracks");
var resultsToken = jtoken.SelectToken("tracks");
var itemsToken = resultsToken.SelectToken("track");

return PageResponse<LastTrack>.CreateSuccessResponse(itemsToken, resultsToken, LastTrack.ParseJToken, LastPageResultsType.Attr);
Expand Down
15 changes: 13 additions & 2 deletions src/IF.Lastfm.Core/Objects/LastTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public LastTag(string name, string uri, int? count = null)
Count = count;
}

public LastTag(string name, int? count = null)
{
Name = name;
Count = count;
}

internal static LastTag ParseJToken(JToken token)
{
return ParseJToken(token, null);
Expand All @@ -43,7 +49,11 @@ internal static LastTag ParseJToken(JToken token)
internal static LastTag ParseJToken(JToken token, string relatedTag)
{
var name = token.Value<string>("name");
var url = token.Value<string>("url");

Uri uri = null;
var urlToken = token.Value<string>("url");
if (!String.IsNullOrWhiteSpace(urlToken))
uri = new Uri(urlToken, UriKind.RelativeOrAbsolute);

int? count = null;
var countToken = token.SelectToken("count") ?? token.SelectToken("taggings");
Expand All @@ -66,8 +76,9 @@ internal static LastTag ParseJToken(JToken token, string relatedTag)
reach = reachToken.ToObject<int?>();
}

return new LastTag(name, url, count)
return new LastTag(name, count)
{
Url = uri,
Streamable = streamable,
RelatedTo = relatedTag,
Reach = reach
Expand Down

0 comments on commit 0f2832e

Please sign in to comment.