Created
January 27, 2018 17:41
-
-
Save Abiwax/46b920172cb372920f5cf9ff610d46e5 to your computer and use it in GitHub Desktop.
APICallService
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
places_url = '/googleplaces'; | |
matrix_url = '/distancematrix'; | |
constructor(public http: Http) { | |
} | |
// make a http call to careerjet public API and return and return an observable | |
getCareerJetResults(search, location): Observable<Job[]> { | |
const formData: FormData = new FormData(); | |
formData.append('keywords', search); | |
formData.append('location', location); | |
return this.http.post(this.career_jet_url, formData).map((response: Response) => <Job[]> response.json().jobs); | |
} | |
// make a http call to google's distance matrix API and return and return an observable | |
getDistance(address1, address2): Observable<any> { | |
const address_params = new URLSearchParams(); | |
address_params.append('origins', address1); | |
address_params.append('destinations', address2); | |
address_params.append('key', this.google_api_key); | |
const options = new RequestOptions({ | |
search: address_params | |
}); | |
return this.http.get(this.matrix_url, options).map((response: Response) => response.json()); | |
} | |
// make a http call to google's places matrix API and return and return an observable | |
getAddressLatLng(address): Observable<any> { | |
const address_params = new URLSearchParams(); | |
address_params.append('query', address); | |
address_params.append('key', this.google_api_key); | |
const options = new RequestOptions({ | |
search: address_params | |
}); | |
return this.http.get(this.places_url, options).map((response: Response) => response.json().results); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment