Skip to content

Commit

Permalink
Merge pull request #92 from calluswhatyouwant/v0.7.x
Browse files Browse the repository at this point in the history
Upgrade to v0.7.0
  • Loading branch information
JRobsonJr committed Aug 20, 2020
2 parents 7cf2e49 + 2ca9bb5 commit fcb03b5
Show file tree
Hide file tree
Showing 20 changed files with 221 additions and 94 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## Unreleased

### Added

- All type declarations to the return type of requests.
- `PlaylistVersion` to encapsulate playlist modifications.

## [0.6.0] - 2020-03-30

### Added

Expand Down
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
"Robson Junior <jrobsonjr16@gmail.com> (https://github.com/JRobsonJr)"
],
"license": "MIT",
"version": "0.6.0",
"version": "0.7.0",
"dependencies": {
"@types/lodash": "^4.14.121",
"axios": "^0.18.1",
"lodash": "^4.17.13"
"lodash.differenceby": "^4.8.0",
"lodash.intersectionby": "^4.7.0",
"lodash.keys": "^4.2.0",
"lodash.omit": "^4.5.0",
"lodash.pick": "^4.4.0",
"lodash.snakecase": "^4.1.1"
},
"scripts": {
"start": "ts-node src/start.ts",
Expand Down Expand Up @@ -48,6 +52,12 @@
"main": "build/index.js",
"devDependencies": {
"@types/chai": "^4.1.7",
"@types/lodash.differenceby": "^4.8.6",
"@types/lodash.intersectionby": "^4.7.6",
"@types/lodash.keys": "^4.2.6",
"@types/lodash.omit": "^4.5.6",
"@types/lodash.pick": "^4.4.6",
"@types/lodash.snakecase": "^4.1.6",
"@types/mocha": "^5.2.5",
"@types/nock": "^9.3.0",
"chai": "^4.2.0",
Expand Down
14 changes: 6 additions & 8 deletions src/lib/browse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import _ from 'lodash';

import { getAxiosSpotifyInstance } from './driver';
import {
Category,
Expand All @@ -16,7 +14,7 @@ export const getCategory = async (
country?: string;
locale?: string;
}
) => {
): Promise<Category> => {
const response = await getAxiosSpotifyInstance().get(
`/browse/categories/${id}`,
{ params }
Expand All @@ -31,7 +29,7 @@ export const getCategoryPlaylists = async (
limit?: number;
offset?: number;
}
) => {
): Promise<Page<PlaylistSimplified>> => {
const response = await getAxiosSpotifyInstance().get(
`/browse/categories/${id}/playlists`,
{ params }
Expand All @@ -48,7 +46,7 @@ export const getCategories = async (params?: {
locale?: string;
limit?: number;
offset?: number;
}) => {
}): Promise<Page<Category>> => {
const response = await getAxiosSpotifyInstance().get('/browse/categories', {
params,
});
Expand All @@ -61,7 +59,7 @@ export const getFeaturedPlaylists = async (params?: {
timestamp?: string;
limit?: number;
offset?: number;
}) => {
}): Promise<Page<PlaylistSimplified>> => {
const response = await getAxiosSpotifyInstance().get(
'/browse/featured-playlists',
{ params }
Expand All @@ -77,7 +75,7 @@ export const getNewReleases = async (params?: {
country?: string;
limit?: number;
offset?: number;
}) => {
}): Promise<Page<AlbumSimplified>> => {
const response = await getAxiosSpotifyInstance().get(
'/browse/new-releases',
{ params }
Expand All @@ -92,7 +90,7 @@ export const getRecommendations = async (params?: {
seedGenres?: string[];
seedTracks?: string[];
[rest: string]: any;
}) => {
}): Promise<Recommendations> => {
const updatedParams = propertiesToSnakeCase(params);
const response = await getAxiosSpotifyInstance().get('/recommendations', {
params: updatedParams,
Expand Down
7 changes: 5 additions & 2 deletions src/lib/episodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Episode } from './models';
export const getSeveralEpisodes = async (
ids: string[],
params?: { market?: string }
) => {
): Promise<Episode[]> => {
const response = await getAxiosSpotifyInstance().get('/episodes', {
params: { ids: ids.join(','), ...params },
});
Expand All @@ -13,7 +13,10 @@ export const getSeveralEpisodes = async (
);
};

export const getEpisode = async (id: string, params?: { market?: string }) => {
export const getEpisode = async (
id: string,
params?: { market?: string }
): Promise<Episode> => {
const response = await getAxiosSpotifyInstance().get(`/episodes/${id}`, {
params,
});
Expand Down
13 changes: 9 additions & 4 deletions src/lib/follow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ export const checkUsersFollowingPlaylist = async (
return response.data;
};

// TODO Improve responses based on Spotify

export const followArtistsOrUsers = async (
ids: string[],
type: 'artist' | 'user'
) => {
): Promise<string> => {
const params = { type };
const response = await getAxiosSpotifyInstance().put(
'/me/following',
Expand All @@ -83,7 +85,10 @@ export const followArtistsOrUsers = async (
return response.data;
};

export const followPlaylist = async (id: string, publicFollow?: boolean) => {
export const followPlaylist = async (
id: string,
publicFollow?: boolean
): Promise<string> => {
const response = await getAxiosSpotifyInstance().put(
`/playlists/${id}/followers`,
{ public: publicFollow }
Expand All @@ -94,7 +99,7 @@ export const followPlaylist = async (id: string, publicFollow?: boolean) => {
export const unfollowArtistsOrUsers = async (
ids: string[],
type: 'artist' | 'user'
) => {
): Promise<string> => {
const params = { type };
const data = { ids };
const response = await getAxiosSpotifyInstance().delete('/me/following', {
Expand All @@ -104,7 +109,7 @@ export const unfollowArtistsOrUsers = async (
return response.data;
};

export const unfollowPlaylist = async (id: string) => {
export const unfollowPlaylist = async (id: string): Promise<string> => {
const response = await getAxiosSpotifyInstance().delete(
`/playlists/${id}/followers`
);
Expand Down
12 changes: 6 additions & 6 deletions src/lib/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Page, SavedAlbum, SavedShow, SavedTrack } from './models';
export const areSavedToCurrentUserLibrary = async (
ids: string[],
type: 'tracks' | 'albums' | 'shows'
) => {
): Promise<Boolean[]> => {
const params = { ids: ids.join() };
const response = await getAxiosSpotifyInstance().get(
`/me/${type}/contains`,
Expand All @@ -17,7 +17,7 @@ export const getCurrentUserSavedAlbums = async (params?: {
limit?: number;
offset?: number;
market?: string;
}) => {
}): Promise<Page<SavedAlbum>> => {
const response = await getAxiosSpotifyInstance().get('/me/albums', {
params,
});
Expand All @@ -28,7 +28,7 @@ export const getCurrentUserSavedTracks = async (params?: {
limit?: number;
offset?: number;
market?: string;
}) => {
}): Promise<Page<SavedTrack>> => {
const response = await getAxiosSpotifyInstance().get('/me/tracks', {
params,
});
Expand All @@ -39,7 +39,7 @@ export const getCurrentUserSavedShows = async (params?: {
limit?: number;
offset?: number;
market?: string;
}) => {
}): Promise<Page<SavedShow>> => {
const response = await getAxiosSpotifyInstance().get('/me/shows', {
params,
});
Expand All @@ -49,7 +49,7 @@ export const getCurrentUserSavedShows = async (params?: {
export const saveToCurrentUserLibrary = async (
ids: string[],
type: 'albums' | 'tracks' | 'shows'
) => {
): Promise<string> => {
const response = await getAxiosSpotifyInstance().put(`/me/${type}`, {
ids,
});
Expand All @@ -59,7 +59,7 @@ export const saveToCurrentUserLibrary = async (
export const removeFromCurrentUserLibrary = async (
ids: string[],
type: 'albums' | 'tracks' | 'shows'
) => {
): Promise<string> => {
const data = { ids };
const response = await getAxiosSpotifyInstance().delete(`/me/${type}`, {
data,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/models/album/album.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import _ from 'lodash';

import AlbumSimplified from './album-simplified';
import Page from '../paging/page';
import TrackSimplified from '../track/track-simplified';
Expand Down Expand Up @@ -51,7 +49,9 @@ class Album extends AlbumSimplified {

async getDurationMs(): Promise<number> {
const tracks = await this.getAllTracks();
return _.sum(tracks.map(track => track.durationMs));
return tracks
.map(track => track.durationMs)
.reduce((duration1, duration2) => duration1 + duration2, 0);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export { default as PlayHistory } from './player/play-history';
export { default as Playlist } from './playlist/playlist';
export { default as PlaylistSimplified } from './playlist/playlist-simplified';
export { default as PlaylistTrack } from './playlist/playlist-track';
export { default as PlaylistVersion } from './playlist/playlist-version';
export { default as SearchResults } from './search/search-results';
export { default as Show } from './show/show';
export { default as ShowSimplified } from './show/show-simplified';
Expand Down
9 changes: 9 additions & 0 deletions src/lib/models/playlist/playlist-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class PlaylistVersion {
snapshotId: string;

constructor(json: any) {
this.snapshotId = json.snapshot_id;
}
}

export default PlaylistVersion;
7 changes: 4 additions & 3 deletions src/lib/models/track/track.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'lodash';
import differenceBy from 'lodash.differenceby';
import intersectionBy from 'lodash.intersectionby';

import AlbumSimplified from '../album/album-simplified';
import ArtistSimplified from '../artist/artist-simplified';
Expand All @@ -23,11 +24,11 @@ class Track extends TrackSimplified {
}

get mainArtists(): ArtistSimplified[] {
return _.intersectionBy(this.artists, this.album.artists, 'id');
return intersectionBy(this.artists, this.album.artists, 'id');
}

get featuredArtists(): ArtistSimplified[] {
return _.differenceBy(this.artists, this.album.artists, 'id');
return differenceBy(this.artists, this.album.artists, 'id');
}

get releaseYear() {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/personalization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const getCurrentUserTopArtists = async (params?: {
limit?: number;
offset?: number;
range?: string;
}) => {
}): Promise<Page<Artist>> => {
const response = await getAxiosSpotifyInstance().get(
'https://api.spotify.com/v1/me/top/artists',
{ params }
Expand All @@ -17,7 +17,7 @@ export const getCurrentUserTopTracks = async (params?: {
limit?: number;
offset?: number;
range?: string;
}) => {
}): Promise<Page<Track>> => {
const response = await getAxiosSpotifyInstance().get(
'https://api.spotify.com/v1/me/top/tracks',
{ params }
Expand Down

0 comments on commit fcb03b5

Please sign in to comment.