explore-services/portal-2/src/app/services/searchDatacite.service.ts

36 lines
1.4 KiB
TypeScript

import {Injectable} from '@angular/core';
import {Jsonp, URLSearchParams} from '@angular/http';
import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
@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 = OpenaireProperties.getSearchDataciteAPIURL()+'?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 || { };
}
}