Added API and improved form
This commit is contained in:
parent
66b3cd6ea4
commit
830ecbffca
5 changed files with 107 additions and 21 deletions
48
src/app/providers/api-service.ts
Normal file
48
src/app/providers/api-service.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Http } from '@angular/http';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import 'rxjs/add/operator/map';
|
||||
|
||||
|
||||
/* this provider handles the interaction between server and client */
|
||||
|
||||
@Injectable()
|
||||
export class ApiService {
|
||||
private apiUrl = 'https://dev.app.peartrade.org/api';
|
||||
private sessionKey: string;
|
||||
constructor(
|
||||
private http: Http,
|
||||
) {}
|
||||
|
||||
public getAgeRanges() {
|
||||
return this.http.get(
|
||||
this.apiUrl + '/info/ages'
|
||||
).map( res => res.json() );
|
||||
}
|
||||
|
||||
public register(data) {
|
||||
return this.http.post(
|
||||
this.apiUrl + '/register',
|
||||
data
|
||||
).map( response => response.json() );
|
||||
}
|
||||
|
||||
public login(data) {
|
||||
let login_event = this.http.post(
|
||||
this.apiUrl + '/login',
|
||||
data
|
||||
).map( response => response.json() );
|
||||
login_event.subscribe(
|
||||
result => { this.sessionKey = result.session_key }
|
||||
);
|
||||
return login_event;
|
||||
}
|
||||
|
||||
public search(data) {
|
||||
data.session_key = this.sessionKey;
|
||||
return this.http.post(
|
||||
this.apiUrl + '/search',
|
||||
data
|
||||
).map( response => response.json() );
|
||||
}
|
||||
}
|
Reference in a new issue