Bib-CrossRef
view release on metacpan or search on metacpan
lib/Bib/CrossRef.pm view on Meta::CPAN
# given free format text, use crossref.org to try to convert into a paper reference and doi
my ($self, $cites) = @_;
my $cites_clean = $cites;
# tidy up string, escape nasty characters etc.
$cites_clean =~ s/\s+/+/g; #$cites_clean = uri_escape_utf8($cites_clean);
#print $cites_clean;
# crossref like us to give a mailto email when making request so they can get in touch if the script is generating errors,
# feel free to change the email address here to something more appropriate
# change to using /works API instead of /dois API
my $req = HTTP::Request->new(GET => 'https://api.crossref.org/works?mailto=doug@leith.ie&rows=1&query='.$cites_clean);
my $ua = LWP::UserAgent->new;
my $res = $ua->request($req);
if ($res->is_success) {
# extract json response
my $json = decode_json($res->decoded_content);
#use Data::Dumper;
#print Dumper($json->{'message'}{'items'});
my $ref={};
# keep a record of the query string we used
$ref->{'query'} = $cites;
lib/Bib/CrossRef.pm view on Meta::CPAN
$self->{ref} = $ref;
} else {
$self->_err("Problem with search.crossref.org: ".$res->status_line);
}
}
sub parse_doi {
# given a DOI, use unixref interface to convert into a full citation
my ($self, $doi) = @_;
my $req = HTTP::Request->new(GET =>'http://dx.doi.org/'.$doi,['Accept' =>'application/vnd.crossref.unixsd+xml']);
my $ua = LWP::UserAgent->new;
my $res = $ua->request($req);
if ($res->is_success) {
# now parse the xml
my $xs = XML::Simple->new();
my $data = $xs->XMLin($res->decoded_content);
my $cite = $data->{'query_result'}->{'body'}->{'query'}->{'doi_record'}->{'crossref'};
my $cc = undef;
if (exists($cite->{'conference'})) {
$self->_setgenre('proceeding');
( run in 0.458 second using v1.01-cache-2.11-cpan-de7293f3b23 )