Catmandu-Adlib
view release on metacpan or search on metacpan
NAME
Catmandu::Adlib - Catmandu interface to Adlib
<http://www.adlibsoft.nl/>
SYNOPSIS
# From the command line
catmandu export Adlib to YAML --id 1234 --endpoint http://test2.adlibsoft.com --username foo --password bar --database collect.inf
# From a Catmandu Fix
lookup_in_store(
object_priref,
Adlib,
endpoint: http://test2.adlibsoft.com,
username: foo,
password: bar,
database: collect.inf
)
MODULES
Catmandu::Store::Adlib
Catmandu::Adlib::API
lib/Catmandu/Adlib.pm view on Meta::CPAN
=encoding utf-8
=head1 NAME
Catmandu::Adlib - Catmandu interface to L<Adlib|http://www.adlibsoft.nl/>
=head1 SYNOPSIS
# From the command line
catmandu export Adlib to YAML --id 1234 --endpoint http://test2.adlibsoft.com --username foo --password bar --database collect.inf
# From a Catmandu Fix
lookup_in_store(
object_priref,
Adlib,
endpoint: http://test2.adlibsoft.com,
username: foo,
password: bar,
database: collect.inf
)
=head1 MODULES
=over
=item L<Catmandu::Store::Adlib>
lib/Catmandu/Adlib/API.pm view on Meta::CPAN
use Catmandu::Sane;
use Moo;
use JSON;
use Catmandu::Adlib::API::Login;
use Catmandu::Adlib::API::QueryBuilder;
has username => (is => 'ro', required => 1);
has password => (is => 'ro', required => 1);
has endpoint => (is => 'ro', required => 1);
has database => (is => 'ro', required => 1);
has ua => (is => 'lazy');
has qb => (is => 'lazy');
sub _build_ua {
my $self = shift;
return Catmandu::Adlib::API::Login->new(
username => $self->username,
password => $self->password
lib/Catmandu/Adlib/API.pm view on Meta::CPAN
});
return {};
}
my $json = decode_json($response->decoded_content);
# If there are multiple results for the same object_id, I'm gonna turn violent.
return $self->get_by_priref($self->get_priref($json->{'adlibXML'}->{'recordList'}->{'record'}->[0]));
}
sub get_by_priref {
my ($self, $priref) = @_;
my $url = sprintf('%s/%s', $self->endpoint, $self->qb->priref($priref));
my $response = $self->ua->get($url);
if ($response->is_success) {
# It's XML - is it already structured? TODO: see
return $response->decoded_content;
} elsif ($response->code == 404) {
return {};
} else {
Catmandu::HTTPError->throw({
code => $response->code,
message => $response->status_line,
lib/Catmandu/Adlib/API.pm view on Meta::CPAN
request_headers => [],
request_body => $response->request->decoded_content,
response_headers => [],
response_body => $response->decoded_content,
});
}
}
sub by_object_id {
my ($self, $id) = @_;
my $url = sprintf('%s/%s', $self->endpoint, $self->qb->object_id($id));
my $response = $self->ua->get($url);
return $response;
}
sub add {
my ($self, $data) = @_;
Catmandu::NotImplemented->throw(
message => 'Adding items is not supported.'
);
}
lib/Catmandu/Adlib/API.pm view on Meta::CPAN
sub delete {
my ($self, $id) = @_;
Catmandu::NotImplemented->throw(
message => 'Deleting items is not supported.'
);
}
sub list {
my ($self, $start) = @_;
my $url = sprintf('%s/%s', $self->endpoint, $self->qb->all());
if (defined($start)) {
$url = sprintf('%s&startfrom=%s', $url, $start);
} else {
$url = sprintf('%s&startfrom=1', $url);
}
warn $url;
my $response = $self->ua->get($url);
if ($response->is_success) {
return decode_json($response->decoded_content);
} elsif ($response->code == 404) {
lib/Catmandu/Store/Adlib.pm view on Meta::CPAN
use Moo;
use Catmandu::Sane;
use Catmandu::Store::Adlib::Bag;
with 'Catmandu::Store';
#http://pwv.adlibhosting.com/api/wwwopac.ashx?command=
has endpoint => (is => 'ro', required => 1);
has username => (is => 'ro', required => 1);
has password => (is => 'ro', required => 1);
has database => (is => 'ro', required => 1);
1;
__END__
=encoding utf-8
=head1 NAME
Catmandu::Store::Adlib -Retrieve items from a L<Adlib|http://www.adlibsoft.nl/> instance
=head1 SYNOPSIS
# From the command line
catmandu export Adlib to YAML --id 1234 --endpoint http://test2.adlibsoft.com --username foo --password bar --database collect.inf
# From a Catmandu Fix
lookup_in_store(
object_priref,
Adlib,
endpoint: http://test2.adlibsoft.com,
username: foo,
password: bar,
database: collect.inf
)
# From Perl code
use Catmandu;
my $store = Catmandu->store('Adlib',
username => 'foo',
password => 'bar',
endpoint => 'http://test2.adlibsoft.com',
database => 'collect.inf'
)->bag;
my $item = $store->get('1234');
=head1 DESCRIPTION
Catmandu::Store::Adlib allows the use of L<Adlib|http://www.adlibsoft.nl/> as a store in Catmandu.
=head1 CONFIGURATION
=head2 endpoint
C<url> of the Adlib API. Do not include the C<api/wwwopac> part; the query builder will append it automatically.
=head2 database
Name of the database (as configured in L<adlibweb.xml|http://api.adlibsoft.com/site/documentation>) you want to query.
=head2 username
Name of a user that can be used to query the API. Only L<Basic Authentication|https://en.wikipedia.org/wiki/Basic_access_authentication> is currently supported.
lib/Catmandu/Store/Adlib/Bag.pm view on Meta::CPAN
with 'Catmandu::Bag';
has api => (is => 'lazy');
sub _build_api {
my $self = shift;
return Catmandu::Adlib::API->new(
username => $self->store->username,
password => $self->store->password,
endpoint => $self->store->endpoint,
database => $self->store->database
);
}
sub generator {
# TODO: OAI
my $self = shift;
my $stack = $self->api->list()->{'adlibJSON'}->{'recordList'}->{'record'};
# TODO: PAGING
( run in 0.277 second using v1.01-cache-2.11-cpan-cc502c75498 )