<commit_before>﻿using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using IF.Lastfm.Core.Api.Commands.TrackApi;
using IF.Lastfm.Core.Api.Enums;
using IF.Lastfm.Core.Api.Helpers;
using IF.Lastfm.Core.Objects;

namespace IF.Lastfm.Core.Api
{
    public class TrackApi : ITrackApi
    {
        public ILastAuth Auth { get; private set; }

        public TrackApi(ILastAuth auth)
        {
            Auth = auth;
        }

        public async Task<LastResponse> ScrobbleAsync(Scrobble scrobble)
        {
            const string apiMethod = "track.scrobble";

            if (Auth.UserSession == null) 
                return LastResponse.CreateErrorResponse<LastResponse>(LastFmApiError.BadAuth);

            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,<commit_msg>Fix scrobble bug<commit_after>﻿using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using IF.Lastfm.Core.Api.Commands.TrackApi;
using IF.Lastfm.Core.Api.Enums;
using IF.Lastfm.Core.Api.Helpers;
using IF.Lastfm.Core.Objects;

namespace IF.Lastfm.Core.Api
{
    public class TrackApi : ITrackApi
    {
        public ILastAuth Auth { get; private set; }

        public TrackApi(ILastAuth auth)
        {
            Auth = auth;
        }

        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()}
            };

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

            var postContent = LastFm.CreatePostBody(apiMethod,
{'fraction_non_alphanumeric': 0.10670731707317073, 'fraction_numerical': 0.001524390243902439, 'mean_word_length': 2.3567774936061383, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4421313', 'n_tokens_mistral': 767, 'n_tokens_neox': 741, 'n_words': 140}