|
1 | | -import { Injectable } from '@angular/core'; |
| 1 | +import { Injectable, Inject } from '@angular/core'; |
2 | 2 | import { Http, Response } from '@angular/http'; |
3 | 3 |
|
4 | 4 | import { Observable } from 'rxjs/Observable'; |
5 | 5 | import 'rxjs/add/operator/catch'; |
6 | 6 | import 'rxjs/add/operator/map'; |
7 | 7 |
|
| 8 | +import { WIT_API_URL } from 'ngx-fabric8-wit'; |
| 9 | + |
8 | 10 | @Injectable() |
9 | 11 | export class StackAnalysesService { |
10 | 12 |
|
11 | | - private stackAnalysesUrl; |
| 13 | + private stackAnalysesUrl: string = ''; |
| 14 | + |
| 15 | + private recommenderString: string = 'recommender'; |
| 16 | + private doubleSlash: string = '//'; |
| 17 | + private dot: string = '.'; |
| 18 | + private singleSlash: string = '/'; |
| 19 | + private v1Extension: string = 'v1'; |
12 | 20 |
|
13 | 21 | constructor( |
14 | 22 | private http: Http, |
| 23 | + @Inject(WIT_API_URL) apiUrl: string, |
15 | 24 | ) { |
16 | | - this.stackAnalysesUrl = 'http://recommender.api.prod-preview.openshift.io/api/v1/'; |
| 25 | + if(process && process.env && process.env.FABRIC8_RECOMMENDER_API) { |
| 26 | + this.stackAnalysesUrl = process.env.FABRIC8_RECOMMENDER_API; |
| 27 | + } else { |
| 28 | + if(apiUrl) { |
| 29 | + this.stackAnalysesUrl = apiUrl.replace(this.doubleSlash, this.doubleSlash + this.recommenderString + this.dot); |
| 30 | + let len: number = this.stackAnalysesUrl.length; |
| 31 | + if(this.stackAnalysesUrl[len - 1] !== this.singleSlash) { |
| 32 | + this.stackAnalysesUrl += this.singleSlash; |
| 33 | + } |
| 34 | + this.stackAnalysesUrl += this.v1Extension + this.singleSlash; |
| 35 | + } |
| 36 | + } |
17 | 37 | } |
18 | 38 |
|
19 | 39 | getStackAnalyses(id: string): Observable<any> { |
|
0 commit comments