All files / src/spotify-api api.js

100% Statements 19/19
100% Branches 0/0
100% Functions 4/4
100% Lines 19/19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33      10x   10x 1x 1x 1x 1x 1x     10x 1x   10x 1x 1x 1x 1x 1x 1x         1x     10x 1x  
import Spotify from "spotify-web-api-js";
import { getToken } from "../redux/selectors";
 
const spotifyApi = new Spotify();
 
const apiSearchSpotify = (searchText, args, api) => {
  const { getState } = args;
  const state = getState();
  const token = getToken(state);
  api.setAccessToken(token);
  return api.search(searchText, ["album"]);
};
 
export const apiSearch = (searchText, args) =>
  apiSearchSpotify(searchText, args, spotifyApi);
 
const apiRecommendationsSpotify = (seeds, args, api) => {
  const { getState } = args;
  const state = getState();
  const token = getToken(state);
  api.setAccessToken(token);
  const album = seeds.album;
  const options = {
    seed_artists: [album.artists[0].id],
    seed_genres: [],
    seed_tracks: []
  };
  return api.getRecommendations(options);
};
 
export const apiRecommendations = (seeds, args) =>
  apiRecommendationsSpotify(seeds, args, spotifyApi);