Skip to content

Commit

Permalink
Fix tags bugs for last objects
Browse files Browse the repository at this point in the history
Needed to check if the token was an array or not and continue from there
to the appropriate action.
  • Loading branch information
haroldma-zz committed Oct 22, 2014
1 parent 150d50f commit 07a5fab
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/IF.Lastfm.Core/Objects/LastAlbum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ internal static LastAlbum ParseJToken(JToken token)
{
var tagToken = tagsToken.SelectToken("tag");
if (tagToken != null)
a.TopTags = tagToken.Children().Select(LastTag.ParseJToken);
{
a.TopTags =
tagToken.Type == JTokenType.Array
? tagToken.Children().Select(LastTag.ParseJToken)
: new List<LastTag> { LastTag.ParseJToken(tagToken) };
}
}

a.ListenerCount = token.Value<int>("listeners");
Expand Down
11 changes: 9 additions & 2 deletions src/IF.Lastfm.Core/Objects/LastArtist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ internal static LastArtist ParseJToken(JToken token)
a.OnTour = Convert.ToBoolean(token.Value<int>("ontour"));

var tagsToken = token.SelectToken("tags");
if (tagsToken != null && tagsToken.HasValues)
if (tagsToken != null)
{
a.Tags = tagsToken.SelectToken("tag").Children().Select(LastTag.ParseJToken);
var tagToken = tagsToken.SelectToken("tag");
if (tagToken != null)
{
a.Tags =
tagToken.Type == JTokenType.Array
? tagToken.Children().Select(LastTag.ParseJToken)
: new List<LastTag> { LastTag.ParseJToken(tagToken) };
}
}

var images = token.SelectToken("image");
Expand Down
11 changes: 9 additions & 2 deletions src/IF.Lastfm.Core/Objects/LastTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,16 @@ internal static LastTrack ParseJToken(JToken token)
}

var tagsToken = token.SelectToken("toptags");
if (tagsToken != null && tagsToken.HasValues)
if (tagsToken != null)
{
t.TopTags = tagsToken.SelectToken("tag").Children().Select(LastTag.ParseJToken);
var tagToken = tagsToken.SelectToken("tag");
if (tagToken != null)
{
t.TopTags =
tagToken.Type == JTokenType.Array
? tagToken.Children().Select(LastTag.ParseJToken)
: new List<LastTag> { LastTag.ParseJToken(tagToken) };
}
}

var date = token.SelectToken("date");
Expand Down

0 comments on commit 07a5fab

Please sign in to comment.