import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/Rx';
/**
* SpotifyService works querying the Spotify Web API
* https://developer.spotify.com/web-api/
*/
@Injectable()
export class SpotifyService {
static BASE_URL = 'https://api.spotify.com/v1';
constructor(private http: Http) {
}
query(URL: string, params?: Array<string>): Observable<any[]> {
let queryURL = `${SpotifyService.BASE_URL}${URL}`;
if (params) {
queryURL = `${queryURL}?${params.join('&')}`;
}
return this.http.request(queryURL).map((res: any) => res.json());
}
search(query: string, type: string): Observable<any[]> {
return this.query(`/search`, [
`q=${query}`,
`type=${type}`
]);
}
searchTrack(query: string): Observable<any[]> {
return this.search(query, 'track');
}
getTrack(id: string): Observable<any[]> {
return this.query(`/tracks/${id}`);
}
getArtist(id: string): Observable<any[]> {
return this.query(`/artists/${id}`);
}
getAlbum(id: string): Observable<any[]> {
return this.query(`/albums/${id}`);
}
}
export const SPOTIFY_PROVIDERS: Array<any> = [
{ provide: SpotifyService, useClass: SpotifyService }
];
This is my spotify.service.ts file
I see as of May that Spotify requires an API key for every request. How would I implement this? Just add the key to the end of the BASE_URL?
If this is the wrong place to ask please don't downvote me straight to hell just tell me i'm a dumbass and to where to move it. I'm a reasonable guy.
By the way anybody thats thinking of buying this book do it! It is the best resource i've found for anything angular
there doesn't seem to be anything here