openaire-library/claims/claim-utils/service/searchCrossref.service.ts

62 lines
2.2 KiB
TypeScript

import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
@Injectable()
export class SearchCrossrefService {
constructor( private http: Http ) {}
searchCrossrefResults (term: string, size : number, page : number, apiUrl:string):any {
let url = apiUrl+'?query='+term+'&rows='+size+'&offset='+(size*(page-1));
let key = url;
return this.http.get(url)
.map(request => <any> request.json().message)
.do(items => console.log("Crossref Results: total results = "+items['total-results']+" keyword = "+term));
//.catch(this.handleError);
}
searchCrossrefByDOIs(DOIs: string[], apiUrl:string):any {
var doisParams = "";
for(var i =0 ;i < DOIs.length; i++){
doisParams+=(doisParams.length > 0?",":"")+'doi:'+DOIs[i];
}
let url = apiUrl+'?filter='+doisParams;
let key = url;
return this.http.get(url)
.map(request => <any> request.json().message)
.do(items => console.log("Crossref Results: total results = "+items['total-results']+" for doi = "+doisParams));
//.catch(this.handleError);
}
searchCrossrefByMultipleDOIs(dois: string[], apiUrl:string):any {
let url = apiUrl+'?filter=doi:';
for(var i=0; i<dois.length; i++){
url=url+(url.length==0?'':',')+'doi:'+dois[i];
}
url = apiUrl+'?filter='+url;
let key = url;
return this.http.get(url)
.map(request => <any> request.json().message)
.do(items => console.log("Crossref Results: total results = "+items['total-results']));
//.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.log(error);
return Observable.throw(error || 'Server error');
}
}