Skip to content

Commit

Permalink
Merge pull request #86 from calluswhatyouwant/v0.6.x
Browse files Browse the repository at this point in the history
Upgrade to v0.6.0
  • Loading branch information
JRobsonJr committed Mar 30, 2020
2 parents c71b57b + 7927257 commit 7cf2e49
Show file tree
Hide file tree
Showing 18 changed files with 339 additions and 20 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Added

- Podcast-related retrieval and searching endpoints: `getEpisode`, `getSeveralEpisodes`, `getCurrentUserSavedShows`, `searchShows`, `searchEpisodes`.
- Podcast-related models: `EpisodeSimplified`, `Episode`, `SavedShow`, `Show`, `ShowSimplified`.
- `actions` to `CurrentlyPlaying` and `Episode` as a possible `item` type.
- `episodes` and `shows` as possible attributes in `SearchResults`.
- `additionalTypes` to the query parameters of `getCurrentUserCurrentlyPlayingTrack` and `getUserPlaybackInformation` to allow considering an `Episode` as the currently playing media.
- `'shows'` as a possible value for the `type` in `areSavedToCurrentUserLibrary`.

### Changed

- `saveAlbumsOrTracksForCurrentUser` renamed to `saveToCurrentUserLibrary` and support to shows.
- `removeAlbumsOrTracksForCurrentUser` renamed to `removeFromCurrentUserLibrary` and support to shows.

## [0.5.2] - 2019-10-27

### Added
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"Robson Junior <jrobsonjr16@gmail.com> (https://github.com/JRobsonJr)"
],
"license": "MIT",
"version": "0.5.2",
"version": "0.6.0",
"dependencies": {
"@types/lodash": "^4.14.121",
"axios": "^0.18.1",
Expand Down
21 changes: 21 additions & 0 deletions src/lib/episodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { getAxiosSpotifyInstance } from './driver';
import { Episode } from './models';

export const getSeveralEpisodes = async (
ids: string[],
params?: { market?: string }
) => {
const response = await getAxiosSpotifyInstance().get('/episodes', {
params: { ids: ids.join(','), ...params },
});
return response.data.episodes.map(
(episodeJson: any) => new Episode(episodeJson)
);
};

export const getEpisode = async (id: string, params?: { market?: string }) => {
const response = await getAxiosSpotifyInstance().get(`/episodes/${id}`, {
params,
});
return new Episode(response.data);
};
2 changes: 2 additions & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ export * from './albums';
export * from './artists';
export * from './browse';
export * from './driver';
export * from './episodes';
export * from './follow';
export * from './library';
export * from './personalization';
export * from './playlists';
export * from './player';
export * from './search';
export * from './shows';
export * from './tracks';
export * from './users-profile';
export * from './models';
23 changes: 17 additions & 6 deletions src/lib/library.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getAxiosSpotifyInstance } from './driver';
import { Page, SavedAlbum, SavedTrack } from './models';
import { Page, SavedAlbum, SavedShow, SavedTrack } from './models';

