diff --git a/chapter 5 - http/simple-http/src/app/you-tube-search/search-result.model.ts b/chapter 5 - http/simple-http/src/app/you-tube-search/search-result.model.ts deleted file mode 100644 index 6998feb..0000000 --- a/chapter 5 - http/simple-http/src/app/you-tube-search/search-result.model.ts +++ /dev/null @@ -1,15 +0,0 @@ -export class SearchResult { - id: string; - title: string; - description: string; - thumbnailUrl: string; - videoUrl: string - - constructor(obj?: any) { - this.id = obj && obj.id || null; - this.title = obj && obj.title || null; - this.description = obj && obj.description || null; - this.thumbnailUrl = obj && obj.thumbnailUrl || null; - this.videoUrl = obj && obj.videoUrl || '`https://www.youtube.com/watch?v=${this.id}`'; - } -} diff --git a/chapter 5 - http/simple-http/src/app/you-tube-search/you-tube-search.component.css b/chapter 5 - http/simple-http/src/app/you-tube-search/you-tube-search.component.css deleted file mode 100644 index e69de29..0000000 diff --git a/chapter 5 - http/simple-http/src/app/you-tube-search/you-tube-search.component.html b/chapter 5 - http/simple-http/src/app/you-tube-search/you-tube-search.component.html deleted file mode 100644 index f28095d..0000000 --- a/chapter 5 - http/simple-http/src/app/you-tube-search/you-tube-search.component.html +++ /dev/null @@ -1,3 +0,0 @@ -

- you-tube-search works! -

diff --git a/chapter 5 - http/simple-http/src/app/you-tube-search/you-tube-search.component.spec.ts b/chapter 5 - http/simple-http/src/app/you-tube-search/you-tube-search.component.spec.ts deleted file mode 100644 index 62659b6..0000000 --- a/chapter 5 - http/simple-http/src/app/you-tube-search/you-tube-search.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - -import { YouTubeSearchComponent } from './you-tube-search.component'; - -describe('YouTubeSearchComponent', () => { - let component: YouTubeSearchComponent; - let fixture: ComponentFixture; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ YouTubeSearchComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(YouTubeSearchComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/chapter 5 - http/simple-http/src/app/you-tube-search/you-tube-search.component.ts b/chapter 5 - http/simple-http/src/app/you-tube-search/you-tube-search.component.ts deleted file mode 100644 index c3c4e96..0000000 --- a/chapter 5 - http/simple-http/src/app/you-tube-search/you-tube-search.component.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Component, OnInit } from '@angular/core'; -import {SearchResult} from "./search-result.model"; -import {YouTubeSearchService} from "./you-tube-search.service"; - -@Component({ - selector: 'app-you-tube-search', - template: ` - - ` -}) -export class YouTubeSearchComponent implements OnInit { - @Output() loading: EventEmitter = new EventEmitter(); - @Output() results: EventEmitter = new EventEmitter(); - - constructor(private youtube: YouTubeSearchService, - private el: ElementRef) { } - - ngOnInit() { - // convert the `keyup` event into an observable stream - Observable.fromEvent(this.el.nativeElement, 'keyup'); - } -} diff --git a/chapter 5 - http/simple-http/src/app/you-tube-search/you-tube-search.injectables.ts b/chapter 5 - http/simple-http/src/app/you-tube-search/you-tube-search.injectables.ts deleted file mode 100644 index e971030..0000000 --- a/chapter 5 - http/simple-http/src/app/you-tube-search/you-tube-search.injectables.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { - YouTubeSearchService, - YOUTUBE_API_KEY, - YOUTUBE_API_URL -} from "./you-tube-search.service"; - -export const youtTubeSearchInjectables: Array = [ - {provide: YouTubeSearchService, useClass: YouTubeSearchService}, - {provide: YOUTUBE_API_KEY, useValue: YOUTUBE_API_KEY}, - {provide: YOUTUBE_API_URL, useValue: YOUTUBE_API_URL} -]; diff --git a/chapter 5 - http/simple-http/src/app/you-tube-search/you-tube-search.service.ts b/chapter 5 - http/simple-http/src/app/you-tube-search/you-tube-search.service.ts deleted file mode 100644 index 61b1288..0000000 --- a/chapter 5 - http/simple-http/src/app/you-tube-search/you-tube-search.service.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { Injectable, Inject } from '@angular/core'; -import { - HttpClient, - HttpRequest, - HttpHeaders -} from '@angular/common/http'; - -import { Observable } from 'rxjs/Rx'; -import { SearchResult } from "./search-result.model"; - -/* - This API key may or may not work for you. Your best bet is to issue your own - API key by following these instructions: - https://developers.google.com/youtube/registering_an_application#Create_API_Keys - Here I've used a **server key** and make sure you enable YouTube. - Note that if you do use this API key, it will only work if the URL in - your browser is "localhost" -*/ -// TODO -export const YOUTUBE_API_KEY = - ''; -export const YOUTUBE_API_URL = - 'https://www.googleapis.com/youtube/v3/search'; - -@Injectable() -export class YouTubeSearchService { - constructor( - private http: HttpClient, - @Inject(YOUTUBE_API_KEY) private apiKey: string, - @Inject(YOUTUBE_API_URL) private apiUrl: string) {} - - search(query: string): Observable { - const params: string = [ - `q=${query}`, - `key=${this.apiKey}`, - `part=snippet`, - `type=video`, - `maxResults=10`, - ].join('&'); - - const queryUrl = `${this.apiUrl}?${params}`; - return this.http.get(queryUrl).map(response => { - return response['items'].map(item => { - return new SearchResult({ - id: item.id.videoId, - title: item.snippet.title, - description: item.snippet.description, - thumbnailUrl: item.snippet.thumbnails.high.url - }); - }); - }); - } -}