Socket
Socket
Sign inDemoInstall

easy-spotify-ts

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-spotify-ts - npm Package Compare versions

Comparing version 0.1.5 to 0.2.0

dist/models/Category.d.ts

35

dist/EasySpotify.d.ts
import { AxiosInstance, AxiosPromise, AxiosRequestConfig } from "axios";
import EasySpotifyConfig from "./EasySpotifyConfig";
import { Album } from "./models/Album";
import { Album, FeaturedAlbums } from "./models/Album";
import { Artist } from "./models/Artist";
import { PagingAlbums, PagingArtists, PagingPlaylists, PagingTracks, PagingSearch } from "./models/Paging";
import { PagingAlbums, PagingArtists, PagingPlaylists, PagingTracks, PagingSearch, PagingCategories } from "./models/Paging";
import { Track } from "./models/Track";
import { Category } from './models/Category';
import { FeaturedPlaylists } from "./models/Playlist";
import { RecommendationsQuery, Recommendations } from "./models/Recomendations";
export interface OptionalRequestParams {

@@ -43,4 +46,32 @@ limit?: number;

search(query: string, options: SearchRequestParams): Promise<PagingSearch>;
getBrowseCategory(id: string, options?: {
country?: string;
locale?: string;
}): Promise<Category>;
getBrowseCategoryPlaylists(id: string, options: {
country?: string;
limit?: number;
offset?: number;
}): Promise<PagingPlaylists>;
getBrowseListOfCategories(options: {
locale?: string;
country?: string;
offset?: number;
limit?: number;
}): Promise<PagingCategories>;
getBrowseFeaturedPlaylists(options: {
locale?: string;
country?: string;
timestamp?: Date;
limit?: number;
offset?: number;
}): Promise<FeaturedPlaylists>;
getBrowseNewReleases(options: {
country?: string;
limit?: number;
offset?: number;
}): Promise<FeaturedAlbums>;
getBrowseRecommendations(query: RecommendationsQuery): Promise<Recommendations>;
buildRequest(endpoint: string, params?: AxiosRequestConfig["params"], method?: string): AxiosPromise<any>;
private buildHeaders;
}

@@ -53,2 +53,3 @@ "use strict";

var Track_1 = require("./models/Track");
var Category_1 = require("./models/Category");
var EasySpotify = /** @class */ (function () {

@@ -397,2 +398,170 @@ function EasySpotify(config) {

};
EasySpotify.prototype.getBrowseCategory = function (id, options) {
return __awaiter(this, void 0, void 0, function () {
var response, err_14;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, this.buildRequest("browse/categories/" + id, options)];
case 1:
response = _a.sent();
if (response.data) {
return [2 /*return*/, new Category_1.Category(response.data)];
}
else {
throw new Error("Could not find any category with that id");
}
return [3 /*break*/, 3];
case 2:
err_14 = _a.sent();
throw err_14;
case 3: return [2 /*return*/];
}
});
});
};
EasySpotify.prototype.getBrowseCategoryPlaylists = function (id, options) {
return __awaiter(this, void 0, void 0, function () {
var response, err_15;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, this.buildRequest("browse/categories/" + id + "/playlists", options)];
case 1:
response = _a.sent();
if (response.data) {
return [2 /*return*/, response.data.playlists];
}
else {
throw new Error("Could not find any playlist from that category id");
}
return [3 /*break*/, 3];
case 2:
err_15 = _a.sent();
throw err_15;
case 3: return [2 /*return*/];
}
});
});
};
EasySpotify.prototype.getBrowseListOfCategories = function (options) {
return __awaiter(this, void 0, void 0, function () {
var response, err_16;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, this.buildRequest("browse/categories", options)];
case 1:
response = _a.sent();
if (response.data) {
return [2 /*return*/, response.data.categories];
}
else {
throw new Error("Could not get any categories");
}
return [3 /*break*/, 3];
case 2:
err_16 = _a.sent();
throw err_16;
case 3: return [2 /*return*/];
}
});
});
};
EasySpotify.prototype.getBrowseFeaturedPlaylists = function (options) {
return __awaiter(this, void 0, void 0, function () {
var response, err_17;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (options.timestamp) {
Object.assign(options, { timestamp: options.timestamp.toISOString() });
}
return [4 /*yield*/, this.buildRequest("browse/featured-playlists", options)];
case 1:
response = _a.sent();
if (response.data) {
return [2 /*return*/, response.data];
}
else {
throw new Error("Could not get any featured playlists");
}
return [3 /*break*/, 3];
case 2:
err_17 = _a.sent();
throw err_17;
case 3: return [2 /*return*/];
}
});
});
};
EasySpotify.prototype.getBrowseNewReleases = function (options) {
return __awaiter(this, void 0, void 0, function () {
var response, err_18;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, this.buildRequest("browse/new-releases", options)];
case 1:
response = _a.sent();
if (response.data) {
return [2 /*return*/, response.data];
}
else {
throw new Error("Could not get any albums");
}
return [3 /*break*/, 3];
case 2:
err_18 = _a.sent();
throw err_18;
case 3: return [2 /*return*/];
}
});
});
};
EasySpotify.prototype.getBrowseRecommendations = function (query) {
return __awaiter(this, void 0, void 0, function () {
var response, err_19;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (query.seed_artists && query.seed_artists.length) {
Object.assign(query, {
seed_artists: query.seed_artists.join(","),
});
}
if (query.seed_genres && query.seed_genres.length) {
Object.assign(query, {
seed_genres: query.seed_genres.join(","),
});
}
if (query.seed_tracks && query.seed_tracks.length) {
Object.assign(query, {
seed_tracks: query.seed_tracks.join(","),
});
}
return [4 /*yield*/, this.buildRequest("recommendations", query)];
case 1:
response = _a.sent();
if (response.data) {
return [2 /*return*/, response.data];
}
else {
throw new Error("Could not get any recommendations");
}
return [3 /*break*/, 3];
case 2:
err_19 = _a.sent();
throw err_19;
case 3: return [2 /*return*/];
}
});
});
};
EasySpotify.prototype.buildRequest = function (endpoint, params, method) {

@@ -399,0 +568,0 @@ if (method === void 0) { method = "get"; }

@@ -6,3 +6,7 @@ import { SimplifiedArtist } from "./Artist";

import { Image } from "./Image";
import { PagingTracks } from "./Paging";
import { PagingTracks, PagingAlbums } from "./Paging";
export interface FeaturedAlbums {
message: string;
albums: PagingAlbums;
}
export interface SimplifiedAlbum {

@@ -9,0 +13,0 @@ album_group?: string;

@@ -5,2 +5,3 @@ import { SimplifiedAlbum } from "./Album";

import { SimplifiedTrack } from "./SimplifiedTrack";
import { Category } from "./Category";
export interface Paging {

@@ -27,2 +28,5 @@ href: string;

}
export interface PagingCategories extends Paging {
items: Category[];
}
export interface PagingSearch {

@@ -29,0 +33,0 @@ tracks: PagingTracks;

import { ExternalUrls } from "./ExternalUrls";
import { Image } from "./Image";
import { User } from "./User";
import { PagingPlaylists } from "./Paging";
export interface FeaturedPlaylists {
message: string;
playlists: PagingPlaylists;
}
export interface SimplifiedPlaylist {

@@ -5,0 +10,0 @@ collaborative: boolean;

9

package.json
{
"name": "easy-spotify-ts",
"version": "0.1.5",
"version": "0.2.0",
"description": "A Spotify Web API library in Typescript",

@@ -8,3 +8,3 @@ "main": "dist/index.js",

"dependencies": {
"axios": "^0.18.0"
"axios": "^0.18.1"
},

@@ -22,3 +22,3 @@ "files": [

"mocha": "^5.2.0",
"nyc": "^13.3.0",
"nyc": "^15.0.0",
"rimraf": "^2.6.2",

@@ -70,3 +70,4 @@ "sinon": "^7.1.1",

"web",
"api"
"api",
"spotify recommendations"
],

@@ -73,0 +74,0 @@ "author": "Bruno Lombardi <djfrizer1@gmail.com> (https://github.com/bruno-lombardi)",

@@ -14,3 +14,3 @@ # EasySpotifyTS - A Spotify Web Api TS Wrapper

## Installation and Usage
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.
This library is lightweight and only have one external dependency, which is axios, a powerful HTTP requests library. Also, if you like **type hints**, or **intellisense**, with easy-spotify-ts you have them for responses that come from Spotify Web API.

@@ -28,2 +28,4 @@ ### NodeJS Environment

const { EasySpotify, EasySpotifyConfig } = require("easy-spotify-ts");
// or with ES Modules:
import { EasySpotify, EasySpotifyConfig } from 'easy-spotify-ts';

@@ -188,7 +190,91 @@ const spotify = new EasySpotify(new EasySpotifyConfig("your-api-token"));

### getBrowseCategory(id: string, options?: { country?: string, locale?: string }): Promise\<Category\>
This method returns a single category used to tag items in Spotify (on, for example, the Spotify player’s “Browse” tab).
> Check official [documentation page](https://developer.spotify.com/documentation/web-api/reference/browse/get-category/)
```ts
const result = await spotify.getBrowseCategory("party", {country: "US"});
// do something with result
// result.href
// result.icons[0].height
```
### getBrowseCategoryPlaylists(id: string, options: { country?: string, limit?: number, offset?: number }): Promise\<PagingPlaylists\>
This method returns a paged list of Spotify playlists tagged with a particular category.
> Check official [documentation page](https://developer.spotify.com/documentation/web-api/reference/browse/get-categorys-playlists/)
```ts
const result = await spotify.getBrowseCategoryPlaylists("party", {country: "US"});
// do something with result
// result.href
// result.items[0].description
// result.limit
// result.offset
```
### getBrowseListOfCategories(options: {locale?: string, country?: string, offset?: number, limit?: number}): Promise\<PagingCategories\>
This method returns a list of categories used to tag items in Spotify (on, for example, the Spotify player’s “Browse” tab).
> Check official [documentation page](https://developer.spotify.com/documentation/web-api/reference/browse/get-list-categories/)
```ts
const result = await spotify.getBrowseListOfCategories({country: "US", limit: 10});
// do something with result
// result.href
// result.items[0].id
// result.limit
// result.offset
```
### getBrowseFeaturedPlaylists(options: {locale?: string, country?: string, timestamp?: Date, limit?: number, offset?: number}): Promise\<FeaturedPlaylists\>
This method returns a list of Spotify featured playlists (shown, for example, on a Spotify player’s ‘Browse’ tab).
> Check official [documentation page](https://developer.spotify.com/documentation/web-api/reference/browse/get-list-featured-playlists/)
```ts
const result = await spotify.getBrowseFeaturedPlaylists({country: "US", limit: 10});
// do something with result
// result.message
// result.playlists.items[0].name
// result.playlists.limit
// result.playlists.offset
```
### getBrowseNewReleases(options: {country?: string, limit?: number, offset?: number}): Promise\<FeaturedAlbums\>
This method returns a list of new album releases featured in Spotify (shown, for example, on a Spotify player’s “Browse” tab).
> Check official [documentation page](https://developer.spotify.com/documentation/web-api/reference/browse/get-list-new-releases/)
```ts
const result = await spotify.getBrowseNewReleases({country: "US", limit: 10});
// do something with result
// result.message
// result.albums.items[0].name
// result.albums.limit
// result.albums.offset
```
### getBrowseRecommendations(query: RecommendationsQuery): Promise\<PagingCategories\>
This method can create a playlist-style listening experience based on seed artists, tracks and genres. There is a huge query options to use,
I suggest you to really check the documentation, though, each target_*
field has a hint when you type that should help you know what you're
doing.
> Check official [documentation page](https://developer.spotify.com/documentation/web-api/reference/browse/get-recommendations/)
```ts
const result = await spotify.getBrowseRecommendations(
{
limit: 10,
seed_tracks: ["4NHQUGzhtTLFvgF5SZesLK", "1VBflYyxBhnDc9uVib98rw"],
target_loudness: 0.2,
min_instrumentalness: 0.4,
max_instrumentalness: 0.9,
}
);
// do something with result
// result.seeds
// result.tracks
```
## <a name="features"></a> Features to implement
- [x] Support Search endpoint
- [x] Support Artists endpoints
- [ ] Support Browse endpoints
- [x] Support Browse endpoints
- [ ] Support Follow endpoints

@@ -195,0 +281,0 @@ - [ ] Support Library endpoints

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc