Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
Merge pull request #462 from christianvogt/httpclient
Browse files Browse the repository at this point in the history
fix(httpclient): move to HttpClient in preparation for ng6
  • Loading branch information
corinnekrych authored Aug 24, 2018
2 parents c71a964 + 3a55bdc commit 2c5d8d2
Show file tree
Hide file tree
Showing 21 changed files with 477 additions and 552 deletions.
54 changes: 25 additions & 29 deletions src/app/stack/card-details/card-details.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,38 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Http, ConnectionBackend, RequestOptions, BaseRequestOptions } from '@angular/http';
import { HttpClientModule } from '@angular/common/http';
import { TabsModule } from 'ngx-bootstrap';

import { CardDetailsComponent } from './card-details.component';
import { ReportInformationModule } from './report-information/report-information.module';

const imports = [
TabsModule,
ReportInformationModule
TabsModule,
ReportInformationModule,
HttpClientModule
];

describe ('CardDetailsComponent', () => {
let component: CardDetailsComponent;
let fixture: ComponentFixture<CardDetailsComponent>;
describe('CardDetailsComponent', () => {
let component: CardDetailsComponent;
let fixture: ComponentFixture<CardDetailsComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
...imports
],
declarations: [
CardDetailsComponent
],
providers: [
Http,
ConnectionBackend,
{ provide: RequestOptions, useClass: BaseRequestOptions }
]
}).compileComponents();
}));
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
...imports
],
declarations: [
CardDetailsComponent
]
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(CardDetailsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
beforeEach(() => {
fixture = TestBed.createComponent(CardDetailsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Http, ConnectionBackend, RequestOptions, BaseRequestOptions } from '@angular/http';
import { HttpClientModule } from '@angular/common/http';

import { TooltipModule } from 'ngx-bootstrap';

Expand All @@ -16,7 +16,8 @@ const imports = [
TooltipModule,
ProgressMeterModule,
ComponentFeedbackModule,
ToastNotificationModule
ToastNotificationModule,
HttpClientModule
];

describe ('ComponentDetailsComponent', () => {
Expand All @@ -32,11 +33,6 @@ describe ('ComponentDetailsComponent', () => {
ComponentSnippetComponent,
ComponentInformationComponent,
ComponentDetailsComponent
],
providers: [
Http,
ConnectionBackend,
{ provide: RequestOptions, useClass: BaseRequestOptions }
]
}).compileComponents();
}));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Http, ConnectionBackend, RequestOptions, BaseRequestOptions } from '@angular/http';
import { HttpClientModule } from '@angular/common/http';

