-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from calluswhatyouwant/v0.4.x
Upgrade to v0.4.0
- Loading branch information
Showing
19 changed files
with
388 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import _ from 'lodash'; | ||
|
||
import { getAxiosSpotifyInstance } from './driver'; | ||
import { | ||
Category, | ||
PlaylistSimplified, | ||
Page, | ||
AlbumSimplified, | ||
Recommendations, | ||
} from './models'; | ||
import { propertiesToSnakeCase } from './util'; | ||
|
||
export const getCategory = async ( | ||
id: string, | ||
params?: { | ||
country?: string; | ||
locale?: string; | ||
} | ||
) => { | ||
const response = await getAxiosSpotifyInstance().get( | ||
`/browse/categories/${id}`, | ||
{ params } | ||
); | ||
return new Category(response.data); | ||
}; | ||
|
||
export const getCategoryPlaylists = async ( | ||
id: string, | ||
params?: { | ||
country?: string; | ||
limit?: number; | ||
offset?: number; | ||
} | ||
) => { | ||
const response = await getAxiosSpotifyInstance().get( | ||
`/browse/categories/${id}/playlists`, | ||
{ params } | ||
); | ||
return new Page<PlaylistSimplified>( | ||
response.data, | ||
PlaylistSimplified, | ||
'playlists' | ||
); | ||
}; | ||
|
||
export const getCategories = async (params?: { | ||
country?: string; | ||
locale?: string; | ||
limit?: number; | ||
offset?: number; | ||
}) => { | ||
const response = await getAxiosSpotifyInstance().get('/browse/categories', { | ||
params, | ||
}); | ||
return new Page<Category>(response.data, Category, 'categories'); | ||
}; | ||
|
||
export const getFeaturedPlaylists = async (params?: { | ||
country?: string; | ||
locale?: string; | ||
timestamp?: string; | ||
limit?: number; | ||
offset?: number; | ||
}) => { | ||
const response = await getAxiosSpotifyInstance().get( | ||
'/browse/featured-playlists', | ||
{ params } | ||
); | ||
return new Page<PlaylistSimplified>( | ||
response.data, | ||
PlaylistSimplified, | ||
'playlists' | ||
); | ||
}; | ||
|
||
export const getNewReleases = async (params?: { | ||
country?: string; | ||
limit?: number; | ||
offset?: number; | ||
}) => { | ||
const response = await getAxiosSpotifyInstance().get( | ||
'/browse/new-releases', | ||
{ params } | ||
); | ||
return new Page<AlbumSimplified>(response.data, AlbumSimplified, 'albums'); | ||
}; | ||
|
||
export const getRecommendations = async (params?: { | ||
limit?: number; | ||
market?: string; | ||
seedArtists?: string[]; | ||
seedGenres?: string[]; | ||
seedTracks?: string[]; | ||
[rest: string]: any; | ||
}) => { | ||
const updatedParams = propertiesToSnakeCase(params); | ||
const response = await getAxiosSpotifyInstance().get('/recommendations', { | ||
params: updatedParams, | ||
}); | ||
return new Recommendations(response.data); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
export * from './albums'; | ||
export * from './artists'; | ||
export * from './browse'; | ||
export * from './driver'; | ||
export * from './follow'; | ||
export * from './library'; | ||
export * from './personalization'; | ||
export * from './playlists'; | ||
export * from './player'; | ||
export * from './search'; | ||
export * from './tracks'; | ||
export * from './users-profile'; | ||
export * from './models'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { getAxiosSpotifyInstance } from './driver'; | ||
import { Page, SavedAlbum, SavedTrack } from './models'; | ||
|
||
export const areSavedToCurrentUserLibrary = async ( | ||
ids: string[], | ||
type: 'tracks' | 'albums' | ||
) => { | ||
const params = { ids: ids.join() }; | ||
const response = await getAxiosSpotifyInstance().get( | ||
`/me/${type}/contains`, | ||
{ params } | ||
); | ||
return response.data; | ||
}; | ||
|
||
export const getCurrentUserSavedAlbums = async (params?: { | ||
limit?: number; | ||
offset?: number; | ||
market?: string; | ||
}) => { | ||
const response = await getAxiosSpotifyInstance().get('/me/albums', { | ||
params, | ||
}); | ||
return new Page<SavedAlbum>(response.data, SavedAlbum); | ||
}; | ||
|
||
export const getCurrentUserSavedTracks = async (params?: { | ||
limit?: number; | ||
offset?: number; | ||
market?: string; | ||
}) => { | ||
const response = await getAxiosSpotifyInstance().get('/me/tracks', { | ||
params, | ||
}); | ||
return new Page<SavedTrack>(response.data, SavedTrack); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.