-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathdocs.service.ts
More file actions
56 lines (48 loc) · 1.67 KB
/
docs.service.ts
File metadata and controls
56 lines (48 loc) · 1.67 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { forwardRef, Inject, Injectable, LOCALE_ID } from '@angular/core'
import {Http, Response} from '@angular/http';
import {Observable, throwError as observableThrowError, of} from 'rxjs';
import {map, catchError} from 'rxjs/operators';
import { environment } from '../../../../environments'
@Injectable()
export class DocsService {
url: string
path: string
constructor(
private http:Http,
@Inject(forwardRef(() => LOCALE_ID)) private locale: string,
) {
const host:string = (<any>environment).faas ? environment.faasHost : environment.host
this.path = this.locale === 'en-US' ? '/en-US' : ''
this.url = host + this.path
}
getCatalog(): Observable<any> {
return this.http.get(`${this.url}/catalog.json`).pipe(
catchError(err => this.handleResponseError(err)),
map((res: Response) => {
if (!res.text()) { return null; }
return res.json();
}));
}
getDocuments(documentType: string): Observable<any> {
return this.http.get(`${this.url}/${documentType}.json`).pipe(
catchError(err => this.handleResponseError(err)),
map((res: Response) => {
if (!res.text()) { return null; }
return res.json();
}));
}
getVersion(): Observable<any> {
return of(environment.version || '1.0.0')
}
getChangeLogs(): Observable<any> {
return this.http.get(`${this.url}/changelog.json`).pipe(
catchError(err => this.handleResponseError(err)),
map((res: Response) => {
if (!res.text()) { return null; }
return res.json();
}));
}
private handleResponseError(error: Response): Observable<never> {
return observableThrowError(error.json());
}
}