forked from PatrickJS/angular-webpack-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGithubService.ts
More file actions
28 lines (22 loc) · 750 Bytes
/
GithubService.ts
File metadata and controls
28 lines (22 loc) · 750 Bytes
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
/// <reference path="../../typings/_custom.d.ts" />
import {provide, Injectable} from 'angular2/angular2';
import {Http} from 'angular2/http';
import * as Rx from '@reactivex/rxjs';
@Injectable()
export class GithubService {
url: string = 'https://api.github.com/search/repositories?q=';
constructor(public http: Http) {
}
/**
* @returns an Observable of repository names
*/
search(query: string): Rx.Observable<any[]> {
return this.http.get(this.url + query)
.map(res => res.json()) // make json
.map(res => res.items) // extract "items" only
.filter(repos => repos); // only if there are results
}
}
export var GITHUB_PROVIDERS: Array<any> = [
provide(GithubService, {useClass: GithubService})
];