diff --git a/src/parse.ts b/src/parse.ts index 239722e..8d6b8ea 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -7,6 +7,7 @@ import Artist from './artist'; import Album from './album'; import Track from './track'; import Episode from './episode'; +import Show from './show'; import User from './user'; import SpotifyUri from './spotify-uri'; import { decode } from './util'; @@ -86,5 +87,8 @@ function parseParts(uri: string, parts: string[]): ParsedSpotifyUri { if (parts[1] === 'episode') { return new Episode(uri, parts[2]); } + if (parts[1] === 'show') { + return new Show(uri, parts[2]); + } throw new TypeError(`Could not determine type for: ${uri}`); } diff --git a/src/show.ts b/src/show.ts new file mode 100644 index 0000000..33ad470 --- /dev/null +++ b/src/show.ts @@ -0,0 +1,24 @@ +import { encode } from './util'; +import SpotifyUri from './spotify-uri'; + +export default class Show extends SpotifyUri { + public type = 'show'; + public id: string; + + constructor(uri: string, id: string) { + super(uri); + this.id = id; + } + + public static is(v: any): v is Show { + return Boolean(v && v.type === 'show'); + } + + public toURI(): string { + return `spotify:${this.type}:${encode(this.id)}`; + } + + public toURL(): string { + return `/${this.type}/${encode(this.id)}`; + } +} diff --git a/test/test.js b/test/test.js index a7db3b7..a0e627c 100644 --- a/test/test.js +++ b/test/test.js @@ -19,6 +19,12 @@ describe('parse()', function() { assert.equal('episode', obj.type); assert.equal('64TORH3xleuD1wcnFsrH1E', obj.id); }); + it('should parse "show" URLs', function () { + let url = 'https://open.spotify.com/show/6uxKcBftLv1aOWoNL7UzTl' + let obj = parse(url) + assert.equal('show', obj.type) + assert.equal('6uxKcBftLv1aOWoNL7UzTl', obj.id) + }); it('should parse user "playlist" URLs', function() { let url = 'http://open.spotify.com/user/tootallnate/playlist/0Lt5S4hGarhtZmtz7BNTeX'; @@ -124,6 +130,12 @@ describe('parse()', function() { assert.equal('episode', obj.type); assert.equal('64TORH3xleuD1wcnFsrH1E', obj.id); }); + it('should parse "show" URIs', function () { + let uri = 'spotify:show:6uxKcBftLv1aOWoNL7UzTl' + let obj = parse(uri) + assert.equal('show', obj.type) + assert.equal('6uxKcBftLv1aOWoNL7UzTl', obj.id) + }); it('should parse user "playlist" URIs', function() { let uri = 'spotify:user:daftpunkofficial:playlist:6jP6EcvAwqNksccDkIe6hX'; @@ -267,6 +279,13 @@ describe('formatOpenURL()', function() { let actual = formatOpenURL(obj); assert.equal(actual, expected); }); + it('should format "show" URIs', function () { + let uri = 'spotify:show:6uxKcBftLv1aOWoNL7UzTl' + let obj = parse(uri) + let expected = 'http://open.spotify.com/show/6uxKcBftLv1aOWoNL7UzTl' + let actual = formatOpenURL(obj) + assert.equal(actual, expected) + }); it('should format user "playlist" URIs', function() { let uri = 'spotify:user:daftpunkofficial:playlist:6jP6EcvAwqNksccDkIe6hX';