import { Injectable } from '@angular/core' ; import { HttpParams } from '@angular/common/http' ; import { Observable } from 'rxjs' ; import { map } from 'rxjs/operators' ; import { CachedHttp } from 'angular-async-cache' ; import { Show , Episode } from '../../interfaces' ; @ Injectable ( ) export class TVMaze { static BASE_URL = 'https://api.tvmaze.com/' ; constructor ( private http ) { } search ( query ) { return this . http . get ( `${ TVMaze . BASE_URL }search/shows` , { params : new HttpParams ( ) . set ( 'q' , query ) } ) . pipe ( map ( ( shows ) => shows . map ( ( show ) => show . show ) ) ) ; } getEpisodes ( id ) { return this . http . get ( `${ TVMaze . BASE_URL }shows/${ id }/episodes` ) ; } }