Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed GetTop commands from the Tag Api #176

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading