-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ab7998
commit 6e3252e
Showing
4 changed files
with
43 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import { searchAlbums } from '../src/main'; | ||
/* to run: babel-node album.js */ | ||
import SpotifyWrapper from '../src/index'; | ||
|
||
global.fetch = require('node-fetch'); | ||
|
||
const albums = searchAlbums('Incubus'); | ||
const spotify = new SpotifyWrapper({ | ||
token: 'BQDsad0YtusZVbU6SW3h2Og2jhaPoWul52J5DU6T6wAkf839-Fnu6_qoy7hS0twLB1dxgq28z1K1s3nd3MClQ5laAFEPEXMnl6VaL0lS6_7hwA5DKOoi0fQyW6BdkrEw7_cW7O5CzDdzQnI4FuA', | ||
}); | ||
|
||
const albums = spotify.search.albums('Charlie Brown Jr'); | ||
|
||
albums.then(data => data.albums.items.map(item => console.log(item.name))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
import { API_URL, HEADERS } from './config'; | ||
import toJSON from './utils'; | ||
/* global fetch */ | ||
function searcher(type, query) { | ||
return this.request(`${this.apiURL}/search?q=${query}&type=${type}`); | ||
} | ||
|
||
export const search = (query, type) => | ||
fetch(`${API_URL}/search?q=${query}&type=${type}`, HEADERS) | ||
.then(toJSON); | ||
|
||
export const searchArtists = query => search(query, 'artist'); | ||
|
||
export const searchAlbums = query => search(query, 'album'); | ||
export const searchTracks = query => search(query, 'track'); | ||
export const searchPlaylists = query => search(query, 'playlist'); | ||
export default function search() { | ||
return { | ||
artists: searcher.bind(this, 'artist'), | ||
albums: searcher.bind(this, 'album'), | ||
tracks: searcher.bind(this, 'track'), | ||
playlists: searcher.bind(this, 'playlist'), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters