diff --git a/.gitattributes b/.gitattributes index 6f5e950..67483f4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -188,4 +188,4 @@ Procfile text ## EXECUTABLES *.exe binary -*.pyc binary \ No newline at end of file +*.pyc binary diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 42f98c3..8ba468c 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl liberapay: scriptex issuehunt: scriptex otechie: # Replace with a single Otechie username -custom: ['paypal.me/scriptex'] +custom: ['paypal.me/scriptex', 'revolut.me/scriptex'] diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3222dfd..be20a40 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,28 +1,20 @@ -# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - name: Build -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] +on: [push, pull_request] jobs: - build: - - runs-on: ubuntu-latest + build: + runs-on: ubuntu-latest - strategy: - matrix: - node-version: [10.x, 12.x, 14.x] + strategy: + matrix: + node-version: [14.x, 16.x] - steps: - - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - - run: yarn - - run: yarn build + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - run: yarn + - run: yarn build diff --git a/.nowignore b/.nowignore deleted file mode 100644 index fe483ec..0000000 --- a/.nowignore +++ /dev/null @@ -1,22 +0,0 @@ -src - -_.config.yml -_config.yml -.editorconfig -.gitattrubutes -.gitignore -.npmignore -.prettierignore -.prettierrc -.travis.yml -.whitesource -package.json -renovate.json -webpack.config.js -yarn.lock - -*.appcache -*.sketch - -LICENSE -README.md diff --git a/.npmignore b/.npmignore index f86922e..c730ff1 100644 --- a/.npmignore +++ b/.npmignore @@ -6,7 +6,7 @@ yarn-debug.log* yarn-error.log* # Dependency directory -node_modules/ +node_modules # Misc .DS_Store @@ -17,35 +17,23 @@ node_modules/ ehthumbs.db Thumbs.db -# EditorConfig +# Config folders and files +.github +_config.yml +_.config.yml .editorconfig - -# Git .gitattributes .gitignore - -# CI -.travis.yml - -# lock files -yarn.lock - -# Prettier +.nvmrc .prettierignore .prettierrc - -# Config files -.github -_.config.yml -_config.yml -.babelrc -.nowignore -.nvmrc +.stylelintignore +.stylelintrc +.travis.yml .whitesource renovate.json -tslint.json tsconfig.json -postcss.config.js -webpack.config.js +tslint.json +yarn.lock -# Project specific +!dist diff --git a/.travis.yml b/.travis.yml index a2aa949..ea2b50c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: node_js sudo: false node_js: - - 'lts/*' + - 'lts/*' install: - - yarn + - yarn script: - - yarn build + - yarn build diff --git a/.whitesource b/.whitesource index 2344e4e..6c8c82e 100644 --- a/.whitesource +++ b/.whitesource @@ -8,4 +8,4 @@ "issueSettings": { "minSeverityLevel": "LOW" } -} \ No newline at end of file +} diff --git a/README.md b/README.md index c38b544..6848472 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,199 @@ -# TypeScript API for last.fm +[![Github Build](https://github.com/scriptex/lastfm-ts-api/workflows/Build/badge.svg)](https://github.com/scriptex/lastfm-ts-api/actions?query=workflow%3ABuild) +[![Codacy Badge](https://app.codacy.com/project/badge/Grade/34d3d75710534dc6a38c3584a1dcd068)](https://www.codacy.com/gh/scriptex/lastfm-ts-api/dashboard?utm_source=github.com&utm_medium=referral&utm_content=scriptex/lastfm-ts-api&utm_campaign=Badge_Grade) +[![Codebeat Badge](https://codebeat.co/badges/d765a4c8-2c0e-44f2-89c3-fa364fdc14e6)](https://codebeat.co/projects/github-com-scriptex-lastfm-ts-api-master) +[![CodeFactor Badge](https://www.codefactor.io/repository/github/scriptex/lastfm-ts-api/badge)](https://www.codefactor.io/repository/github/scriptex/lastfm-ts-api) +[![DeepScan grade](https://deepscan.io/api/teams/3574/projects/5257/branches/40799/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=3574&pid=5257&bid=40799) +[![Analytics](https://ga-beacon-361907.ew.r.appspot.com/UA-83446952-1/github.com/scriptex/lastfm-ts-api/README.md?pixel)](https://github.com/scriptex/lastfm-ts-api/) -> A Last.FM API written in TypeScript +# Last.FM TypeScript API Client -## Installation, usage, etc. +> A API client for the Last.FM API written in TypeScript -TODO +See the [Last.FM API](https://www.last.fm/api) for information about the Last.Fm API, including details on how to register an account and get your API key, shared secret, and session key. -## Support this project +## Visitor stats -[![Tweet](https://img.shields.io/badge/Tweet-Share_this_repository-blue.svg?style=flat-square&logo=twitter&color=38A1F3)](https://twitter.com/intent/tweet?text=Checkout%20this%20awesome%20software%20project%3A&url=https%3A%2F%2Fgithub.com%2Fscriptex%2Fatanas.info&via=scriptexbg&hashtags=software%2Cgithub%2Ccode%2Cawesome) -[![Donate on PayPal](https://img.shields.io/badge/Donate-Support_me_on_PayPal-blue.svg?style=flat-square&logo=paypal&color=222d65)](https://www.paypal.me/scriptex) -[![Become a Patron](https://img.shields.io/badge/Become_Patron-Support_me_on_Patreon-blue.svg?style=flat-square&logo=patreon&color=e64413)](https://www.patreon.com/atanas) -[![Buy Me A Coffee](https://img.shields.io/badge/Donate-Buy%20me%20a%20coffee-yellow.svg?logo=ko-fi)](https://ko-fi.com/scriptex) -[![Donate on Liberapay](https://img.shields.io/liberapay/receives/scriptex.svg?logo=liberapay)](https://liberapay.com/scriptex/) -[![Donate on Issuehunt](https://raw.githubusercontent.com/BoostIO/issuehunt-materials/master/v1/issuehunt-shield-v1.svg)](https://issuehunt.io/r/scriptex/atanas.info) +![GitHub stars](https://img.shields.io/github/stars/scriptex/lastfm-ts-api?style=social) +![GitHub forks](https://img.shields.io/github/forks/scriptex/lastfm-ts-api?style=social) +![GitHub watchers](https://img.shields.io/github/watchers/scriptex/lastfm-ts-api?style=social) +![GitHub followers](https://img.shields.io/github/followers/scriptex?style=social) + +## Code stats + +![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/scriptex/lastfm-ts-api) +![GitHub repo size](https://img.shields.io/github/repo-size/scriptex/lastfm-ts-api?style=plastic) +![GitHub language count](https://img.shields.io/github/languages/count/scriptex/lastfm-ts-api?style=plastic) +![GitHub top language](https://img.shields.io/github/languages/top/scriptex/lastfm-ts-api?style=plastic) +![GitHub last commit](https://img.shields.io/github/last-commit/scriptex/lastfm-ts-api?style=plastic) + +## Installation + +```sh +npm install lastfm-ts-api + +# or + +yarn add lastfm-ts-api +``` + +## Usage + +`lastfm-ts-api` exposes several classes which interact with different parts of the Last.FM API. These classes can be used to interact with the corresponding parts of the Last.FM API. First, you must instantiate these classes with arguments containing the details of your API account. `apiKey` is required, however since many endpoints of the API do not require authentication, `secret` and `sessionKey` are optional. + +```js +// To interact with the Album API: +import { LastFMAlbum } from 'lastfm-ts-api'; + +const album = new LastFMAlbum('API_KEY', 'SECRET', 'SESSION_KEY'); + +// To interact with the Artist API: +import { LastFMArtist } from 'lastfm-ts-api'; + +const artist = new LastFMArtist('API_KEY', 'SECRET', 'SESSION_KEY'); + +// To interact with the Auth API: +import { LastFMAuth } from 'lastfm-ts-api'; + +const auth = new LastFMAuth('API_KEY', 'SECRET', 'SESSION_KEY'); + +// To interact with the Chart API: +import { LastFMChart } from 'lastfm-ts-api'; + +const chart = new LastFMChart('API_KEY', 'SECRET', 'SESSION_KEY'); + +// To interact with the Geo API: +import { LastFMGeo } from 'lastfm-ts-api'; + +const geo = new LastFMGeo('API_KEY', 'SECRET', 'SESSION_KEY'); + +// To interact with the Library API: +import { LastFMLibrary } from 'lastfm-ts-api'; + +const library = new LastFMLibrary('API_KEY', 'SECRET', 'SESSION_KEY'); + +// To interact with the Tag API: +import { LastFMTag } from 'lastfm-ts-api'; + +const tag = new LastFMTag('API_KEY', 'SECRET', 'SESSION_KEY'); + +// To interact with the Track API: +import { LastFMTrack } from 'lastfm-ts-api'; + +const track = new LastFMTrack('API_KEY', 'SECRET', 'SESSION_KEY'); + +// To interact with the User API: +import { LastFMUser } from 'lastfm-ts-api'; + +const user = new LastFMUser('API_KEY', 'SECRET', 'SESSION_KEY'); +``` + +## Making Requests + +Each of the Last.FM classes contains methods which directly correspond to the Last.FM API methods. +For example, endpoint `User.getRecentTracks` is accessed as `user.getRecentTracks()` (after instantiating the class as described above). + +Parameters can be passed to the API through the `params` argument as an object that will be sent directly with the request, either as a query for a GET request, or a body for a POST request. The property names will not be transformed or abstracted, and so they must match the endpoint parameters exactly. This is where the TypeScript definitions play significant role - they get picked up by the IDE automatically so you don't need to worry about including/importing them. + +```js +user.getRecentTracks({ + user: 'USER' +}); +``` ## LICENSE MIT + +--- + +
+ Connect with me: +
+ +
+ +
+ + + +   + + + +   + + + +   + + + +   + + + +   + + + +   + + + +   + + + +   + + + +   + + + +   + + + +   + + + +
+ +--- + +
+Support and sponsor my work: +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/package.json b/package.json index b1f601f..c72b1f4 100644 --- a/package.json +++ b/package.json @@ -1,29 +1,34 @@ { "name": "lastfm-ts-api", "version": "1.0.0", - "description": "API client for Last.FM with full TypeScript support", - "scripts": { - "watch": "tsc -w", - "build": "tsc" - }, + "description": "An API client for the Last.FM API written in TypeScript", "keywords": [ - "Last.FM API", "Last.FM", - "API Client", - "TypeScript API" + "Last.FM API", + "Last.FM API Client", + "Last.FM TypeScript API" ], - "author": "Atanas Atanasov (https://atanas.info)", - "repository": "git@github.com:scriptex/last-fm-ts-api.git", + "homepage": "https://atanas.info/projects/lastfm-ts-api.html", "bugs": { "url": "https://github.com/scriptex/last-fm-ts-api/issues", - "email": "scriptex.bg@gmail.com" + "email": "hi@atanas.info" }, "license": "MIT", + "author": "Atanas Atanasov (https://atanas.info)", + "funding": "https://github.com/sponsors/scriptex", "main": "dist/index.js", - "typings": "dist/index.d.ts", + "types": "dist/index.d.ts", + "repository": { + "type": "git", + "url": "github:scriptex/lastfm-ts-api" + }, + "scripts": { + "watch": "tsc -w", + "build": "tsc" + }, "dependencies": {}, "devDependencies": { - "@types/node": "16.11.59", + "@types/node": "18.7.18", "tslib": "2.4.0", "typescript": "4.8.3" } diff --git a/src/album.ts b/src/album.ts new file mode 100644 index 0000000..9cac6e3 --- /dev/null +++ b/src/album.ts @@ -0,0 +1,131 @@ +import { LastFM } from './base'; +import { LastFMParam, LastFMApiRequest, LastFMRequestParams, LastFMUnknownFunction } from './api-request'; + +export interface LastFMAlbumParams { + readonly album: string; + readonly artist: string; +} + +export interface LastFMAlbumOptionalParams { + readonly mbid?: string; + readonly autocorrect?: 0 | 1; +} + +export interface LastFMAlbumAddTagsParams extends LastFMRequestParams, LastFMAlbumParams { + readonly tags: string | string[]; +} + +export interface LastFMAlbumGetInfoParams + extends LastFMRequestParams<0 | 1 | void>, + LastFMAlbumParams, + LastFMAlbumOptionalParams { + readonly lang?: string; + readonly username?: string; +} + +export interface LastFMAlbumGetTagsParams + extends LastFMRequestParams<0 | 1 | void>, + LastFMAlbumParams, + LastFMAlbumOptionalParams { + readonly user?: string; +} + +export interface LastFMAlbumGetTopTagsParams + extends LastFMRequestParams<0 | 1 | void>, + LastFMAlbumParams, + LastFMAlbumOptionalParams {} + +export interface LastFMAlbumRemoveLastFMTagParams extends LastFMRequestParams, LastFMAlbumParams { + readonly tag: string; +} + +export interface LastFMAlbumSearchParams extends LastFMRequestParams { + readonly page?: number; + readonly album: string; + readonly limit?: number; +} + +export class LastFMAlbum extends LastFM { + constructor(apiKey: string, secret?: string, sessionKey?: string) { + super(apiKey, secret, sessionKey); + } + + public addTags( + params: LastFMAlbumAddTagsParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'album.addTags', + sk: this.sessionKey + }) + .sign(this.secret) + .send('POST', callback); + } + + public getInfo( + params: LastFMAlbumGetInfoParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'album.getInfo' + }) + .send(callback); + } + + public getTags( + params: LastFMAlbumGetTagsParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'album.getTags' + }) + .send(callback); + } + + public getTopTags( + params: LastFMAlbumGetTopTagsParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'album.getTopTags' + }) + .send(callback); + } + + public removeTag( + params: LastFMAlbumRemoveLastFMTagParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'album.removeTag', + sk: this.sessionKey + }) + .sign(this.secret) + .send('POST', callback); + } + + public search(params: LastFMAlbumSearchParams, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'album.search' + }) + .send(callback); + } +} diff --git a/src/api-request.ts b/src/api-request.ts index b3bd69b..2040d9c 100644 --- a/src/api-request.ts +++ b/src/api-request.ts @@ -2,9 +2,10 @@ import { createHash } from 'crypto'; import { parse, stringify } from 'querystring'; import { request, RequestOptions } from 'https'; -export type UnknownFunction = (...args: unknown[]) => unknown; -export type Param = string | string[]; -export type Params = Record; +export type LastFMUnknownFunction = (...args: unknown[]) => unknown; +export type LastFMParam = string | string[]; +export type LastFMParams = Record; +export type LastFMRequestParams = Record; export class LastFMApiRequest { private params: Map = new Map(); @@ -13,7 +14,7 @@ export class LastFMApiRequest { this.params.set('format', 'json'); } - public set(params: Params): LastFMApiRequest { + public set(params: LastFMParams): LastFMApiRequest { Object.entries(params).forEach(([key, value]) => { if (typeof value !== 'undefined') { this.params.set(key, value); @@ -24,7 +25,7 @@ export class LastFMApiRequest { } public sign(secret?: string): LastFMApiRequest { - const paramsObj: Params = this.setParams(); + const paramsObj: LastFMParams = this.setParams(); const paramsObjParsed = parse(stringify(paramsObj)); const paramsStr = Array.from(Object.entries(paramsObjParsed)) @@ -58,7 +59,10 @@ export class LastFMApiRequest { return this; } - public send(method?: string | UnknownFunction, callback?: UnknownFunction): void | Promise { + public send( + method?: string | LastFMUnknownFunction, + callback?: LastFMUnknownFunction + ): void | Promise { callback = callback === undefined ? typeof method === 'function' @@ -73,7 +77,7 @@ export class LastFMApiRequest { this.params.delete('callback'); } - const paramsObj: Params = this.setParams(); + const paramsObj: LastFMParams = this.setParams(); const paramsStr = stringify(paramsObj); const options: RequestOptions = { @@ -136,8 +140,8 @@ export class LastFMApiRequest { return LastFMapiRequest; } - private setParams(): Params { - const result: Params = {}; + private setParams(): LastFMParams { + const result: LastFMParams = {}; this.params.forEach((value, key) => { if (typeof value !== 'undefined') { diff --git a/src/artist.ts b/src/artist.ts new file mode 100644 index 0000000..c37c9d2 --- /dev/null +++ b/src/artist.ts @@ -0,0 +1,202 @@ +import { LastFM } from './base'; +import { LastFMParam, LastFMApiRequest, LastFMRequestParams, LastFMUnknownFunction } from './api-request'; + +export interface LastFMArtistParams extends LastFMRequestParams { + readonly artist: string; +} + +export interface LastFMArtistAddTagsParams extends LastFMRequestParams, LastFMArtistParams { + readonly tags: string | string[]; +} + +export interface LastFMArtistGetInfoParams extends LastFMRequestParams<0 | 1 | void> { + readonly lang?: string; + readonly mbid?: string; + readonly artist: string; + readonly username?: string; + readonly autocorrect?: 0 | 1; +} + +export interface LastFMArtistGetSimilarParams extends LastFMRequestParams<0 | 1 | void | number> { + readonly mbid?: string; + readonly limit?: number; + readonly artist: string; + readonly autocorrect?: 0 | 1; +} + +export interface LastFMArtistGetTagsParams extends LastFMRequestParams<0 | 1 | void> { + readonly mbid?: string; + readonly user?: string; + readonly artist: string; + readonly autocorrect?: 0 | 1; +} + +export interface LastFMArtistGetTopAlbumsParams extends LastFMRequestParams<0 | 1 | void | number> { + readonly mbid?: string; + readonly page?: number; + readonly limit?: number; + readonly artist: string; + readonly autocorrect?: 0 | 1; +} + +export interface LastFMArtistGetTopTagsParams extends LastFMRequestParams<0 | 1 | void> { + readonly mbid?: string; + readonly artist: string; + readonly autocorrect?: 0 | 1; +} + +export interface LastFMArtistGetTopTracksParams extends LastFMRequestParams<0 | 1 | void | number> { + readonly mbid?: string; + readonly page?: number; + readonly limit?: number; + readonly artist: string; + readonly autocorrect?: 0 | 1; +} + +export interface LastFMArtistRemoveLastFMTagParams extends LastFMRequestParams { + readonly tag: string; + readonly artist: string; +} + +export interface LastFMArtistSearchParams extends LastFMRequestParams { + readonly page?: number; + readonly limit?: number; + readonly artist: string; +} + +export class LastFMArtist extends LastFM { + constructor(apiKey: string, secret?: string, sessionKey?: string) { + super(apiKey, secret, sessionKey); + } + + public addTags( + params: LastFMArtistAddTagsParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'artist.addTags', + sk: this.sessionKey + }) + .sign(this.secret) + .send('POST', callback); + } + + public getCorrection( + params: LastFMArtistParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'artist.getCorrection' + }) + .send(callback); + } + + public getInfo( + params: LastFMArtistGetInfoParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'artist.getInfo' + }) + .send(callback); + } + + public getSimilar( + params: LastFMArtistGetSimilarParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'artist.getSimilar' + }) + .send(callback); + } + + public getTags( + params: LastFMArtistGetTagsParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'artist.getTags' + }) + .send(callback); + } + + public getTopAlbums( + params: LastFMArtistGetTopAlbumsParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'artist.getTopAlbums' + }) + .send(callback); + } + + public getTopTags( + params: LastFMArtistGetTopTagsParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'artist.getTopTags' + }) + .send(callback); + } + + public getTopTracks( + params: LastFMArtistGetTopTracksParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'artist.getTopTracks' + }) + .send(callback); + } + + public removeTag( + params: LastFMArtistRemoveLastFMTagParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'artist.removeTag', + sk: this.sessionKey + }) + .sign(this.secret) + .send('POST', callback); + } + + public search(params: LastFMArtistSearchParams, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'artist.search' + }) + .send(callback); + } +} diff --git a/src/auth.ts b/src/auth.ts new file mode 100644 index 0000000..49e9998 --- /dev/null +++ b/src/auth.ts @@ -0,0 +1,55 @@ +import { LastFM } from './base'; +import { LastFMParam, LastFMApiRequest, LastFMRequestParams, LastFMUnknownFunction } from './api-request'; + +export interface LastFMAuthGetMobileSessionParams extends LastFMRequestParams { + readonly username: string; + readonly password: string; +} + +export interface LastFMAuthGetSessionParams extends LastFMRequestParams { + readonly token: string; +} + +export class LastFMAuth extends LastFM { + constructor(apiKey: string, secret?: string, sessionKey?: string) { + super(apiKey, secret, sessionKey); + } + + public getMobileSession( + params: LastFMAuthGetMobileSessionParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'auth.getMobileSession' + }) + .sign(this.secret) + .send('POST', callback); + } + + public getSession( + params: LastFMAuthGetSessionParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'auth.getSession' + }) + .sign(this.secret) + .send(callback); + } + + public getToken(callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set({ + api_key: this.apiKey, + method: 'auth.getToken' + }) + .sign(this.secret) + .send(callback); + } +} diff --git a/src/base.ts b/src/base.ts new file mode 100644 index 0000000..206d061 --- /dev/null +++ b/src/base.ts @@ -0,0 +1,29 @@ +export class LastFM { + public apiKey: string; + public secret?: string; + public sessionKey?: string; + + constructor(apiKey: string, secret?: string, sessionKey?: string) { + if (typeof apiKey !== 'string') { + throw new TypeError('apiKey must be of type string'); + } + + this.apiKey = apiKey; + + if (secret !== undefined) { + if (typeof secret !== 'string') { + throw new TypeError('secret must be of type string'); + } + + this.secret = secret; + } + + if (sessionKey !== undefined) { + if (typeof sessionKey !== 'string') { + throw new TypeError('sessionKey must be of type string'); + } + + this.sessionKey = sessionKey; + } + } +} diff --git a/src/chart.ts b/src/chart.ts new file mode 100644 index 0000000..1cd19e1 --- /dev/null +++ b/src/chart.ts @@ -0,0 +1,43 @@ +import { LastFM } from './base'; +import { LastFMApiRequest, LastFMRequestParams, LastFMUnknownFunction } from './api-request'; + +export interface LastFMChartParams extends LastFMRequestParams { + readonly page?: number; + readonly limit?: number; +} + +export class LastFMChart extends LastFM { + constructor(apiKey: string, secret?: string, sessionKey?: string) { + super(apiKey, secret, sessionKey); + } + + public getTopArtists(params: LastFMChartParams, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'chart.getTopArtists' + }) + .send(callback); + } + + public getTopTags(params: LastFMChartParams, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'chart.getTopTags' + }) + .send(callback); + } + + public getTopTracks(params: LastFMChartParams, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'chart.getTopTracks' + }) + .send(callback); + } +} diff --git a/src/geo.ts b/src/geo.ts new file mode 100644 index 0000000..2ae9ff0 --- /dev/null +++ b/src/geo.ts @@ -0,0 +1,44 @@ +import { LastFM } from './base'; +import { LastFMApiRequest, LastFMRequestParams, LastFMUnknownFunction } from './api-request'; + +export interface LastFMGeoGetTopArtistsParams extends LastFMRequestParams { + readonly page?: number; + readonly limit?: number; + readonly country: string; +} + +export interface LastFMGeoGetTopTracksParams extends LastFMGeoGetTopArtistsParams { + readonly location?: string; +} + +export class LastFMGeo extends LastFM { + constructor(apiKey: string, secret?: string, sessionKey?: string) { + super(apiKey, secret, sessionKey); + } + + public getTopArtists( + params: LastFMGeoGetTopArtistsParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'geo.getTopArtists' + }) + .send(callback); + } + + public getTopTracks( + params: LastFMGeoGetTopTracksParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'geo.getTopTracks' + }) + .send(callback); + } +} diff --git a/src/index.ts b/src/index.ts index 8da476b..d8a84c5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,1181 +1,11 @@ -import { Param, UnknownFunction, LastFMApiRequest } from './api-request'; - -export type RequestParams = Record; - -export class LastFM { - public apiKey: string; - public secret?: string; - public sessionKey?: string; - - constructor(apiKey: string, secret?: string, sessionKey?: string) { - if (typeof apiKey !== 'string') { - throw new TypeError('apiKey must be of type string'); - } - - this.apiKey = apiKey; - - if (secret !== undefined) { - if (typeof secret !== 'string') { - throw new TypeError('secret must be of type string'); - } - - this.secret = secret; - } - - if (sessionKey !== undefined) { - if (typeof sessionKey !== 'string') { - throw new TypeError('sessionKey must be of type string'); - } - - this.sessionKey = sessionKey; - } - } -} - -export interface AlbumAddTagsParams extends RequestParams { - readonly tags: string | string[]; - readonly album: string; - readonly artist: string; -} - -export interface AlbumGetInfoParams extends RequestParams<0 | 1 | void> { - readonly mbid?: string; - readonly lang: string; - readonly album: string; - readonly artist: string; - readonly username: string; - readonly autocorrect: 0 | 1; -} - -export interface AlbumGetTagsParams extends RequestParams<0 | 1 | void> { - readonly mbid?: string; - readonly user: string; - readonly album: string; - readonly artist: string; - readonly autocorrect: 0 | 1; -} - -export interface AlbumGetTopTagsParams extends RequestParams<0 | 1 | void> { - readonly mbid?: string; - readonly album: string; - readonly artist: string; - readonly autocorrect: 0 | 1; -} - -export interface AlbumRemoveTagParams extends RequestParams { - readonly tag: string; - readonly album: string; - readonly artist: string; -} - -export interface AlbumSearchParams extends RequestParams { - readonly page: number; - readonly album: string; - readonly limit: number; -} - -export class LastFMAlbum extends LastFM { - constructor(apiKey: string, secret?: string, sessionKey?: string) { - super(apiKey, secret, sessionKey); - } - - public addTags(params: AlbumAddTagsParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'album.addTags', - sk: this.sessionKey - }) - .sign(this.secret) - .send('POST', callback); - } - - public getInfo(params: AlbumGetInfoParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'album.getInfo' - }) - .send(callback); - } - - public getTags(params: AlbumGetTagsParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'album.getTags' - }) - .send(callback); - } - - public getTopTags(params: AlbumGetTopTagsParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'album.getTopTags' - }) - .send(callback); - } - - public removeTag(params: AlbumRemoveTagParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'album.removeTag', - sk: this.sessionKey - }) - .sign(this.secret) - .send('POST', callback); - } - - public search(params: AlbumSearchParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'album.search' - }) - .send(callback); - } -} - -export interface ArtistAddTagsParams extends RequestParams { - readonly tags: string | string[]; - readonly artist: string; -} - -export interface ArtistGetCorrectionParams extends RequestParams { - readonly artist: string; -} - -export interface ArtistGetInfoParams extends RequestParams<0 | 1 | void> { - readonly mbid?: string; - readonly lang: string; - readonly artist: string; - readonly autocorrect: 0 | 1; - readonly username: string; -} - -export interface ArtistGetSimilarParams extends RequestParams<0 | 1 | void | number> { - readonly mbid?: string; - readonly limit: number; - readonly artist: string; - readonly autocorrect: 0 | 1; -} - -export interface ArtistGetTagsParams extends RequestParams<0 | 1 | void> { - readonly user: string; - readonly mbid?: string; - readonly artist: string; - readonly autocorrect: 0 | 1; -} - -export interface ArtistGetTopAlbumsParams extends RequestParams<0 | 1 | void | number> { - readonly page: number; - readonly mbid?: string; - readonly limit: number; - readonly artist: string; - readonly autocorrect: 0 | 1; -} - -export interface ArtistGetTopTagsParams extends RequestParams<0 | 1 | void> { - readonly mbid?: string; - readonly artist: string; - readonly autocorrect: 0 | 1; -} - -export interface ArtistGetTopTracksParams extends RequestParams<0 | 1 | void | number> { - readonly page: number; - readonly mbid?: string; - readonly limit: number; - readonly artist: string; - readonly autocorrect: 0 | 1; -} - -export interface ArtistRemoveTagParams extends RequestParams { - readonly tag: string; - readonly artist: string; -} - -export interface ArtistSearchParams extends RequestParams { - readonly page: number; - readonly limit: number; - readonly artist: string; -} - -export class LastFMArtist extends LastFM { - constructor(apiKey: string, secret?: string, sessionKey?: string) { - super(apiKey, secret, sessionKey); - } - - public addTags(params: ArtistAddTagsParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'artist.addTags', - sk: this.sessionKey - }) - .sign(this.secret) - .send('POST', callback); - } - - public getCorrection( - params: ArtistGetCorrectionParams, - callback: UnknownFunction - ): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'artist.getCorrection' - }) - .send(callback); - } - - public getInfo(params: ArtistGetInfoParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'artist.getInfo' - }) - .send(callback); - } - - public getSimilar(params: ArtistGetSimilarParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'artist.getSimilar' - }) - .send(callback); - } - - public getTags(params: ArtistGetTagsParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'artist.getTags' - }) - .send(callback); - } - - public getTopAlbums(params: ArtistGetTopAlbumsParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'artist.getTopAlbums' - }) - .send(callback); - } - - public getTopTags(params: ArtistGetTopTagsParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'artist.getTopTags' - }) - .send(callback); - } - - public getTopTracks(params: ArtistGetTopTracksParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'artist.getTopTracks' - }) - .send(callback); - } - - public removeTag(params: ArtistRemoveTagParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'artist.removeTag', - sk: this.sessionKey - }) - .sign(this.secret) - .send('POST', callback); - } - - public search(params: ArtistSearchParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'artist.search' - }) - .send(callback); - } -} - -export interface AuthGetMobileSessionParams extends RequestParams { - readonly username: string; - readonly password: string; -} - -export interface AuthGetSessionParams extends RequestParams { - readonly token: string; -} - -export class LastFMAuth extends LastFM { - constructor(apiKey: string, secret?: string, sessionKey?: string) { - super(apiKey, secret, sessionKey); - } - - public getMobileSession( - params: AuthGetMobileSessionParams, - callback: UnknownFunction - ): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'auth.getMobileSession' - }) - .sign(this.secret) - .send('POST', callback); - } - - public getSession(params: AuthGetSessionParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'auth.getSession' - }) - .sign(this.secret) - .send(callback); - } - - public getToken(callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set({ - api_key: this.apiKey, - method: 'auth.getToken' - }) - .sign(this.secret) - .send(callback); - } -} - -export interface ChartGetTopArtistsParams extends RequestParams { - readonly page: number; - readonly limit: number; -} - -export interface ChartGetTopTagsParams extends RequestParams { - readonly page: number; - readonly limit: number; -} - -export interface ChartGetTopTracksParams extends RequestParams { - readonly page: number; - readonly limit: number; -} - -export class LastFMChart extends LastFM { - constructor(apiKey: string, secret?: string, sessionKey?: string) { - super(apiKey, secret, sessionKey); - } - - public getTopArtists( - params: ChartGetTopArtistsParams, - callback: UnknownFunction - ): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'chart.getTopArtists' - }) - .send(callback); - } - - public getTopTags(params: ChartGetTopTagsParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'chart.getTopTags' - }) - .send(callback); - } - - public getTopTracks(params: ChartGetTopTracksParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'chart.getTopTracks' - }) - .send(callback); - } -} - -export interface GeoGetTopArtistsParams extends RequestParams { - readonly page: number; - readonly limit: number; - readonly country: string; -} - -export interface GeoGetTopTracksParams extends RequestParams { - readonly page: number; - readonly limit: number; - readonly country: string; - readonly location: string; -} - -export class LastFMGeo extends LastFM { - constructor(apiKey: string, secret?: string, sessionKey?: string) { - super(apiKey, secret, sessionKey); - } - - public getTopArtists(params: GeoGetTopArtistsParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'geo.getTopArtists' - }) - .send(callback); - } - - public getTopTracks(params: GeoGetTopTracksParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'geo.getTopTracks' - }) - .send(callback); - } -} - -export interface LibraryGetArtists extends RequestParams { - readonly user: string; - readonly page: number; - readonly limit: number; -} - -export class LastFMLibrary extends LastFM { - constructor(apiKey: string, secret?: string, sessionKey?: string) { - super(apiKey, secret, sessionKey); - } - - public getArtists(params: LibraryGetArtists, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'library.getArtists' - }) - .send(callback); - } -} - -export interface TagGetInfoParams extends RequestParams { - readonly tag: string; - readonly lang: string; -} - -export class LastFMTag extends LastFM { - constructor(apiKey: string, secret?: string, sessionKey?: string) { - super(apiKey, secret, sessionKey); - } - - public getInfo(params: TagGetInfoParams, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'tag.getInfo' - }) - .send(callback); - } - - /** - * Get similar to a tag - * @param {Object} params - * @param {string} params.tag - Tag to get similar to - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - tagGetSimilar(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'tag.getSimilar' - }) - .send(callback); - } - - /** - * Get top albums of a tag - * @param {Object} params - * @param {string} params.tag - Tag to get top albums of - * @param {number} [params.limit] - Number of albums to get per page - * @param {number} [params.page] - Page number to get - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - tagGetTopAlbums(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'tag.getTopAlbums' - }) - .send(callback); - } - - /** - * Get top artists of a tag - * @param {Object} params - * @param {string} params.tag - Tag to get top artists of - * @param {number} [params.limit] - Number of artists to get per page - * @param {number} [params.page] - Page number to get - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - tagGetTopArtists(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'tag.getTopArtists' - }) - .send(callback); - } - - /** - * Get top tags - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - tagGetTopTags(callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set({ - api_key: this.apiKey, - method: 'tag.getTopTags' - }) - .send(callback); - } - - /** - * Get top tracks of a tag - * @param {Object} params - * @param {string} params.tag - Tag to get top tracks of - * @param {number} [params.limit] - Number of tracks to get per page - * @param {number} [params.page] - Page number to get - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - tagGetTopTracks(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'tag.getTopTracks' - }) - .send(callback); - } - - /** - * Get weekly charts of a tag - * @param {Object} params - * @param {string} params.tag - Tag to get weekly charts of - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - tagGetWeeklyChartList(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'tag.getWeeklyChartList' - }) - .send(callback); - } - - /** - * Add tags to a track - * @param {Object} params - * @param {string} params.artist - Artist whose track to add tags to - * @param {string} params.track - Track to add tags to - * @param {(string|string[])} params.tags - Tags to add to track - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - trackAddTags(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'track.addTags', - sk: this.sessionKey - }) - .sign(this.secret) - .send('POST', callback); - } - - /** - * Get correction of a track and artist - * @param {Object} params - * @param {string} params.artist - Artist and whose track to get correction of - * @param {string} params.track - Track to get correction of - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - trackGetCorrection(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'track.getCorrection' - }) - .send(callback); - } - - /** - * Get info of a track - * @param {Object} params - * @param {string} [params.artist] - Artist whose track to get info of. Required unless params.mbid is set. - * @param {string} [params.track] - Track to get info of. Required unless params.mbid is set. - * @param {string} [params.mbid] - MusicBrainz ID of track to get info of. Required unless params.artist and params.track are set. - * @param {(0|1)} [params.autocorrect] - Whether to correct misspelt artist and track names - * @param {string} [params.username] - User whose playcount and whether or not they have loved the track to include - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - trackGetInfo(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'track.getInfo' - }) - .send(callback); - } - - /** - * Get similar to a track - * @param {Object} params - * @param {string} [params.artist] - Artist whose track to get similar to. Required unless params.mbid is set. - * @param {string} [params.track] - Track to get similar to. Required unless params.mbid is set. - * @param {string} [params.mbid] - MusicBrainz ID of track to get similar to. Required unless params.artist and params.track are set. - * @param {(0|1)} [params.autocorrect] - Whether to correct misspelt artist and track names - * @param {number} [params.limit] - Number of tracks to get - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - trackGetSimilar(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'track.getSimilar' - }) - .send(callback); - } - - /** - * Get tags of a track added by a user - * @param {Object} params - * @param {string} [params.artist] - Artist whose track to get tags of. Required unless params.mbid is set. - * @param {string} [params.track] - Track to get tags of. Required unless params.mbid is set. - * @param {string} [params.mbid] - MusicBrainz ID of track to get tags of. Required unless params.artist and params.track are set. - * @param {string} params.user - User whose tags added to the track to get - * @param {(0|1)} [params.autocorrect] - Whether to correct misspelt artist and track names - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - trackGetTags(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'track.getTags' - }) - .send(callback); - } - - /** - * Get top tags of a track - * @param {Object} params - * @param {string} [params.artist] - Artist whose track to get top tags of. Required unless params.mbid is set. - * @param {string} [params.track] - Track to get top tags of. Required unless params.mbid is set. - * @param {string} [params.mbid] - MusicBrainz ID of track to get top tags of. Required unless params.artist and params.track are set. - * @param {(0|1)} [params.autocorrect] - Whether to correct misspelt artist and track names - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - trackGetTopTags(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'track.getTopTags' - }) - .send(callback); - } - - /** - * Love a track - * @param {Object} params - * @param {string} params.artist - Artist whose track to love - * @param {string} params.track - Track to love - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - trackLove(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'track.love', - sk: this.sessionKey - }) - .sign(this.secret) - .send('POST', callback); - } - - /** - * Remove tag from a track - * @param {Object} params - * @param {string} params.artist - Artist whose track to remove tag from - * @param {string} params.track - Track to remove tag from - * @param {string} params.tag - Tag to remove from track - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - trackRemoveTag(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'track.removeTag', - sk: this.sessionKey - }) - .sign(this.secret) - .send('POST', callback); - } - - /** - * Scrobble a track - * @param {Object} params - * @param {string} params.artist - Artist whose track to scrobble - * @param {string} params.track - Track to scobble - * @param {string} [params.album] - Album the track to scrobble is from - * @param {string} [params.albumArist] - Artist whose album the track to scrobble is from - * @param {number} params.timestamp - Timestamp to scrobble track at - * @param {number} [params.trackNumber] - Number of track to scrobble on the album - * @param {number} [params.duration] - Length of the track to scrobble in seconds - * @param {(0|1)} [params.chosenByUser] - Whether the user chose the track to scrobble - * @param {string} [params.streamId] - Stream ID if track to scrobble is from Last.Fm radio - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - trackScrobble(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'track.scrobble', - sk: this.sessionKey - }) - .sign(this.secret) - .send('POST', callback); - } - - /** - * Scrobble many tracks - * @param {Object[]} paramsArr - * @param {string} paramsArr[].artist - Artist whose track to scrobble - * @param {string} paramsArr[].track - Track to scobble - * @param {string} [paramsArr[].album] - Album the track to scrobble is from - * @param {string} [paramsArr[].albumArist] - Artist whose album the track to scrobble is from - * @param {number} paramsArr[].timestamp - Timestamp to scrobble track at - * @param {number} [paramsArr[].trackNumber] - Number of track to scrobble on the album - * @param {number} [paramsArr[].duration] - Length of the track to scrobble in seconds - * @param {(0|1)} [paramsArr[].chosenByUser] - Whether the user chose the track to scrobble - * @param {string} [paramsArr.streamId] - Stream ID if track to scrobble is from Last.Fm radio - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - trackScrobbleMany(paramsArr, callback: UnknownFunction): Promise | void { - const params = {}; - - paramsArr.forEach((paramsObj, i) => - Object.entries(paramsObj).forEach(([name, value]) => (params[`${name}[${i}]`] = value)) - ); - - return this.trackScrobble(params, callback); - } - - /** - * Search for a track - * @param {Object} params - * @param {string} [params.artist] - Artist whose track to search for - * @param {string} params.track - Track to search for - * @param {number} [params.limit] - Number of tracks to get per page - * @param {number} [params.page] - Page number to get - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - trackSearch(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'track.search' - }) - .send(callback); - } - - /** - * Unlove a track - * @param {Object} params - * @param {string} params.artist - Artist whose track to unlove - * @param {string} params.track - Track to unlove - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - trackUnlove(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'track.unlove', - sk: this.sessionKey - }) - .sign(this.secret) - .send('POST', callback); - } - - /** - * Update now playing - * @param {Object} params - * @param {string} params.artist - Artist whose track to update now playing with - * @param {string} params.track - Track to update now playing with - * @param {string} [params.album] - Album the track to update now playing with is from - * @param {string} [params.albumArist] - Artist whose album the track to update now playing with is from - * @param {number} [params.trackNumber] - Number of track to update now playing with on the album - * @param {number} [params.duration] - Length of the track to update now playing with in seconds - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - trackUpdateNowPlaying(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'track.updateNowPlaying', - sk: this.sessionKey - }) - .sign(this.secret) - .send('POST', callback); - } - - /** - * Get friends of a user - * @param {Object} params - * @param {string} params.user - User to get friends of - * @param {(0|1)} [params.recenttracks] - Whether to include recent tracks of friends - * @param {number} [params.limit] - Number of friends to get per page - * @param {number} [params.page] - Page number to get - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - userGetFriends(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'user.getFriends' - }) - .send(callback); - } - - /** - * Get info of a user - * @param {Object} [params] - * @param {string} [params.user] - User to get info of - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - userGetInfo(params, callback: UnknownFunction): Promise | void { - callback = callback === undefined ? (typeof params === 'function' ? params : undefined) : callback; - params = typeof params === 'object' ? params : {}; - - return new LastFMApiRequest().set(params).set({ - api_key: this.apiKey, - method: 'user.getInfo' - }); - - if (!params.user) { - LastFMApiRequest.set({ sk: this.sessionKey }).sign(this.secret); - } - - return LastFMApiRequest.send(params.user ? 'GET' : 'POST', callback) || this; - } - - /** - * Get loved tracks of a user - * @param {Object} params - * @param {string} params.user - User to get loved tracks of - * @param {number} [params.limit] - Number of tracks to get per page - * @param {number} [params.page] - Page number to get - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - userGetLovedTracks(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'user.getLovedTracks' - }) - .send(callback); - } - - /** - * Get items of a tag added by a user - * @param {Object} params - * @param {string} params.user - User whose added tag to get items of - * @param {string} params.tag - Tag to get items of - * @param {("artist"|"album"|"track")} params.taggingtype - Type of tag to get items of - * @param {number} [params.limit] - Number of items to get per page - * @param {number} [params.page] - Page number to get - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - userGetPersonalTags(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'user.getPersonalTags' - }) - .send(callback); - } - - /** - * Get recent tracks of a user - * @param {Object} params - * @param {string} params.user - User whose recent tracks to get - * @param {(0|1)} [params.extended] - Whether to include extended data of the artist and whether the user has loved the track or not - * @param {string} [params.from] - Timestamp to get tracks from - * @param {string} [params.to] - Timestamp to get tracks to - * @param {number} [params.limit] - Number of tracks to get per page - * @param {number} [params.page] - Page number to get - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - userGetRecentTracks(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'user.getRecentTracks' - }) - .send(callback); - } - - /** - * Get top albums of a user - * @param {Object} params - * @param {string} params.user - User to get top albums of - * @param {("7day"|"1month"|"3month"|"6month"|"12month"|"overall")} [params.period] - Time period to get top albums of - * @param {number} [params.limit] - Number of albums to get per page - * @param {number} [params.page] - Page number to get - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - userGetTopAlbums(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'user.getTopAlbums' - }) - .send(callback); - } - - /** - * Get top artists of a user - * @param {Object} params - * @param {string} params.user - User to get top artists of - * @param {("7day"|"1month"|"3month"|"6month"|"12month"|"overall")} [params.period] - Time period to get top artists of - * @param {number} [params.limit] - Number of artists to get per page - * @param {number} [params.page] - Page number to get - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - userGetTopArtists(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'user.getTopArtists' - }) - .send(callback); - } - - /** - * Get top tags of a user - * @param {Object} params - * @param {string} params.user - User to get top tags of - * @param {number} [params.limit] - Number of tags to get - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - userGetTopTags(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'user.getTopTags' - }) - .send(callback); - } - - /** - * Get top tracks of a user - * @param {Object} params - * @param {string} params.user - User to get top tracks of - * @param {("7day"|"1month"|"3month"|"6month"|"12month"|"overall")} [params.period] - Time period to get top tracks of - * @param {number} [params.limit] - Number of tracks to get per page - * @param {number} [params.page] - Page number to get - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - userGetTopTracks(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'user.getTopTracks' - }) - .send(callback); - } - - /** - * Get weekly album chart of a user - * @param {Object} params - * @param {string} params.user - User to get weekly album chart of - * @param {string} [params.from] - Timestamp to get weekly album chart from - * @param {string} [params.to] - Timestamp to get weekly album chart to - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - userGetWeeklyAlbumChart(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'user.getWeeklyAlbumChart' - }) - .send(callback); - } - - /** - * Get weekly artist chart of a user - * @param {Object} params - * @param {string} params.user - User to get weekly artist chart of - * @param {string} [params.from] - Timestamp to get weekly artist chart from - * @param {string} [params.to] - Timestamp to get weekly artist chart to - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - userGetWeeklyArtistChart(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'user.getWeeklyArtistChart' - }) - .send(callback); - } - - /** - * Get weekly charts of a user - * @param {Object} params - * @param {string} params.user - User to get weekly charts of - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - userGetWeeklyChartList(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'user.getWeeklyChartList' - }) - .send(callback); - } - - /** - * Get weekly track chart of a user - * @param {Object} params - * @param {string} params.user - User to get weekly track chart of - * @param {string} [params.from] - Timestamp to get weekly track chart from - * @param {string} [params.to] - Timestamp to get weekly track chart to - * @param {callback} [callback] - * @returns {(Promise|LastFm)} - */ - - userGetWeeklyTrackChart(params, callback: UnknownFunction): Promise | void { - return new LastFMApiRequest() - .set(params) - .set({ - api_key: this.apiKey, - method: 'user.getWeeklyTrackChart' - }) - .send(callback); - } -} +export * from './album'; +export * from './api-request'; +export * from './artist'; +export * from './auth'; +export * from './base'; +export * from './chart'; +export * from './geo'; +export * from './library'; +export * from './tag'; +export * from './track'; +export * from './user'; diff --git a/src/library.ts b/src/library.ts new file mode 100644 index 0000000..ba87603 --- /dev/null +++ b/src/library.ts @@ -0,0 +1,27 @@ +import { LastFM } from './base'; +import { LastFMApiRequest, LastFMRequestParams, LastFMUnknownFunction } from './api-request'; + +export interface LastFMLibraryGetArtists extends LastFMRequestParams { + readonly user: string; + readonly page?: number; + readonly limit?: number; +} + +export class LastFMLibrary extends LastFM { + constructor(apiKey: string, secret?: string, sessionKey?: string) { + super(apiKey, secret, sessionKey); + } + + public getArtists( + params: LastFMLibraryGetArtists, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'library.getArtists' + }) + .send(callback); + } +} diff --git a/src/tag.ts b/src/tag.ts new file mode 100644 index 0000000..55d179e --- /dev/null +++ b/src/tag.ts @@ -0,0 +1,95 @@ +import { LastFM } from './base'; +import { LastFMApiRequest, LastFMRequestParams, LastFMUnknownFunction } from './api-request'; + +export interface LastFMTagParams extends LastFMRequestParams { + readonly tag: string; +} + +export interface LastFMTagOptionalParams { + readonly page?: number; + readonly limit?: number; +} + +export interface LastFMTagGetInfoParams extends LastFMRequestParams, LastFMTagParams { + readonly lang?: string; +} + +export interface LastFMTagGetTop extends LastFMRequestParams, LastFMTagParams, LastFMTagOptionalParams {} + +export class LastFMTag extends LastFM { + constructor(apiKey: string, secret?: string, sessionKey?: string) { + super(apiKey, secret, sessionKey); + } + + public getInfo(params: LastFMTagGetInfoParams, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'tag.getInfo' + }) + .send(callback); + } + + public getSimilar(params: LastFMTagParams, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'tag.getSimilar' + }) + .send(callback); + } + + public getTopAlbums(params: LastFMTagGetTop, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'tag.getTopAlbums' + }) + .send(callback); + } + + public getTopArtists(params: LastFMTagGetTop, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'tag.getTopArtists' + }) + .send(callback); + } + + public getTopTags(callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set({ + api_key: this.apiKey, + method: 'tag.getTopTags' + }) + .send(callback); + } + + public getTopTracks(params: LastFMTagGetTop, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'tag.getTopTracks' + }) + .send(callback); + } + + public getWeeklyChartList( + params: LastFMTagParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'tag.getWeeklyChartList' + }) + .send(callback); + } +} diff --git a/src/track.ts b/src/track.ts new file mode 100644 index 0000000..e847d12 --- /dev/null +++ b/src/track.ts @@ -0,0 +1,225 @@ +import { LastFM } from './base'; +import { LastFMApiRequest, LastFMRequestParams, LastFMUnknownFunction } from './api-request'; + +export interface LastFMTrackParams extends LastFMRequestParams { + readonly track: string; + readonly artist: string; +} + +export interface LastFMTrackOptionalParams { + readonly mbid?: string; + readonly autocorrect?: 0 | 1; +} + +export interface LastFMTrackAddTags extends LastFMTrackParams { + readonly tags: string | string[]; +} + +export interface LastFMTrackGetInfo extends LastFMTrackParams, LastFMTrackOptionalParams { + readonly username?: string; +} + +export interface LastFMTrackGetSimilar extends LastFMTrackParams, LastFMTrackOptionalParams { + readonly limit?: number; +} + +export interface LastFMTrackGetTags extends LastFMTrackParams, LastFMTrackOptionalParams { + readonly user?: string; +} + +export interface LastFMTrackGetTopTags extends LastFMTrackParams, LastFMTrackOptionalParams {} + +export interface LastFMTrackRemoveTag extends LastFMTrackParams { + readonly tag: string; +} + +export interface LastFMTrackScrobble extends LastFMTrackParams { + readonly timestamp?: number; + readonly mbid?: string; + readonly album?: string; + readonly context?: string; + readonly streamId?: string; + readonly duration?: number; + readonly chosenByUser?: 0 | 1; + readonly trackNumber?: number; + readonly albumArtist?: string; +} + +export interface LastFMTrackSearch extends LastFMRequestParams { + readonly page?: number; + readonly limit?: number; + readonly track: string; + readonly artist?: string; +} + +export interface LastFMTrackUpdateNowPlaying extends LastFMTrackParams { + readonly mbid?: string; + readonly album?: string; + readonly context?: string; + readonly duration?: number; + readonly trackNumber?: number; + readonly albumArtist?: string; +} + +export class LastFMTrack extends LastFM { + constructor(apiKey: string, secret?: string, sessionKey?: string) { + super(apiKey, secret, sessionKey); + } + + public addTags(params: LastFMTrackAddTags, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'track.addTags', + sk: this.sessionKey + }) + .sign(this.secret) + .send('POST', callback); + } + + public getCorrection(params: LastFMTrackParams, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'track.getCorrection' + }) + .send(callback); + } + + public getInfo(params: LastFMTrackGetInfo, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'track.getInfo' + }) + .send(callback); + } + + public getSimilar( + params: LastFMTrackGetSimilar, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'track.getSimilar' + }) + .send(callback); + } + + public getTags(params: LastFMTrackGetTags, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'track.getTags' + }) + .send(callback); + } + + public getTopTags( + params: LastFMTrackGetTopTags, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'track.getTopTags' + }) + .send(callback); + } + + public love(params: LastFMTrackParams, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'track.love', + sk: this.sessionKey + }) + .sign(this.secret) + .send('POST', callback); + } + + public removeTag(params: LastFMTrackRemoveTag, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'track.removeTag', + sk: this.sessionKey + }) + .sign(this.secret) + .send('POST', callback); + } + + public scrobble(params: LastFMTrackScrobble, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'track.scrobble', + sk: this.sessionKey + }) + .sign(this.secret) + .send('POST', callback); + } + + public scrobbleMany( + paramsArr: LastFMTrackScrobble[], + callback: LastFMUnknownFunction + ): Promise | void { + const params: any = {}; + + paramsArr.forEach((paramsObj: LastFMTrackScrobble, i: number) => + Object.entries(paramsObj).forEach( + ([name, value]: [name: string, value: string | string[] | number | void]) => + (params[`${name}[${i}]`] = value) + ) + ); + + return this.scrobble(params, callback); + } + + public search(params: LastFMTrackSearch, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'track.search' + }) + .send(callback); + } + + public unlove(params: LastFMTrackParams, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'track.unlove', + sk: this.sessionKey + }) + .sign(this.secret) + .send('POST', callback); + } + + public updateNowPlaying( + params: LastFMTrackUpdateNowPlaying, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'track.updateNowPlaying', + sk: this.sessionKey + }) + .sign(this.secret) + .send('POST', callback); + } +} diff --git a/src/user.ts b/src/user.ts new file mode 100644 index 0000000..e069a8a --- /dev/null +++ b/src/user.ts @@ -0,0 +1,200 @@ +import { LastFM } from './base'; +import { LastFMParam, LastFMApiRequest, LastFMRequestParams, LastFMUnknownFunction } from './api-request'; + +export interface LastFMUserParams extends LastFMRequestParams { + readonly user: string; +} + +export interface LastFMUserOptionalParams { + readonly page?: number; + readonly limit?: number; +} + +export interface LastFMUserGetFriends extends LastFMUserParams, LastFMUserOptionalParams { + readonly recenttracks?: boolean; +} + +export interface LastFMUserGetLovedTracks extends LastFMUserParams, LastFMUserOptionalParams {} + +export interface LastFMUserGetPersonalTags extends LastFMUserParams, LastFMUserOptionalParams { + readonly tag?: string; + readonly taggingtype: 'artist' | 'album' | 'track'; +} + +export interface LastFMUserGetRecentTracks extends LastFMUserParams, LastFMUserOptionalParams { + readonly to?: string; + readonly from?: string; + readonly extended: 0 | 1; +} + +export interface LastFMUserGetTop extends LastFMUserParams, LastFMUserOptionalParams { + readonly period?: 'overall' | '7day' | '1month' | '3month' | '6month' | '12month'; +} + +export interface LastFMUserGetTopTags extends LastFMRequestParams { + readonly user: string; + readonly limit?: number; +} + +export interface LastFMUserGetWeekly extends LastFMRequestParams { + readonly to?: string; + readonly user: string; + readonly from?: string; +} + +export class LastFMUser extends LastFM { + constructor(apiKey: string, secret?: string, sessionKey?: string) { + super(apiKey, secret, sessionKey); + } + + public getFriends(params: LastFMUserGetFriends, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'user.getFriends' + }) + .send(callback); + } + + public getInfo(params: LastFMUserParams, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'user.getInfo' + }) + .send(callback); + } + + public getLovedTracks( + params: LastFMUserGetLovedTracks, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'user.getLovedTracks' + }) + .send(callback); + } + + public getPersonalTags( + params: LastFMUserGetPersonalTags, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'user.getPersonalTags' + }) + .send(callback); + } + + public getRecentTracks( + params: LastFMUserGetRecentTracks, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'user.getRecentTracks' + }) + .send(callback); + } + + public getTopAlbums(params: LastFMUserGetTop, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'user.getTopAlbums' + }) + .send(callback); + } + + public getTopArtists(params: LastFMUserGetTop, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'user.getTopArtists' + }) + .send(callback); + } + + public getTopTags(params: LastFMUserGetTopTags, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'user.getTopTags' + }) + .send(callback); + } + + public getTopTracks(params: LastFMUserGetTop, callback: LastFMUnknownFunction): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'user.getTopTracks' + }) + .send(callback); + } + + public getWeeklyAlbumChart( + params: LastFMUserGetWeekly, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'user.getWeeklyAlbumChart' + }) + .send(callback); + } + + public getWeeklyArtistChart( + params: LastFMUserGetWeekly, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'user.getWeeklyArtistChart' + }) + .send(callback); + } + + public getWeeklyChartList( + params: LastFMUserParams, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'user.getWeeklyChartList' + }) + .send(callback); + } + + public getWeeklyTrackChart( + params: LastFMUserGetWeekly, + callback: LastFMUnknownFunction + ): Promise | void { + return new LastFMApiRequest() + .set(params) + .set({ + api_key: this.apiKey, + method: 'user.getWeeklyTrackChart' + }) + .send(callback); + } +} diff --git a/tsconfig.json b/tsconfig.json index d2ae35c..d5a6513 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,37 +1,39 @@ { - "compileOnSave": false, "compilerOptions": { "allowJs": false, "allowSyntheticDefaultImports": true, "alwaysStrict": true, + "baseUrl": "./", "checkJs": false, "declaration": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "forceConsistentCasingInFileNames": true, "importHelpers": false, - "noEmitHelpers": false, - "lib": ["ES5", "ESNext"], - "outDir": "dist", - "module": "umd", - "moduleResolution": "node", + "isolatedModules": true, + "jsx": "react", + "lib": ["DOM", "ESNext"], + "module": "ESNext", + "moduleResolution": "Node", "noEmit": false, + "noEmitHelpers": false, "noEmitOnError": true, "noFallthroughCasesInSwitch": true, "noImplicitAny": true, "noImplicitReturns": true, "noImplicitThis": true, "noStrictGenericChecks": false, + "outDir": "./dist", + "pretty": true, + "removeComments": false, + "sourceMap": true, "strict": true, "strictBindCallApply": true, "strictFunctionTypes": true, "strictPropertyInitialization": true, "strictNullChecks": true, - "pretty": true, - "removeComments": false, - "sourceMap": true, - "target": "es5" + "target": "ESNext" }, - "exclude": ["node_modules"], - "include": ["src/*.ts"] + "include": ["src/*.ts"], + "exclude": ["node_modules"] } diff --git a/yarn.lock b/yarn.lock index 9e13c59..8b936f2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -"@types/node@16.11.59": - version "16.11.59" - resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.59.tgz#823f238b9063ccc3b3b7f13186f143a57926c4f6" - integrity sha512-6u+36Dj3aDzhfBVUf/mfmc92OEdzQ2kx2jcXGdigfl70E/neV21ZHE6UCz4MDzTRcVqGAM27fk+DLXvyDsn3Jw== +"@types/node@18.7.18": + version "18.7.18" + resolved "https://registry.yarnpkg.com/@types/node/-/node-18.7.18.tgz#633184f55c322e4fb08612307c274ee6d5ed3154" + integrity sha512-m+6nTEOadJZuTPkKR/SYK3A2d7FZrgElol9UP1Kae90VVU4a6mxnPuLiIW1m4Cq4gZ/nWb9GrdVXJCoCazDAbg== tslib@2.4.0: version "2.4.0"