-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
80 lines (76 loc) · 2.29 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import Album from './album'
/**
* @author Rúben Gomes <[email protected]>
* @class Spotify
*
* @param {object} opts Specifies the options for spotify class
* @param {string} opts.token Specifies the spotify token to use
*/
export default class Spotify {
constructor({ token }) {
this.album = new Album({ token })
}
/**
* Gets albums info based on albums ids specified
*
* @param {object} opts Specifies the options object
* @param {string[]} opts.ids Specifies the spotify albums ids
* @returns {Promise<object[]>} The albums information
*
* @example Albums
* [{
* album_type: 'album',
* artists: [ [Object] ],
* available_markets: ['AD', 'EC', 'PT', ...],
* copyrights: [ [Object] ],
* external_ids: { upc: '886445352382' },
* external_urls: { spotify: 'https://open.spotify.com/album/{albumId}'}
* ...
* }]
*/
getAlbums({ ids }) {
return this.album.find({ ids: ids.join() })
}
/**
* Gets album info based on the id of the album
*
* @param {object} opts Specifies the options object
* @param {string} opts.id Specifies the spotify album id
* @returns {Promise<object>} The album information
* @example Album
* {
* album_type: 'album',
* artists: [ [Object] ],
* available_markets: ['AD', 'EC', 'PT', ...],
* copyrights: [ [Object] ],
* external_ids: { upc: '886445352382' },
* external_urls: { spotify: 'https://open.spotify.com/album/{albumId}'}
* ...
* }
*/
getAlbum({ id }) {
return this.album.findOne({ id })
}
/**
* Gets the tracks of the album info based on the id of the album
*
* @param {object} opts Specifies the options object
* @param {string} opts.id Specifies the spotify album id
* @param {number} [opts.skip=0] Specifies the offset of the items to retrieve
* @param {number} [opts.limit=20] Specifies the limit of items to retrieve
* @returns {Promise<object[]>} The album tracks information
*
* @example Tracks
* [{
* artists: [ [Object] ],
* available_markets: ['AD', 'EC', 'PT', ...],
* copyrights: [ [Object] ],
* disc_number: 1,
* track_number: 1
* ...
* }]
*/
getAlbumTracks({ id, skip = 0, limit = 20 }) {
return this.album.getTracks({ id, skip, limit })
}
}