Пример #1
0
        public Task <LastResponse> UpdateNowPlayingAsync(Scrobble scrobble)
        {
            var command = new UpdateNowPlayingCommand(Auth, scrobble)
            {
                HttpClient = HttpClient
            };

            return(command.ExecuteAsync());
        }
Пример #2
0
        public Task <ScrobbleResponse> ScrobbleAsync(Scrobble scrobble)
        {
            var command = new ScrobbleCommand(Auth, scrobble)
            {
                HttpClient = HttpClient
            };

            return(command.ExecuteAsync());
        }
Пример #3
0
        public async Task <LastResponse> ScrobbleAsync(Scrobble scrobble)
        {
            const string apiMethod = "track.scrobble";

            var methodParameters = new Dictionary <string, string>
            {
                { "artist", scrobble.Artist },
                { "album", scrobble.Album },
                { "track", scrobble.Track },
                { "albumArtist", scrobble.AlbumArtist },
                { "chosenByUser", Convert.ToInt32(scrobble.ChosenByUser).ToString() },
                { "timestamp", scrobble.TimePlayed.ToUnixTimestamp().ToString() },
                { "sk", Auth.UserSession.Token }
            };

            var apisig = Auth.GenerateMethodSignature(apiMethod, methodParameters);

            var postContent = LastFm.CreatePostBody(apiMethod,
                                                    Auth.ApiKey,
                                                    apisig,
                                                    methodParameters);

            var httpClient = new HttpClient();
            HttpResponseMessage response = await httpClient.PostAsync(LastFm.ApiRoot, postContent);

            string json = await response.Content.ReadAsStringAsync();

            LastFmApiError error;

            if (LastFm.IsResponseValid(json, out error) && response.IsSuccessStatusCode)
            {
                return(LastResponse.CreateSuccessResponse());
            }
            else
            {
                return(LastResponse.CreateErrorResponse <LastResponse>(error));
            }
        }
Пример #4
0
        public Task <LastResponse> UpdateNowPlayingAsync(Scrobble scrobble)
        {
            var command = new TrackUpdateNowPlayingCommand(Auth, scrobble);

            return(command.ExecuteAsync());
        }
Пример #5
0
        public Task <LastResponse> ScrobbleAsync(Scrobble scrobble)
        {
            var command = new TrackScrobbleCommand(Auth, scrobble);

            return(command.ExecuteAsync());
        }