easy-spotify-ts
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -5,5 +5,5 @@ import { AxiosInstance, AxiosPromise, AxiosRequestConfig } from "axios"; | ||
import { Artist } from "./models/Artist"; | ||
import { PagingAlbums, PagingTracks } from "./models/Paging"; | ||
import { PagingAlbums, PagingArtists, PagingPlaylists, PagingTracks, PagingSearch } from "./models/Paging"; | ||
import { Track } from "./models/Track"; | ||
export interface GetAlbumTracksOptions { | ||
export interface OptionalRequestParams { | ||
limit?: number; | ||
@@ -13,6 +13,10 @@ offset?: number; | ||
} | ||
export interface SearchRequestParams extends OptionalRequestParams { | ||
type: string; | ||
include_external?: string; | ||
} | ||
export interface GetAlbumOptions { | ||
market: string; | ||
} | ||
export interface GetArtistAlbumsOptions extends GetAlbumTracksOptions { | ||
export interface GetArtistAlbumsOptions extends OptionalRequestParams { | ||
include_groups?: string; | ||
@@ -30,3 +34,3 @@ } | ||
getAlbums(ids: string[], options?: GetAlbumOptions): Promise<Album[]>; | ||
getAlbumTracks(id: string, options?: GetAlbumTracksOptions): Promise<PagingTracks>; | ||
getAlbumTracks(id: string, options?: OptionalRequestParams): Promise<PagingTracks>; | ||
getArtist(id: string): Promise<Artist>; | ||
@@ -37,4 +41,9 @@ getArtists(ids: string[]): Promise<Artist[]>; | ||
getArtistRelatedArtists(id: string): Promise<Artist[]>; | ||
searchAlbums(query: string, options?: OptionalRequestParams): Promise<PagingAlbums>; | ||
searchArtists(query: string, options?: OptionalRequestParams): Promise<PagingArtists>; | ||
searchPlaylists(query: string, options?: OptionalRequestParams): Promise<PagingPlaylists>; | ||
searchTracks(query: string, options?: OptionalRequestParams): Promise<PagingTracks>; | ||
search(query: string, options: SearchRequestParams): Promise<PagingSearch>; | ||
buildRequest(endpoint: string, params?: AxiosRequestConfig["params"], method?: string): AxiosPromise<any>; | ||
private buildHeaders; | ||
} |
@@ -282,2 +282,116 @@ "use strict"; | ||
}; | ||
EasySpotify.prototype.searchAlbums = function (query, options) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var params, response, err_9; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
params = __assign({}, options, { q: query, type: "album" }); | ||
return [4 /*yield*/, this.buildRequest("search", params)]; | ||
case 1: | ||
response = _a.sent(); | ||
if (response.data.albums) { | ||
return [2 /*return*/, response.data.albums]; | ||
} | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
err_9 = _a.sent(); | ||
throw err_9; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
EasySpotify.prototype.searchArtists = function (query, options) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var params, response, err_10; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
params = __assign({}, options, { q: query, type: "artist" }); | ||
return [4 /*yield*/, this.buildRequest("search", params)]; | ||
case 1: | ||
response = _a.sent(); | ||
if (response.data.artists) { | ||
return [2 /*return*/, response.data.artists]; | ||
} | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
err_10 = _a.sent(); | ||
throw err_10; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
EasySpotify.prototype.searchPlaylists = function (query, options) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var params, response, err_11; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
params = __assign({}, options, { q: query, type: "playlist" }); | ||
return [4 /*yield*/, this.buildRequest("search", params)]; | ||
case 1: | ||
response = _a.sent(); | ||
if (response.data.playlists) { | ||
return [2 /*return*/, response.data.playlists]; | ||
} | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
err_11 = _a.sent(); | ||
throw err_11; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
EasySpotify.prototype.searchTracks = function (query, options) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var params, response, err_12; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
params = __assign({}, options, { q: query, type: "track" }); | ||
return [4 /*yield*/, this.buildRequest("search", params)]; | ||
case 1: | ||
response = _a.sent(); | ||
if (response.data.tracks) { | ||
return [2 /*return*/, response.data.tracks]; | ||
} | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
err_12 = _a.sent(); | ||
throw err_12; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
EasySpotify.prototype.search = function (query, options) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var response, err_13; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, this.buildRequest("search", __assign({}, options, { q: query }))]; | ||
case 1: | ||
response = _a.sent(); | ||
if (response.data) { | ||
return [2 /*return*/, response.data]; | ||
} | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
err_13 = _a.sent(); | ||
throw err_13; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
EasySpotify.prototype.buildRequest = function (endpoint, params, method) { | ||
@@ -284,0 +398,0 @@ if (method === void 0) { method = "get"; } |
@@ -17,2 +17,5 @@ import { SimplifiedArtist } from "./Artist"; | ||
name: string; | ||
release_date: string; | ||
release_date_precision: string; | ||
restrictions: any; | ||
type: string; | ||
@@ -33,5 +36,6 @@ uri: string; | ||
name: string; | ||
popularity: number; | ||
release_date: string; | ||
release_date_precision: string; | ||
restrictions: any; | ||
popularity: number; | ||
tracks: PagingTracks; | ||
@@ -38,0 +42,0 @@ type: string; |
import { SimplifiedAlbum } from "./Album"; | ||
import { SimplifiedArtist } from "./Artist"; | ||
import { SimplifiedPlaylist } from "./Playlist"; | ||
import { SimplifiedTrack } from "./SimplifiedTrack"; | ||
@@ -18,1 +20,13 @@ export interface Paging { | ||
} | ||
export interface PagingArtists extends Paging { | ||
items: SimplifiedArtist[]; | ||
} | ||
export interface PagingPlaylists extends Paging { | ||
items: SimplifiedPlaylist[]; | ||
} | ||
export interface PagingSearch { | ||
tracks: PagingTracks; | ||
albums: PagingAlbums; | ||
artists: PagingArtists; | ||
playlists: PagingPlaylists; | ||
} |
{ | ||
"name": "easy-spotify-ts", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "A Spotify Web API library in Typescript", | ||
@@ -19,3 +19,5 @@ "main": "dist/index.js", | ||
"chai": "^4.2.0", | ||
"codecov": "^3.2.0", | ||
"mocha": "^5.2.0", | ||
"nyc": "^13.3.0", | ||
"rimraf": "^2.6.2", | ||
@@ -34,8 +36,26 @@ "sinon": "^7.1.1", | ||
"build:example": "rimraf ./example/dist && tsc ./examples/app.ts --outDir ./examples/dist --lib es2015,es6,dom", | ||
"build:all": "npm run build:tsc && npm run build:example", | ||
"dev": "tsc -w", | ||
"test": "mocha -r ts-node/register tests/**/*.spec.js", | ||
"test": "mocha -r ts-node/register tests/**/*.spec.ts", | ||
"test:tdd": "mocha -r ts-node/register tests/**/*.spec.ts --watch-extensions ts --watch", | ||
"lint": "tslint -p .", | ||
"prepush": "npm run lint" | ||
"prepush": "npm run lint", | ||
"test:coverage": "nyc npm test", | ||
"test:report": "nyc report --reporter=text-lcov > coverage.lcov" | ||
}, | ||
"nyc": { | ||
"extension": [ | ||
".ts" | ||
], | ||
"require": [ | ||
"ts-node/register" | ||
], | ||
"reporter": [ | ||
"text", | ||
"html" | ||
], | ||
"exclude": [ | ||
"tests/**" | ||
] | ||
}, | ||
"repository": { | ||
@@ -42,0 +62,0 @@ "type": "git", |
# EasySpotifyTS - A Spotify Web Api TS Wrapper | ||
This is a TypeScript library that wraps [Spotify Web API](https://developer.spotify.com/documentation/web-api/) to make your life easier. It's still not published and in **development**. See [features list](#features) to check what else I plan to add to this library. | ||
<p align="center"> | ||
<img><a href="https://nodei.co/npm/easy-spotify-ts/"><img src="https://nodei.co/npm/easy-spotify-ts.png"></a> | ||
</p> | ||
[![Build Status](https://travis-ci.org/bruno-lombardi/easy-spotify-ts.svg?branch=master)](https://travis-ci.org/bruno-lombardi/easy-spotify-ts) | ||
[![codecov](https://codecov.io/gh/bruno-lombardi/easy-spotify-ts/branch/master/graph/badge.svg)](https://codecov.io/gh/bruno-lombardi/easy-spotify-ts) | ||
This is a Javascript library written in Typescript that wraps [Spotify Web API](https://developer.spotify.com/documentation/web-api/) to make your spotify responses and requests benefit from autocompletion. It's still not published and in **development**. See [features list](#features) to check what else I plan to add to this library. | ||
![Demo](demo.gif) | ||
There is also a [JS version here](https://github.com/bruno-lombardi/easy-spotify/). | ||
## Installation and Usage | ||
@@ -122,4 +127,64 @@ This library is easier than the JS version to use, because it doesn't have any external dependencies. Also, if you like **type hints**, or **intellisense**, here you get them evem for responses that come from Spotify. | ||
### searchAlbums(query: string, options?: OptionalRequestParams): Promise\<PagingAlbums\> | ||
This method returns an paging object of albums for the given query. | ||
> Check official [documentation page](https://developer.spotify.com/documentation/web-api/reference/search/search/) | ||
```ts | ||
const albums = await spotify.searchAlbums("Rock", {limit: 2}); | ||
// do something with albums | ||
// albums.items[0].id | ||
// albums.items[1].artists | ||
``` | ||
### searchArtists(query: string, options?: OptionalRequestParams): Promise\<PagingArtists\> | ||
This method returns an paging object of artists for the given query. | ||
> Check official [documentation page](https://developer.spotify.com/documentation/web-api/reference/search/search/) | ||
```ts | ||
const artists = await spotify.searchArtists("Elvis", {limit: 2}); | ||
// do something with artists | ||
// artists.items[0].name | ||
// artists.items[1].uri | ||
``` | ||
### searchPlaylists(query: string, options?: OptionalRequestParams): Promise\<PagingPlaylists\> | ||
This method returns an paging object of playlists for the given query. | ||
> Check official [documentation page](https://developer.spotify.com/documentation/web-api/reference/search/search/) | ||
```ts | ||
const playlists = await spotify.searchPlaylists("abba", {limit: 2, market: "US"}); | ||
// do something with playlists | ||
// playlists.items[0].tracks | ||
// playlists.items[1].owner | ||
``` | ||
### searchTracks(query: string, options?: OptionalRequestParams): Promise\<PagingTracks\> | ||
This method returns an paging object of tracks for the given query. | ||
> Check official [documentation page](https://developer.spotify.com/documentation/web-api/reference/search/search/) | ||
```ts | ||
const tracks = await spotify.searchTracks("love", {limit: 2}); | ||
// do something with playlists | ||
// tracks.items[0].artists | ||
// tracks.items[1].preview_url | ||
``` | ||
### search(query: string, options: SearchRequestParams): Promise\<PagingSearch\> | ||
This method returns an object that may contain albums, artists, playlists or tracks paging object. Under options, | ||
you should define the type as comma-separated list of wich ones you want (in singular). | ||
> Check official [documentation page](https://developer.spotify.com/documentation/web-api/reference/search/search/) | ||
```ts | ||
const result = await spotify.search("love", {type: "artist,playlist", limit: 2}); | ||
// do something with result | ||
// result.artists.items[0].id | ||
// result.playlists.total | ||
// result.playlists.items[0].name | ||
// result.tracks -> undefined | ||
// result.albums -> undefined | ||
``` | ||
## <a name="features"></a> Features to implement | ||
- [ ] Support Search endpoints | ||
- [x] Support Search endpoint | ||
- [x] Support Artists endpoints | ||
@@ -126,0 +191,0 @@ - [ ] Support Browse 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
42000
35
791
207
15