var $ = require('jquery');

const API_KEY = '3fe031d61d7cddb809ce4e5d748cfe8f';
const API_URL = 'http://ws.audioscrobbler.com/2.0/';

$.ajaxSetup({
    method: 'GET',
    url: API_URL,
    data: {
        'api_key': API_KEY,
        'format': 'json',
        'dataType': 'json'
    }
});

export function fetchFriends(user, callback) {
    $.ajax({
        data: {
            method: 'user.getFriends',
            user: user
        }
    }).success(function (data) {
        var friends = [];
        for (let friend of data.friends.user) {
            friends.push({
                username: friend.name,
                url: friend.url
            });
        }

        callback(friends);
    });
}

export function fetchArtist(artist, user, callback) {
    $.ajax({
        data: {
            method: 'artist.getInfo',
            artist: artist,
            username: user
        }
    }).success(function (data) {
        callback(data.artist.stats.userplaycount);
    });
}

export function fetchSong(artist, song, user, callback) {
    $.ajax({
        data: {
            method: 'track.getInfo',
            artist: artist,
            track: song,
            username: user
        }
    }).success(function (data) {
        callback(data.track.userplaycount);
    });
}

export function fetchAlbum(artist, album, user, callback) {
    $.ajax({
        data: {
            method: 'album.getInfo',
            artist: artist,
            album: album,
            username: user
        }
    }).success(function (data) {
        callback(data.album.userplaycount);
    });
}

@@ -932,24 +932,33 @@
    callback(
+parseInt(
 data.artist.
@@ -969,32 +969,33 @@
 s.userplaycount)
+)
 ;%0A    %7D);%0A%7D%0A%0Aexp
@@ -1251,24 +1251,33 @@
    callback(
+parseInt(
 data.track.u
@@ -1281,32 +1281,33 @@
 k.userplaycount)
+)
 ;%0A    %7D);%0A%7D%0A%0Aexp
@@ -1570,16 +1570,25 @@
 allback(
+parseInt(
 data.alb
@@ -1604,16 +1604,17 @@
 aycount)
+)
 ;%0A    %7D)

Convert play count to integer