@imikailoby/lastfm-ts
Version:
A minimalistic TypeScript-based client for Last.fm API 2.0
2 lines (1 loc) • 5.3 kB
JavaScript
class t{constructor(){this.baseUrl='https://ws.audioscrobbler.com/2.0'}async get(t){const e=function(t){return new URLSearchParams({...t,format:'json'})}(t),i=await fetch(`${this.baseUrl}/?${e}`,{method:'GET'}),a=await i.json();if(!i.ok)throw a;return a}}class e{constructor(e){this.apiClient=new t,this.apiKey=e}}class i extends e{getFriends(t){return this.apiClient.get({method:'user.getFriends',api_key:this.apiKey,...t})}getInfo(t){return this.apiClient.get({method:'user.getInfo',api_key:this.apiKey,...t})}getLovedTracks(t){return this.apiClient.get({method:'user.getLovedTracks',api_key:this.apiKey,...t})}getPersonalTags(t){return this.apiClient.get({method:'user.getPersonalTags',api_key:this.apiKey,...t})}getRecentTracks(t){return this.apiClient.get({method:'user.getRecentTracks',api_key:this.apiKey,...t})}getTopAlbums(t){return this.apiClient.get({method:'user.getTopAlbums',api_key:this.apiKey,...t})}getTopArtists(t){return this.apiClient.get({method:'user.getTopArtists',api_key:this.apiKey,...t})}getTopTags(t){return this.apiClient.get({method:'user.getTopTags',api_key:this.apiKey,...t})}getTopTracks(t){return this.apiClient.get({method:'user.getTopTracks',api_key:this.apiKey,...t})}getWeeklyAlbumChart(t){return this.apiClient.get({method:'user.getWeeklyAlbumChart',api_key:this.apiKey,...t})}getWeeklyArtistChart(t){return this.apiClient.get({method:'user.getWeeklyArtistChart',api_key:this.apiKey,...t})}getWeeklyTrackChart(t){return this.apiClient.get({method:'user.getWeeklyTrackChart',api_key:this.apiKey,...t})}}class a extends e{getArtists(t){return this.apiClient.get({method:'library.getArtists',api_key:this.apiKey,...t})}}class s extends e{getTopArtists(t){return this.apiClient.get({method:'geo.getTopArtists',api_key:this.apiKey,...t})}getTopTracks(t){return this.apiClient.get({method:'geo.getTopTracks',api_key:this.apiKey,...t})}}class r extends e{getTopArtists(t){return this.apiClient.get({method:'chart.getTopArtists',api_key:this.apiKey,...t})}getTopTags(t){return this.apiClient.get({method:'chart.getTopTags',api_key:this.apiKey,...t})}getTopTracks(t){return this.apiClient.get({method:'chart.getTopTracks',api_key:this.apiKey,...t})}}class p extends e{getInfo(t){return this.apiClient.get({method:'tag.getInfo',api_key:this.apiKey,...t})}getTopAlbums(t){return this.apiClient.get({method:'tag.getTopAlbums',api_key:this.apiKey,...t})}getTopArtists(t){return this.apiClient.get({method:'tag.getTopArtists',api_key:this.apiKey,...t})}getTopTags(){return this.apiClient.get({method:'tag.getTopTags',api_key:this.apiKey})}getTopTracks(t){return this.apiClient.get({method:'tag.getTopTracks',api_key:this.apiKey,...t})}}class h extends e{getInfo(t){return this.apiClient.get({method:'album.getInfo',api_key:this.apiKey,...t})}getTags(t){return this.apiClient.get({method:'album.getTags',api_key:this.apiKey,...t})}getTopTags(t){return this.apiClient.get({method:'album.getTopTags',api_key:this.apiKey,...t})}search(t){return this.apiClient.get({method:'album.search',api_key:this.apiKey,...t})}}class g extends e{getCorrection(t){return this.apiClient.get({method:'artist.getCorrection',api_key:this.apiKey,...t})}getInfo(t){return this.apiClient.get({method:'artist.getInfo',api_key:this.apiKey,...t})}getSimilar(t){return this.apiClient.get({method:'artist.getSimilar',api_key:this.apiKey,...t})}getTags(t){return this.apiClient.get({method:'artist.getTags',api_key:this.apiKey,...t})}getTopAlbums(t){return this.apiClient.get({method:'artist.getTopAlbums',api_key:this.apiKey,...t})}getTopTags(t){return this.apiClient.get({method:'artist.getTopTags',api_key:this.apiKey,...t})}getTopTracks(t){return this.apiClient.get({method:'artist.getTopTracks',api_key:this.apiKey,...t})}search(t){return this.apiClient.get({method:'artist.search',api_key:this.apiKey,...t})}}class n extends e{getCorrection(t){return this.apiClient.get({method:'track.getCorrection',api_key:this.apiKey,...t})}getInfo(t){return this.apiClient.get({method:'track.getInfo',api_key:this.apiKey,...t})}getSimilar(t){return this.apiClient.get({method:'track.getSimilar',api_key:this.apiKey,...t})}getTags(t){return this.apiClient.get({method:'track.getTags',api_key:this.apiKey,...t})}getTopTags(t){return this.apiClient.get({method:'track.getTopTags',api_key:this.apiKey,...t})}search(t){return this.apiClient.get({method:'track.search',api_key:this.apiKey,...t})}}var o;exports.ApiError=void 0,(o=exports.ApiError||(exports.ApiError={}))[o.INVALID_SERVICE=2]='INVALID_SERVICE',o[o.INVALID_METHOD=3]='INVALID_METHOD',o[o.AUTHENTICATION_FAILED=4]='AUTHENTICATION_FAILED',o[o.INVALID_FORMAT=5]='INVALID_FORMAT',o[o.INVALID_PARAMETERS=6]='INVALID_PARAMETERS',o[o.INVALID_RESOURCE=7]='INVALID_RESOURCE',o[o.OPERATION_FAILED=8]='OPERATION_FAILED',o[o.INVALID_SESSION_KEY=9]='INVALID_SESSION_KEY',o[o.INVALID_API_KEY=10]='INVALID_API_KEY',o[o.SERVICE_OFFLINE=11]='SERVICE_OFFLINE',o[o.INVALID_METHOD_SIGNATURE_SUPPLIED=13]='INVALID_METHOD_SIGNATURE_SUPPLIED',o[o.TEMPORARY_ERROR=16]='TEMPORARY_ERROR',o[o.SUSPENDED_API_KEY=26]='SUSPENDED_API_KEY',o[o.RATE_LIMIT_EXCEEDED=29]='RATE_LIMIT_EXCEEDED',exports.LastFm=class{constructor(t){this.user=new i(t),this.library=new a(t),this.geo=new s(t),this.chart=new r(t),this.tag=new p(t),this.album=new h(t),this.artist=new g(t),this.track=new n(t)}};