Skip to content

Commit

Permalink
COmments and error handlin
Browse files Browse the repository at this point in the history
  • Loading branch information
Exerra committed Sep 24, 2021
1 parent e09021b commit b8a6e0c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.DS_STORE
node_modules
docs
.idea
.idea
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let auth
class MusicKit {
/**
*
* @param {Object} credentials Apple Music credentials. Consists of a key containing MusicKit priviledges, the team ID of developer account and the ID of the key
* @param {Object} credentials Apple Music credentials. Consists of a key containing MusicKit privileges, the team ID of developer account and the ID of the key
* @param {string} credentials.key A valid key generated from developer console that has MusicKit permissions
* @param {string} credentials.teamId ID of the team that credentials.key belongs to
* @param {string} credentials.keyId ID of the credentials.key
Expand Down
21 changes: 17 additions & 4 deletions src/personalized/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,20 @@ class MusicKit {
}

/**
*
* This updates the auth. Only used by the module
* @private
*/
updateAuth(paramToken, userTokenparam) {
auth = `Bearer ${paramToken}`
userToken = userTokenparam
}

/**
* Get the users library
* @param limit How much results to get
* @param offset How much to offset the results
* @returns {Promise<Object>}
*/
getLibrary(limit = 1, offset = 1) {
return new Promise((resolve, reject) => {
axios({
Expand All @@ -57,7 +63,7 @@ class MusicKit {
}

/**
*
* Create a playlist
* @param {Object} attributes The attributes for the playlist. See more [here](https://developer.apple.com/documentation/applemusicapi/libraryplaylistcreationrequest/attributes)
* @param {string} attributes.name The name of the playlist you want to make
* @param {string} attributes.description The description of the playlist you want to make
Expand Down Expand Up @@ -94,15 +100,22 @@ class MusicKit {

/**
* Add a song to a playlist
* @param {string} playlistId
* @param {{data: [{id: string}]}} songs
* @param {string} playlistId ID of the playlist to add the song to
* @param {{data: [{id: string}]}} songs The songs
*/
addSongToPlaylist(playlistId, songs) {

if (!playlistId || !songs) {
throw new Error("At least one required parameter is missing. Find out about how to use the createPlaylist function in https://musickit.js.org/#/catalog/functions/getFunctions?id=get-a-song")
return
}

// Adds the song type to all of the data
for (let i in songs.data) {
songs.data[i].type = "songs"
}

// Used for testing
console.log(songs)

return new Promise((resolve, reject) => {
Expand Down

0 comments on commit b8a6e0c

Please sign in to comment.