Biblio-Refbase
view release on metacpan or search on metacpan
}
else {
print 'Nothing found!';
}
}
else {
print 'An error occurred: ', $response->status_line;
}
print "\n\n";
$response = $refbase->upload(
user => 'user@refbase.net', # Switch user for
password => 'user', # this request.
show => 1, # Return records
format => 'BibTeX', # in BibTeX format.
source_ids => [ # Upload records
'arXiv:cs/0106057', # from arXiv.org
'arXiv:cond-mat/0210361', # via source IDs.
],
);
if ($response->is_success) {
print 'Number of records imported: ', $response->rows , "\n";
print 'ID range of records: ' , $response->records, "\n";
print "Records:\n\n", $response->content;
}
# Upload records by supplying a string of content:
# $response = $refbase->upload( content => $content );
INSTALLATION
To install this module, run the following commands:
perl Makefile.PL
make
make test
make install
lib/Biblio/Refbase.pm view on Meta::CPAN
my $search = $self->_search_args(\%args);
if (%args) {
croak q{Unknown arguments provided to 'search' method:}
. join("\n ", '', sort keys %args) . "\n";
}
return $self->_search($account, $search);
}
sub upload {
my $self = shift;
unshift @_, 'content' if @_ % 2;
my %args = @_;
my $account = $self->_account_args(\%args);
my $upload = $self->_upload_args(\%args);
my $show = delete $args{show};
$show = %args unless defined $show;
my $search = $self->_search_args(\%args);
if (%args) {
croak q{Unknown arguments provided to 'upload' method:}
. join("\n ", '', sort keys %args) . "\n";
}
my $url = $account->{url} . REFBASE_IMPORT;
my $request = $upload->{uploadFile}
? POST $url, Content_Type => 'form-data', Content => $upload
: POST $url, $upload;
my $response = $self->_request($account, $request);
unless ($response->is_error) {
if (defined(my $location = $response->header('location'))) {
if ($location =~ /^(${\REFBASE_SHOW}\?)/o) {
my $q = URI->new($location)->query_form_hash;
my ($rows) = ($q->{headerMsg} || '') =~ /(\d+)/;
my $records = $q->{records} || '';
if ($show) {
lib/Biblio/Refbase.pm view on Meta::CPAN
$param{showquery} = 1;
}
if (defined(my $showlinks = delete $args->{showLinks})) {
$param{showLinks} = 0 if $showlinks eq '0';
}
$param{client} = $self->{_client};
return \%param;
}
# setup upload parameters from arguments hash, dynamic and static defaults
sub _upload_args {
my ($self, $args) = @_;
my %param;
if (defined(my $content = delete $args->{content})) {
$param{uploadFile} = [ undef, 'filename', Content => $content ];
$param{formType} = 'import';
}
elsif (defined(my $source_ids = delete $args->{source_ids})) {
$param{sourceIDs} = ref $source_ids eq 'ARRAY'
? join ' ', @$source_ids
: $source_ids;
$param{formType} = 'importID';
}
else {
croak q{upload requires either record content supplied by parameter 'content' or }
. q{a list of record IDs in parameter 'source_ids'};
}
if (delete $args->{skipbad}) {
$param{skipBadRecords} = 1;
}
if (defined(my $only = delete $args->{only})) {
$param{importRecords} = $only;
$param{importRecordsRadio} = 'only';
}
$param{client} = $self->{_client};
lib/Biblio/Refbase.pm view on Meta::CPAN
}
else {
print 'Nothing found!';
}
}
else {
print 'An error occurred: ', $response->status_line;
}
print "\n\n";
$response = $refbase->upload(
user => 'user@refbase.net', # Switch user for
password => 'user', # this request.
show => 1, # Return records
format => 'BibTeX', # in BibTeX format.
source_ids => [ # Upload records
'arXiv:cs/0106057', # from arXiv.org
'arXiv:cond-mat/0210361', # via source IDs.
],
);
if ($response->is_success) {
print 'Number of records imported: ', $response->rows , "\n";
print 'ID range of records: ' , $response->records, "\n";
print "Records:\n\n", $response->content;
}
# Upload records by supplying a string of content:
# $response = $refbase->upload( content => $content );
=head1 DESCRIPTION
Biblio::Refbase is an object-oriented interface to refbase
Web Reference Database sites.
refbase (L<http://www.refbase.net/>) is a web-based bibliographic manager
which can import and export references in various formats (including BibTeX,
Endnote, MODS and OpenOffice).
lib/Biblio/Refbase.pm view on Meta::CPAN
Special output options for ASCII and HTML formats:
showquery show SQL statement if set to 1 (ASCII only)
showlinks don't show links column if set to 0 (HTML only)
view view type (HTML only): 'Web', 'Print' or 'Mobile'
Refer to L<"EXAMPLES"> section for a short tutorial and working code
snippets.
=item $response = $refbase->upload(%args);
Imports/uploads records to a refbase database.
As with the C<search> method, all instance-wide configured values can be
overridden on a per-request basis (except 'ua'). See C<search> method and
L<"ACCESSORS"> section.
The C<upload> method requires one of these two keys to be present in the
arguments hash:
content a string containing records in a format known by refbase
source_ids a string or list of record IDs recognized by refbase
The 'source_ids' can be supplied either as a string of IDs separated by
blanks or as a reference to an array. If both keys are present, 'content'
will be used and 'source_ids' will be ignored.
Optional keys are:
lib/Biblio/Refbase.pm view on Meta::CPAN
only record numbers/range to be imported from the source
show immediately search for the records imported by this call
if set to a true value
If 'show' is set to a true value or any search field parameters (see
C<search> method) are present, the method call will perform a search request
after importing. The search request will automatically set the record selection
to the new IDs of the freshly imported records (overridable by 'records' key)
and the maximum number of records to the number of records that have
been imported (overridable by 'rows' key). I.e. if 'show' is true and no
search field parameters are set, the C<upload> method will return all
imported records (in the desired/default format and style).
Refer to L<"EXAMPLES"> section for a short tutorial and working code
snippets.
=item $response = $refbase->upload($content, %args);
If the constructor is called with an uneven arguments list the first
element will be taken as 'content'.
=item $boolean = $refbase->ping;
Checks if configured base URL is accessible.
=back
lib/Biblio/Refbase.pm view on Meta::CPAN
=item @styles = $refbase->styles;
=item @styles = Biblio::Refbase->styles;
Returns a list of available citation styles known by this module.
=back
=head1 RESPONSE ACCESSOR METHODS
The C<search> and C<upload> methods return C<$response> objects.
A C<$response> object is a formerly instance of C<HTTP::Response>
that has been re-blessed into the package C<Biblio::Refbase::Response>.
This package subclasses C<HTTP::Response> and extends it by three fields
and the corresponding accessors. No methods are overridden.
=over 4
=item $response->hits;
Indicates the success of a C<search> request:
1 search has found some records
0 search has found nothing
undef search has failed
=item $response->rows;
Returns the number of records that have been imported by an C<upload>
request.
=item $response->records;
Returns the record ID range of the imported records, i.e. the first ID and the
last ID of the new records (joined by the minus sign). Or a single ID, if only
one record has been imported.
=back
t/04-methods.t view on Meta::CPAN
skip NO_INTERNET, 2 unless $internet;
my $response = $refbase->search( user => 'let_me_fail' );
isa_ok $response, 'Biblio::Refbase::Response';
is $response->code, HTTP_UNAUTHORIZED, 'status code is UNAUTHORIZED';
}
#
# upload
#
can_ok $refbase, 'upload';
eval { $refbase->upload };
like $@, qr/^upload requires/, 'upload failed as expected due to missing argument';
eval { $refbase->upload( 'baz', foo => 'bar' ) };
like $@, qr/^Unknown arguments/, 'upload failed as expected due to unknown arguments';
eval { $refbase->upload( content => 'baz', foo => 'bar' ) };
like $@, qr/^Unknown arguments/, 'upload failed as expected due to unknown arguments';
eval { $refbase->upload( source_ids => 'baz', foo => 'bar' ) };
like $@, qr/^Unknown arguments/, 'upload failed as expected due to unknown arguments';
( run in 0.814 second using v1.01-cache-2.11-cpan-b16cb0d3907 )