easy-spotify-ts
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -5,3 +5,4 @@ import { AxiosInstance, AxiosPromise, AxiosRequestConfig } from "axios"; | ||
import { Artist } from "./models/Artist"; | ||
import { PagingTracks, PagingAlbums } from "./models/Paging"; | ||
import { PagingAlbums, PagingTracks } from "./models/Paging"; | ||
import { Track } from "./models/Track"; | ||
export interface GetAlbumTracksOptions { | ||
@@ -32,4 +33,6 @@ limit?: number; | ||
getArtistAlbums(id: string, options?: GetArtistAlbumsOptions): Promise<PagingAlbums>; | ||
getArtistTopTracks(id: string, options?: GetAlbumOptions): Promise<Track[]>; | ||
getArtistRelatedArtists(id: string): Promise<Artist[]>; | ||
buildRequest(endpoint: string, params?: AxiosRequestConfig["params"], method?: string): AxiosPromise<any>; | ||
private buildHeaders; | ||
} |
@@ -52,2 +52,3 @@ "use strict"; | ||
var Artist_1 = require("./models/Artist"); | ||
var Track_1 = require("./models/Track"); | ||
var EasySpotify = /** @class */ (function () { | ||
@@ -229,2 +230,55 @@ function EasySpotify(config) { | ||
}; | ||
EasySpotify.prototype.getArtistTopTracks = function (id, options) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var response, tracks, err_7; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, this.buildRequest("artists/" + id + "/top-tracks", options)]; | ||
case 1: | ||
response = _a.sent(); | ||
if (response.data.tracks) { | ||
tracks = response.data.tracks.map(function (track) { | ||
return new Track_1.Track(track); | ||
}); | ||
return [2 /*return*/, tracks]; | ||
} | ||
else { | ||
throw new Error("Could not find any tracks for provided id"); | ||
} | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
err_7 = _a.sent(); | ||
throw err_7; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
EasySpotify.prototype.getArtistRelatedArtists = function (id) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var response, artists, err_8; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, this.buildRequest("artists/" + id + "/related-artists")]; | ||
case 1: | ||
response = _a.sent(); | ||
if (response.data.artists) { | ||
artists = response.data.artists.map(function (artist) { | ||
return new Artist_1.Artist(artist); | ||
}); | ||
return [2 /*return*/, artists]; | ||
} | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
err_8 = _a.sent(); | ||
throw err_8; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
EasySpotify.prototype.buildRequest = function (endpoint, params, method) { | ||
@@ -231,0 +285,0 @@ if (method === void 0) { method = "get"; } |
{ | ||
"name": "easy-spotify-ts", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "A Spotify Web API library in Typescript", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -11,3 +11,3 @@ # EasySpotifyTS - A Spotify Web Api TS Wrapper | ||
### TypeScript environment | ||
### NodeJS Environment | ||
@@ -18,8 +18,7 @@ Install [easy-spotify-ts](https://www.npmjs.com/package/easy-spotify-ts), and then just import and use the library: | ||
```sh | ||
$ npm install node-fetch easy-spotify --save | ||
$ npm install easy-spotify-ts --save | ||
``` | ||
`app.ts` | ||
```ts | ||
import { EasySpotify, EasySpotifyConfig } from "easy-spotify-ts"; | ||
import { Album } from "easy-spotify-ts/dist/models"; | ||
`app.js` | ||
```js | ||
const { EasySpotify, EasySpotifyConfig } = require("easy-spotify-ts"); | ||
@@ -30,4 +29,6 @@ const spotify = new EasySpotify(new EasySpotifyConfig("your-api-token")); | ||
spotify.getAlbums(["382ObEPsp2rxGrnsizN5TX", "1A2GTWGtFfWp7KSQTwWOyo"], {market: "ES"}).then((albums) => { | ||
// do something with albums | ||
console.log(albums); | ||
}).catch((error) => { | ||
// catch an error, like invalid token or invalid request | ||
console.log(error); | ||
@@ -88,3 +89,3 @@ }); | ||
This method returns an array of simplified album objects for the given artist id. | ||
> Check [official documentation page](https://developer.spotify.com/documentation/web-api/reference/artists/get-several-artists/) | ||
> Check [official documentation page](https://developer.spotify.com/documentation/web-api/reference/artists/get-artists-albums/) | ||
```ts | ||
@@ -103,5 +104,27 @@ const artistAlbums = await spotify.getArtistAlbums("4aawyAB9vmqN3uQ7FjRGTy", { | ||
### getArtistTopTracks(id: string, options?: GetAlbumOptions): Promise\<Track[]\> | ||
This method returns an array of up to 10 top Track objects for the given artist id. | ||
> Check official [documentation page](https://developer.spotify.com/documentation/web-api/reference/artists/get-artists-top-tracks/) | ||
```ts | ||
const topTracks = await spotfiy.getArtistTopTracks("43ZHCT0cAZBISjO8DG9PnE", {market: "SE"}); | ||
// do something with tracks | ||
// topTracks[0].name | ||
// topTracks[2].disc_number | ||
// topTracks[9].preview_url | ||
``` | ||
### getArtistRelatedArtists(id: string): Promise<Artist[]> | ||
This method returns an array of related artists for the given artist id. | ||
> Check official [documentation page](https://developer.spotify.com/documentation/web-api/reference/artists/get-related-artists/) | ||
```ts | ||
const relatedArtists = await spotfiy.getArtistRelatedArtists("43ZHCT0cAZBISjO8DG9PnE"); | ||
// do something with artists | ||
// relatedArtists[0].followers.total | ||
// relatedArtists[1].images[0].url | ||
// relatedArtists[3].genres[0] | ||
``` | ||
## <a name="features"></a> Features to implement | ||
- [ ] Support Search endpoints | ||
- [ ] Support Artists endpoints | ||
- [x] Support Artists endpoints | ||
- [ ] Support Browse endpoints | ||
@@ -108,0 +131,0 @@ - [ ] Support Follow endpoints |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31734
31
610
142