import { ComponentInformationComponent } from './component-information.component';
import { AddWorkFlowService } from '../../stack-details/add-work-flow.service';
Expand Down Expand Up @@ -84,18 +84,16 @@ describe ('ComponentInformationComponent', () => {
ProgressMeterModule,
ComponentFeedbackModule,
ComponentFeedbackModule,
ToastNotificationModule
ToastNotificationModule,
HttpClientModule
],
declarations: [
ComponentInformationComponent,
ComponentSnippetComponent
],
providers: [
Http,
Contexts,
AddWorkFlowService,
ConnectionBackend,
{ provide: RequestOptions, useClass: BaseRequestOptions },
witApiUrlProvider,
ApiLocatorService,
authApiUrlProvider,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Http, ConnectionBackend, RequestOptions, BaseRequestOptions } from '@angular/http';
import { HttpClientModule } from '@angular/common/http';

import {
MCardDetails
MCardDetails
} from '../../../models/ui.model';

import { NoDataComponent } from './no-data.component';

const components = [
NoDataComponent
NoDataComponent
];

describe ('NoDataComponent', () => {
let component: NoDataComponent;
let fixture: ComponentFixture<NoDataComponent>;
describe('NoDataComponent', () => {
let component: NoDataComponent;
let fixture: ComponentFixture<NoDataComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
...components
],
providers: [
Http,
ConnectionBackend,
{ provide: RequestOptions, useClass: BaseRequestOptions }
]
}).compileComponents();
}));
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
...components
],
imports: [
HttpClientModule
]
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(NoDataComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
beforeEach(() => {
fixture = TestBed.createComponent(NoDataComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Http, ConnectionBackend, RequestOptions, BaseRequestOptions } from '@angular/http';
import { HttpClientModule } from '@angular/common/http';

import { TooltipModule } from 'ngx-bootstrap';

Expand All @@ -19,48 +19,46 @@ import { ReportInformationModule } from './report-information.module';
import { ToastNotificationModule } from '../../toast-notification/toast-notification.module';

const components = [
ComponentSnippetComponent,
ComponentInformationComponent,
ComponentDetailsComponent,
ReportInformationComponent,
NoDataComponent
ComponentSnippetComponent,
ComponentInformationComponent,
ComponentDetailsComponent,
ReportInformationComponent,
NoDataComponent
];

const imports = [
TooltipModule.forRoot(),
ProgressMeterModule,
ComponentFeedbackModule,
ToastNotificationModule
TooltipModule.forRoot(),
ProgressMeterModule,
ComponentFeedbackModule,
ToastNotificationModule,
HttpClientModule
];

describe ('ReportInformationComponent', () => {
let component: ReportInformationComponent;
let fixture: ComponentFixture<ReportInformationComponent>;
describe('ReportInformationComponent', () => {
let component: ReportInformationComponent;
let fixture: ComponentFixture<ReportInformationComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
...imports
],
declarations: [
...components
],
providers: [
Http,
AddWorkFlowService,
ConnectionBackend,
{ provide: RequestOptions, useClass: BaseRequestOptions }
]
}).compileComponents();
}));
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
...imports
],
declarations: [
...components
],
providers: [
AddWorkFlowService
]
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ReportInformationComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
beforeEach(() => {
fixture = TestBed.createComponent(ReportInformationComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
67 changes: 32 additions & 35 deletions src/app/stack/feedback/feedback.service.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,46 @@
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { HttpErrorResponse, HttpHeaders, HttpClient, HttpResponse } from '@angular/common/http';
import { AuthenticationService } from 'ngx-login-client';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/operators/map';

@Injectable()
export class FeedbackService {
private headers: Headers = new Headers({'Content-Type': 'application/json'});
constructor(
private http: Http,
private auth: AuthenticationService) {
if (this.auth.getToken() !== null) {
this.headers.set('Authorization', 'Bearer ' + this.auth.getToken());
}
}
private headers: HttpHeaders = new HttpHeaders({'Content-Type': 'application/json'});
constructor(
private http: HttpClient,
private auth: AuthenticationService) {
if (this.auth.getToken() !== null) {
this.headers.set('Authorization', 'Bearer ' + this.auth.getToken());
}
}

public submit(feedback: any): Observable<any> {
let url: string = 'https://recommender.api.openshift.io/api/v1/user-feedback';
let options: RequestOptions = new RequestOptions({
headers: this.headers
});
public submit(feedback: any): Observable<any> {
let url: string = 'https://recommender.api.openshift.io/api/v1/user-feedback';
let options = {
headers: this.headers
};

return this.http
.post(url, JSON.stringify(feedback), options)
.map(this.extractData)
.catch(this.handleError);
}
return this.http
.post<any>(url, JSON.stringify(feedback), options)
.map(this.extractData)
.catch(this.handleError);
}

private extractData(res: Response) {
let body = res.json();
return body || {};
}
private extractData(body: any): any {
return body || {};
}

private handleError(error: Response | any) {
// In a real world app, we might use a remote logging infrastructure
let errMsg: string;
if (error instanceof Response) {
const body = error.json() || '';
const err = body.error || JSON.stringify(body);
errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
} else {
errMsg = error.message ? error.message : error.toString();
}
console.error(errMsg);
return Observable.throw(errMsg);
private handleError(error: HttpErrorResponse) {
let errMsg: string;
if (error.error instanceof ErrorEvent) {
errMsg = error.error.message || error.error.toString();
} else {
const body = error.error || '';
const err = body.error || JSON.stringify(body);
errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
}
return Observable.throw(errMsg);
}
}
Loading

0 comments on commit 2c5d8d2

Please sign in to comment.