diff --git a/src/IF.Lastfm.Core.Tests/Api/Commands/UserGetLovedTracksCommandTests.cs b/src/IF.Lastfm.Core.Tests/Api/Commands/UserGetLovedTracksCommandTests.cs new file mode 100644 index 0000000..b561f48 --- /dev/null +++ b/src/IF.Lastfm.Core.Tests/Api/Commands/UserGetLovedTracksCommandTests.cs @@ -0,0 +1,93 @@ +using IF.Lastfm.Core.Api.Enums; +using IF.Lastfm.Core.Objects; +using IF.Lastfm.Core.Tests.Resources; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using IF.Lastfm.Core.Api.Commands.User; +using Newtonsoft.Json.Linq; + +namespace IF.Lastfm.Core.Tests.Api.Commands +{ + using System.Web.Configuration; + + class UserGetLovedTracksCommandTests : CommandTestsBase + { + [Test] + public async Task HandleResponseMultiple() + { + var command = new GetLovedTracksCommand(MAuth.Object, "rj") + { + Count = 3 + }; + + var expectedTrack = new LastTrack + { + ArtistName = "The Rolling Stones", + TimePlayed = new DateTime(2014, 12, 19, 16, 16, 56, DateTimeKind.Utc), + Mbid = "3dde65c8-22c3-4637-b67e-b234177c847b", + Name = "Love in Vain", + ArtistMbid = "b071f9fa-14b0-4217-8e97-eb41da73f598", + AlbumName = "Let It Bleed", + Url = new Uri("http://www.last.fm/music/The+Rolling+Stones/_/Love+in+Vain"), + Images = new LastImageSet( + "http://userserve-ak.last.fm/serve/34s/101739037.png", + "http://userserve-ak.last.fm/serve/64s/101739037.png", + "http://userserve-ak.last.fm/serve/126/101739037.png", + "http://userserve-ak.last.fm/serve/300x300/101739037.png") + }; + var response = CreateResponseMessage(Encoding.UTF8.GetString(UserApiResponses.UserGetLovedTracksMultiple)); + var actual = await command.HandleResponse(response); + + Assert.IsTrue(actual.Success); + TestHelper.AssertSerialiseEqual(expectedTrack, actual.Content[1]); + } + + [Test] + public async Task HandleResponseSingle() + { + var command = new GetLovedTracksCommand(MAuth.Object, "rj") + { + Count = 1 + }; + var expectedTrack = new LastTrack + { + ArtistName = "Rick James", + Mbid = "", + Name = "Super Freak (Part 1) - 1981 Single Version", + ArtistMbid = "cba9cec2-be8d-41bd-91b4-a1cd7de39b0c", + + TimePlayed = new DateTime(2014, 12, 20, 10, 16, 52, DateTimeKind.Utc), + AlbumName = "The Definitive Collection", + Url = new Uri("http://www.last.fm/music/Rick+James/_/Super+Freak+(Part+1)+-+1981+Single+Version", UriKind.Absolute), + Images = new LastImageSet( + "http://userserve-ak.last.fm/serve/34s/90462319.jpg", + "http://userserve-ak.last.fm/serve/64s/90462319.jpg", + "http://userserve-ak.last.fm/serve/126/90462319.jpg", + "http://userserve-ak.last.fm/serve/300x300/90462319.jpg") + }; + var response = CreateResponseMessage(Encoding.UTF8.GetString(UserApiResponses.UserGetLovedTracksSingle)); + var actual = await command.HandleResponse(response); + + Assert.IsTrue(actual.Success); + TestHelper.AssertSerialiseEqual(expectedTrack, actual.Single()); + } + + [Test] + public async Task HandleErrorResponse() + { + var command = new GetRecentTracksCommand(MAuth.Object, "rj") + { + Count = 1 + }; + var response = CreateResponseMessage(Encoding.UTF8.GetString(UserApiResponses.UserGetRecentTracksError)); + var parsed = await command.HandleResponse(response); + + Assert.IsFalse(parsed.Success); + Assert.IsTrue(parsed.Status == LastResponseStatus.MissingParameters); + } + } +} diff --git a/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj b/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj index 0ae567c..990ba45 100644 --- a/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj +++ b/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj @@ -97,6 +97,7 @@ + @@ -199,6 +200,9 @@ + + + diff --git a/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetLovedTracksError.json b/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetLovedTracksError.json new file mode 100644 index 0000000..9c9ef1f --- /dev/null +++ b/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetLovedTracksError.json @@ -0,0 +1,5 @@ +{ + "error": 6, + "message": "Invalid parameters - Your request is missing the [user] parameter", + "links": [] +} \ No newline at end of file diff --git a/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetLovedTracksMultiple.json b/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetLovedTracksMultiple.json new file mode 100644 index 0000000..9a65838 --- /dev/null +++ b/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetLovedTracksMultiple.json @@ -0,0 +1,733 @@ +{ + "lovedtracks": { + "track": [ + { + "artist": { + "#text": "Santana", + "mbid": "1bc6816a-d056-4113-9b0a-6c52e5c31a3c" + }, + "name": "No One to Depend On", + "streamable": "0", + "mbid": "3f8ed8da-dcc6-43dc-8266-3663007261a6", + "album": { + "#text": "Santana (III)", + "mbid": "" + }, + "url": "http://www.last.fm/music/Santana/_/No+One+to+Depend+On", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/99461493.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/99461493.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/99461493.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/99461493.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 16:21", + "uts": "1419006075" + } + }, + { + "artist": { + "#text": "The Rolling Stones", + "mbid": "b071f9fa-14b0-4217-8e97-eb41da73f598" + }, + "name": "Love in Vain", + "streamable": "0", + "mbid": "3dde65c8-22c3-4637-b67e-b234177c847b", + "album": { + "#text": "Let It Bleed", + "mbid": "8bc2f5e2-122a-42db-b86c-fddedc77463a" + }, + "url": "http://www.last.fm/music/The+Rolling+Stones/_/Love+in+Vain", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/101739037.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/101739037.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/101739037.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/101739037.png", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 16:16", + "uts": "1419005816" + } + }, + { + "artist": { + "#text": "The Who", + "mbid": "9fdaa16b-a6c4-4831-b87c-bc9ca8ce7eaa" + }, + "name": "Pinball Wizard", + "streamable": "0", + "mbid": "79f3dc97-2297-47ee-8556-9a1bb4b48d53", + "album": { + "#text": "Tommy (Remastered)", + "mbid": "" + }, + "url": "http://www.last.fm/music/The+Who/_/Pinball+Wizard", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/35234991.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/35234991.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/35234991.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/35234991.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 16:13", + "uts": "1419005635" + } + }, + { + "artist": { + "#text": "Cream", + "mbid": "04cd0cfd-bfd1-4c36-bc38-95c35e2c045f" + }, + "name": "I'm So Glad", + "streamable": "0", + "mbid": "3dc91be5-c7ab-4af3-9557-19eb8e054d5a", + "album": { + "#text": "Fresh Cream (Remastered)", + "mbid": "" + }, + "url": "http://www.last.fm/music/Cream/_/I%27m+So+Glad", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/89387215.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/89387215.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/89387215.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/89387215.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 16:09", + "uts": "1419005395" + } + }, + { + "artist": { + "#text": "The Yardbirds", + "mbid": "191de76f-a224-445d-b041-54df16d65bf7" + }, + "name": "Smokestack Lightning", + "streamable": "0", + "mbid": "580b35c9-b701-43d7-9ec3-6bd6f01534c2", + "album": { + "#text": "Five Live Yardbirds", + "mbid": "3fda56ac-efe1-4a26-9c86-116f5cc4b721" + }, + "url": "http://www.last.fm/music/The+Yardbirds/_/Smokestack+Lightning", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/91925037.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/91925037.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/91925037.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/91925037.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 16:04", + "uts": "1419005063" + } + }, + { + "artist": { + "#text": "Canned Heat", + "mbid": "815a0279-558c-4522-ac3b-6a1e259e95b5" + }, + "name": "One Kind Favor", + "streamable": "0", + "mbid": "5bde419b-9e93-46c6-baf5-ef58a0b3bb73", + "album": { + "#text": "Living The Blues", + "mbid": "ec82ab15-8c01-4aa0-810c-d184d20f229b" + }, + "url": "http://www.last.fm/music/Canned+Heat/_/One+Kind+Favor", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/100370719.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/100370719.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/100370719.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/100370719.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:59", + "uts": "1419004779" + } + }, + { + "artist": { + "#text": "Cream", + "mbid": "04cd0cfd-bfd1-4c36-bc38-95c35e2c045f" + }, + "name": "Politician", + "streamable": "0", + "mbid": "f2c2760c-ea5c-4ca0-8a8b-4199a41ffba0", + "album": { + "#text": "Wheels of Fire (Remastered)", + "mbid": "" + }, + "url": "http://www.last.fm/music/Cream/_/Politician", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/75021714.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/75021714.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/75021714.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/75021714.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:55", + "uts": "1419004522" + } + }, + { + "artist": { + "#text": "The Doors", + "mbid": "9efff43b-3b29-4082-824e-bc82f646f93d" + }, + "name": "Light My Fire", + "streamable": "0", + "mbid": "05b7cd66-a700-4aa1-baf3-e1e41388f3cf", + "album": { + "#text": "The Doors", + "mbid": "8f3cf206-35f6-3c77-925e-766bdfbf6333" + }, + "url": "http://www.last.fm/music/The+Doors/_/Light+My+Fire", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/88289473.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/88289473.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/88289473.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/88289473.png", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:48", + "uts": "1419004096" + } + }, + { + "artist": { + "#text": "Full Metal Hammer", + "mbid": "" + }, + "name": "Since Ive Been Loving You", + "streamable": "0", + "mbid": "", + "album": { + "#text": "It's A Full Metal Hammer Thing", + "mbid": "" + }, + "url": "http://www.last.fm/music/Full+Metal+Hammer/_/Since+Ive+Been+Loving+You", + "image": [ + { + "#text": "", + "size": "small" + }, + { + "#text": "", + "size": "medium" + }, + { + "#text": "", + "size": "large" + }, + { + "#text": "", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:41", + "uts": "1419003662" + } + }, + { + "artist": { + "#text": "The Jimi Hendrix Experience", + "mbid": "33b3c323-77c2-417c-a5b4-af7e6a111cc9" + }, + "name": "Burning Of The Midnight Lamp", + "streamable": "0", + "mbid": "1a1c8a21-351d-4c43-8ed4-3fd3f5058e1b", + "album": { + "#text": "Electric Ladyland", + "mbid": "9fa7f446-b15c-3ad9-a4cc-3348e9140319" + }, + "url": "http://www.last.fm/music/The+Jimi+Hendrix+Experience/_/Burning+Of+The+Midnight+Lamp", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/96516997.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/96516997.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/96516997.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/96516997.png", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:37", + "uts": "1419003443" + } + }, + { + "artist": { + "#text": "Otis Rush", + "mbid": "40ee7c92-f44a-4d14-9aee-f87244465ee4" + }, + "name": "Double Trouble", + "streamable": "0", + "mbid": "f23c009e-19c4-4196-8fe2-236c28546bfc", + "album": { + "#text": "Live At Montreux 1986", + "mbid": "" + }, + "url": "http://www.last.fm/music/Otis+Rush/_/Double+Trouble", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/91112769.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/91112769.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/91112769.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/91112769.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:32", + "uts": "1419003132" + } + }, + { + "artist": { + "#text": "The Yardbirds", + "mbid": "191de76f-a224-445d-b041-54df16d65bf7" + }, + "name": "I Don't Care No More", + "streamable": "0", + "mbid": "30e22d26-15f7-4547-a0f4-b08feed1a7fc", + "album": { + "#text": "Rock Classics: Parable Of Arable Land", + "mbid": "" + }, + "url": "http://www.last.fm/music/The+Yardbirds/_/I+Don%27t+Care+No+More", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/54760139.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/54760139.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/54760139.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/174s/54760139.png", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:28", + "uts": "1419002911" + } + }, + { + "artist": { + "#text": "The Doors", + "mbid": "9efff43b-3b29-4082-824e-bc82f646f93d" + }, + "name": "Crawling King Snake", + "streamable": "0", + "mbid": "a08905e0-dc59-47fe-ae93-be5bb0d22a84", + "album": { + "#text": "L.A. Woman", + "mbid": "492025d7-a5fd-40f0-94f9-8841e9078bb3" + }, + "url": "http://www.last.fm/music/The+Doors/_/Crawling+King+Snake", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/88488175.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/88488175.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/88488175.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/88488175.png", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:23", + "uts": "1419002612" + } + }, + { + "artist": { + "#text": "Jimmy Page", + "mbid": "519774a4-3b18-4042-b8c0-927845a616c9" + }, + "name": "Prison Blues", + "streamable": "0", + "mbid": "f78a2ce9-3dba-439c-9e05-0783ccfa40c3", + "album": { + "#text": "Outrider", + "mbid": "a53095c1-a6ea-4bc9-a14c-6ecafeef738e" + }, + "url": "http://www.last.fm/music/Jimmy+Page/_/Prison+Blues", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/90138723.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/90138723.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/90138723.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/90138723.png", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:16", + "uts": "1419002181" + } + }, + { + "artist": { + "#text": "Cream", + "mbid": "04cd0cfd-bfd1-4c36-bc38-95c35e2c045f" + }, + "name": "Spoonful", + "streamable": "0", + "mbid": "f6f5d7f0-b368-45c0-8505-4b33ac696035", + "album": { + "#text": "Fresh Cream (Remastered)", + "mbid": "" + }, + "url": "http://www.last.fm/music/Cream/_/Spoonful", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/89387215.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/89387215.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/89387215.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/89387215.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:09", + "uts": "1419001787" + } + }, + { + "artist": { + "#text": "The Doors", + "mbid": "9efff43b-3b29-4082-824e-bc82f646f93d" + }, + "name": "Back Door Man", + "streamable": "0", + "mbid": "1976f693-f35f-4534-b341-31d51f46b208", + "album": { + "#text": "The Doors", + "mbid": "8f3cf206-35f6-3c77-925e-766bdfbf6333" + }, + "url": "http://www.last.fm/music/The+Doors/_/Back+Door+Man", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/88289473.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/88289473.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/88289473.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/88289473.png", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:06", + "uts": "1419001574" + } + }, + { + "artist": { + "#text": "The Yardbirds", + "mbid": "191de76f-a224-445d-b041-54df16d65bf7" + }, + "name": "I Ain't Got You", + "streamable": "0", + "mbid": "19ee6ab9-1716-41e1-8aa7-cada544f5695", + "album": { + "#text": "Five Live", + "mbid": "" + }, + "url": "http://www.last.fm/music/The+Yardbirds/_/I+Ain%27t+Got+You", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/87032633.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/87032633.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/87032633.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/87032633.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:04", + "uts": "1419001453" + } + }, + { + "artist": { + "#text": "The Who", + "mbid": "9fdaa16b-a6c4-4831-b87c-bc9ca8ce7eaa" + }, + "name": "Substitute (Remixed Live At Leeds Version)", + "streamable": "0", + "mbid": "", + "album": { + "#text": "Live At Leeds (25th Anniversary Edition)", + "mbid": "" + }, + "url": "http://www.last.fm/music/The+Who/_/Substitute+(Remixed+Live+At+Leeds+Version)", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/82286267.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/82286267.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/82286267.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/82286267.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:01", + "uts": "1419001281" + } + }, + { + "artist": { + "#text": "Cream", + "mbid": "04cd0cfd-bfd1-4c36-bc38-95c35e2c045f" + }, + "name": "Tales of Brave Ulysses", + "streamable": "0", + "mbid": "f5e62507-07f1-45eb-83c6-6742d5260d06", + "album": { + "#text": "Disraeli Gears (Remastered)", + "mbid": "" + }, + "url": "http://www.last.fm/music/Cream/_/Tales+of+Brave+Ulysses", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/57500153.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/57500153.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/57500153.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/57500153.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 14:58", + "uts": "1419001115" + } + }, + { + "artist": { + "#text": "Jimi Hendrix", + "mbid": "06fb1c8b-566e-4cb2-985b-b467c90781d4" + }, + "name": "Johnny B. Goode (Live Berkeley Community Center, Berkeley, CA May 30, 1970)", + "streamable": "0", + "mbid": "", + "album": { + "#text": "In The West", + "mbid": "" + }, + "url": "http://www.last.fm/music/Jimi+Hendrix/_/Johnny+B.+Goode+(Live+Berkeley+Community+Center,+Berkeley,+CA+May+30,+1970)", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/78579114.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/78579114.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/78579114.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/78579114.png", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 14:53", + "uts": "1419000831" + } + } + ], + "@attr": { + "user": "RJ", + "page": "0", + "perPage": "20", + "totalPages": "3827", + "total": "76526" + } + } +} \ No newline at end of file diff --git a/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetLovedTracksSingle.json b/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetLovedTracksSingle.json new file mode 100644 index 0000000..87fa849 --- /dev/null +++ b/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetLovedTracksSingle.json @@ -0,0 +1,47 @@ +{ + "lovedtracks": { + "track": { + "artist": { + "#text": "Rick James", + "mbid": "cba9cec2-be8d-41bd-91b4-a1cd7de39b0c" + }, + "name": "Super Freak (Part 1) - 1981 Single Version", + "streamable": "0", + "mbid": "", + "album": { + "#text": "The Definitive Collection", + "mbid": "f22c19bf-1c88-4651-a0d3-8c50735f3c93" + }, + "url": "http://www.last.fm/music/Rick+James/_/Super+Freak+(Part+1)+-+1981+Single+Version", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/90462319.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/90462319.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/90462319.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/90462319.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "20 Dec 2014, 10:16", + "uts": "1419070612" + } + }, + "@attr": { + "user": "RJ", + "page": "0", + "perPage": "1", + "totalPages": "76536", + "total": "76536" + } + } +} \ No newline at end of file diff --git a/src/IF.Lastfm.Core.Tests/Resources/UserApiResponses.Designer.cs b/src/IF.Lastfm.Core.Tests/Resources/UserApiResponses.Designer.cs index 2c3bf41..b1ec920 100644 --- a/src/IF.Lastfm.Core.Tests/Resources/UserApiResponses.Designer.cs +++ b/src/IF.Lastfm.Core.Tests/Resources/UserApiResponses.Designer.cs @@ -19,7 +19,7 @@ namespace IF.Lastfm.Core.Tests.Resources { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] public class UserApiResponses { @@ -60,6 +60,36 @@ internal UserApiResponses() { } } + /// + /// Looks up a localized resource of type System.Byte[]. + /// + public static byte[] UserGetLovedTracksError { + get { + object obj = ResourceManager.GetObject("UserGetLovedTracksError", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + public static byte[] UserGetLovedTracksMultiple { + get { + object obj = ResourceManager.GetObject("UserGetLovedTracksMultiple", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + public static byte[] UserGetLovedTracksSingle { + get { + object obj = ResourceManager.GetObject("UserGetLovedTracksSingle", resourceCulture); + return ((byte[])(obj)); + } + } + /// /// Looks up a localized resource of type System.Byte[]. /// diff --git a/src/IF.Lastfm.Core.Tests/Resources/UserApiResponses.resx b/src/IF.Lastfm.Core.Tests/Resources/UserApiResponses.resx index f080b31..1a77684 100644 --- a/src/IF.Lastfm.Core.Tests/Resources/UserApiResponses.resx +++ b/src/IF.Lastfm.Core.Tests/Resources/UserApiResponses.resx @@ -118,6 +118,15 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + UserApi\UserGetLovedTracksError.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + UserApi\UserGetLovedTracksMultiple.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + UserApi\UserGetLovedTracksSingle.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + userapi\usergetrecenttracksempty.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 diff --git a/src/IF.Lastfm.Core/Api/Commands/User/GetLovedTracksCommand.cs b/src/IF.Lastfm.Core/Api/Commands/User/GetLovedTracksCommand.cs new file mode 100644 index 0000000..48012f3 --- /dev/null +++ b/src/IF.Lastfm.Core/Api/Commands/User/GetLovedTracksCommand.cs @@ -0,0 +1,52 @@ +using System; +using System.Net.Http; +using System.Threading.Tasks; +using IF.Lastfm.Core.Api.Enums; +using IF.Lastfm.Core.Api.Helpers; +using IF.Lastfm.Core.Objects; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace IF.Lastfm.Core.Api.Commands.User +{ + [ApiMethodName("user.getLovedTracks")] + internal class GetLovedTracksCommand : GetAsyncCommandBase> + { + public string Username { get; set; } + public GetLovedTracksCommand(ILastAuth auth, string username) : base(auth) + { + Username = username; + } + + public override void SetParameters() + { + Parameters.Add("user", Username); + + this.AddPagingParameters(); + this.DisableCaching(); + } + + public override async Task> HandleResponse(HttpResponseMessage response) + { + var json = await response.Content.ReadAsStringAsync(); + + LastResponseStatus status; + if (LastFm.IsResponseValid(json, out status) && response.IsSuccessStatusCode) + { + var jtoken = JsonConvert.DeserializeObject(json).SelectToken("lovedtracks"); + var itemsToken = jtoken.SelectToken("track"); + var attrToken = jtoken.SelectToken("@attr"); + + return PageResponse.CreateSuccessResponse( + itemsToken, + attrToken, + LastTrack.ParseJToken, + LastPageResultsType.Attr); + } + else + { + return LastResponse.CreateErrorResponse>(status); + } + } + } +} diff --git a/src/IF.Lastfm.Core/Api/IUserApi.cs b/src/IF.Lastfm.Core/Api/IUserApi.cs index 99468b7..d383a0f 100644 --- a/src/IF.Lastfm.Core/Api/IUserApi.cs +++ b/src/IF.Lastfm.Core/Api/IUserApi.cs @@ -37,5 +37,7 @@ Task> GetShoutsAsync(string username, Task> GetInfoAsync(string username); Task AddShoutAsync(string recipient, string message); + + Task> GetLovedTracks(string username, int pagenumber, int count); } } \ No newline at end of file diff --git a/src/IF.Lastfm.Core/Api/UserApi.cs b/src/IF.Lastfm.Core/Api/UserApi.cs index 2956d33..39e5390 100644 --- a/src/IF.Lastfm.Core/Api/UserApi.cs +++ b/src/IF.Lastfm.Core/Api/UserApi.cs @@ -118,5 +118,19 @@ public async Task AddShoutAsync(string recipient, string message) return await command.ExecuteAsync(); } + + public async Task> GetLovedTracks( + string username, + int pagenumber = 1, + int count = LastFm.DefaultPageLength) + { + var command = new GetLovedTracksCommand(auth: Auth, username: username) + { + Page = pagenumber, + Count = count, + HttpClient = HttpClient + }; + return await command.ExecuteAsync(); + } } } \ No newline at end of file