export const areSavedToCurrentUserLibrary = async (
ids: string[],
type: 'tracks' | 'albums'
type: 'tracks' | 'albums' | 'shows'
) => {
const params = { ids: ids.join() };
const response = await getAxiosSpotifyInstance().get(
Expand Down Expand Up @@ -35,19 +35,30 @@ export const getCurrentUserSavedTracks = async (params?: {
return new Page<SavedTrack>(response.data, SavedTrack);
};

export const saveAlbumsOrTracksForCurrentUser = async (
export const getCurrentUserSavedShows = async (params?: {
limit?: number;
offset?: number;
market?: string;
}) => {
const response = await getAxiosSpotifyInstance().get('/me/shows', {
params,
});
return new Page<SavedShow>(response.data, SavedShow);
};

export const saveToCurrentUserLibrary = async (
ids: string[],
type: 'albums' | 'tracks'
type: 'albums' | 'tracks' | 'shows'
) => {
const response = await getAxiosSpotifyInstance().put(`/me/${type}`, {
ids,
});
return response.data;
};

export const removeAlbumsOrTracksForCurrentUser = async (
export const removeFromCurrentUserLibrary = async (
ids: string[],
type: 'albums' | 'tracks'
type: 'albums' | 'tracks' | 'shows'
) => {
const data = { ids };
const response = await getAxiosSpotifyInstance().delete(`/me/${type}`, {
Expand Down
71 changes: 71 additions & 0 deletions src/lib/models/episode/episode-simplified.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import Image from '../common/image';

class EpisodeSimplified {
audioPreviewUrl: string;

description: string;

durationMs: number;

explicit: boolean;

externalUrls: any;

href: string;

id: string;

images: Image[];

isExternallyHosted: boolean | null;

isPlayable: boolean;

languages: string[];

name: string;

releaseDate: string;

releaseDatePrecision: 'year' | 'month' | 'day';

resumePoint?: ResumePoint;

type: 'episode';

uri: string;

constructor(json: any) {
this.audioPreviewUrl = json.audio_preview_url;
this.description = json.description;
this.durationMs = json.duration_ms;
this.explicit = json.explicit;
this.externalUrls = json.external_urls;
this.href = json.href;
this.id = json.id;
this.images = json.images.map((imageJson: any) => new Image(imageJson));
this.isExternallyHosted = json.is_externally_hosted;
this.isPlayable = json.is_playable;
this.languages = json.languages;
this.name = json.name;
this.releaseDate = json.release_date;
this.releaseDatePrecision = json.release_date_precision;
if (json.resume_point) {
this.resumePoint = new ResumePoint(json.resume_point);
}
this.type = json.type;
this.uri = json.uri;
}
}

class ResumePoint {
fullyPlayed: boolean;
resumePositionMs: number;

constructor(json: any) {
this.fullyPlayed = json.fully_played;
this.resumePositionMs = json.resume_position_ms;
}
}

export default EpisodeSimplified;
13 changes: 13 additions & 0 deletions src/lib/models/episode/episode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import EpisodeSimplified from './episode-simplified';
import ShowSimplified from '../show/show-simplified';

class Episode extends EpisodeSimplified {
show: ShowSimplified;

constructor(json: any) {
super(json);
this.show = new ShowSimplified(json.show);
}
}

export default Episode;
5 changes: 5 additions & 0 deletions src/lib/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export { default as Copyright } from './common/copyright';
export { default as Error } from './common/error';
export { default as Followers } from './common/followers';
export { default as Image } from './common/image';
export { default as Episode } from './episode/episode';
export { default as EpisodeSimplified } from './episode/episode-simplified';
export { default as SavedAlbum } from './library/saved-album';
export { default as SavedShow } from './library/saved-show';
export { default as SavedTrack } from './library/saved-track';
export { default as TrackLink } from './other/track-link';
export { default as CursorBasedPage } from './paging/cursor-based-page';
Expand All @@ -25,6 +28,8 @@ 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 SearchResults } from './search/search-results';
export { default as Show } from './show/show';
export { default as ShowSimplified } from './show/show-simplified';
export { default as AudioAnalysis } from './track/audio-analysis';
export { default as AudioFeatures } from './track/audio-features';
export { default as Track } from './track/track';
Expand Down
14 changes: 14 additions & 0 deletions src/lib/models/library/saved-show.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import ShowSimplified from '../show/show-simplified';

class SavedShow {
addedAt: string;

show: ShowSimplified;

constructor(json: any) {
this.addedAt = json.added_at;
this.show = new ShowSimplified(json.show);
}
}

export default SavedShow;
13 changes: 11 additions & 2 deletions src/lib/models/player/currently-playing.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import Context from './context';
import Track from '../track/track';
import Episode from '../episode/episode';

class CurrentlyPlaying {
actions: any;
context: Context | null;
currentlyPlayingType: string;
isPlaying: boolean;
item: Track | null;
item: Track | Episode | null;
progressMs: number;
timestamp: number;

constructor(json: any) {
this.actions = json.actions;
this.context = json.context ? new Context(json.context) : null;
this.currentlyPlayingType = json.currently_playing_type;
this.isPlaying = json.is_playing;
this.item = json.item ? new Track(json.item) : null;
if (this.currentlyPlayingType === 'track' && json.item) {
this.item = new Track(json.item);
} else if (this.currentlyPlayingType === 'episode' && json.item) {
this.item = new Episode(json.item);
} else {
this.item = null;
}
this.progressMs = json.progress_ms;
this.timestamp = json.timestamp;
}
Expand Down
18 changes: 18 additions & 0 deletions src/lib/models/search/search-results.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import Page from '../paging/page';
import AlbumSimplified from '../album/album-simplified';
import Artist from '../artist/artist';
import EpisodeSimplified from '../episode/episode-simplified';
import PlaylistSimplified from '../playlist/playlist-simplified';
import ShowSimplified from '../show/show-simplified';
import Track from '../track/track';

class SearchResults {
albums?: Page<AlbumSimplified>;
artists?: Page<Artist>;
playlists?: Page<PlaylistSimplified>;
tracks?: Page<Track>;
episodes?: Page<EpisodeSimplified>;
shows?: Page<ShowSimplified>;

constructor(json: any) {
if (json.albums) {
Expand All @@ -31,6 +35,20 @@ class SearchResults {
if (json.tracks) {
this.tracks = new Page<Track>(json, Track, 'tracks');
}
if (json.episodes) {
this.episodes = new Page<EpisodeSimplified>(
json,
EpisodeSimplified,
'episodes'
);
}
if (json.shows) {
this.shows = new Page<ShowSimplified>(
json,
ShowSimplified,
'shows'
);
}
}
}

Expand Down
56 changes: 56 additions & 0 deletions src/lib/models/show/show-simplified.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import Copyright from '../common/copyright';
import Image from '../common/image';

class ShowSimplified {
availableMarkets: string[];

copyrights: Copyright[];

description: string;

explicit: boolean;

externalUrls: any;

href: string;

id: string;

images: Image[];

isExternallyHosted: boolean | null;

languages: string[];

mediaType: string;

name: string;

publisher: string;

type: 'show';

uri: string;

constructor(json: any) {
this.availableMarkets = json.available_markets;
this.copyrights = json.copyrights.map(
(copyrightJson: any) => new Copyright(copyrightJson)
);
this.description = json.description;
this.explicit = json.explicit;
this.externalUrls = json.external_urls;
this.href = json.href;
this.id = json.id;
this.images = json.images.map((imageJson: any) => new Image(imageJson));
this.isExternallyHosted = json.is_externally_hosted;
this.languages = json.languages;
this.mediaType = json.media_type;
this.name = json.name;
this.publisher = json.publisher;
this.type = json.type;
this.uri = json.uri;
}
}

export default ShowSimplified;
17 changes: 17 additions & 0 deletions src/lib/models/show/show.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import EpisodeSimplified from '../episode/episode-simplified';
import Page from '../paging/page';
import ShowSimplified from './show-simplified';

class Show extends ShowSimplified {
episodes: Page<EpisodeSimplified>;

constructor(json: any) {
super(json);
this.episodes = new Page<EpisodeSimplified>(
json.episodes,
EpisodeSimplified
);
}
}

export default Show;

0 comments on commit 7cf2e49

Please sign in to comment.