35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import {Injectable} from '@angular/core';
|
|
import {Jsonp, URLSearchParams} from '@angular/http';
|
|
import {Http, Response} from '@angular/http';
|
|
import {Observable} from 'rxjs/Observable';
|
|
|
|
@Injectable()
|
|
export class SearchDataciteService {
|
|
constructor(private jsonp: Jsonp, private http: Http) {}
|
|
|
|
searchDataciteResults (term: string, size : number, page : number):any {
|
|
console.info("In search datacite results "+term);
|
|
let url = 'http://search.datacite.org/api?q='+term+'&fl=doi,title,creator,publisher&wt=json&rows='+size+'&start='+(size*(page-1));
|
|
|
|
return this.http.get( url)
|
|
.map(request => <any> request.json().response)
|
|
.do(items => console.log("Datacite Results: total results = "+items['numFound']+" keyword = "+term))
|
|
.catch(this.handleError);
|
|
}
|
|
|
|
|
|
private handleError (error: Response) {
|
|
// in a real world app, we may send the error to some remote logging infrastructure
|
|
// instead of just logging it to the console
|
|
console.error(error);
|
|
return Observable.throw(error || 'Server error');
|
|
}
|
|
private extractData(res: Response) {
|
|
if (res.status < 200 || res.status >= 300) {
|
|
throw new Error('Bad response status: ' + res.status);
|
|
}
|
|
let body = res.json();
|
|
return body.data || { };
|
|
}
|
|
}
|