line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Importer::Blacklight; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
41418
|
use Catmandu::Sane; |
|
2
|
|
|
|
|
188378
|
|
|
2
|
|
|
|
|
12
|
|
4
|
2
|
|
|
2
|
|
2115
|
use Catmandu::Util qw(:is); |
|
2
|
|
|
|
|
99445
|
|
|
2
|
|
|
|
|
835
|
|
5
|
2
|
|
|
2
|
|
1457
|
use REST::Client; |
|
2
|
|
|
|
|
91976
|
|
|
2
|
|
|
|
|
71
|
|
6
|
2
|
|
|
2
|
|
18
|
use URI::Escape; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
115
|
|
7
|
2
|
|
|
2
|
|
1287
|
use JSON::MaybeXS; |
|
2
|
|
|
|
|
2233
|
|
|
2
|
|
|
|
|
114
|
|
8
|
2
|
|
|
2
|
|
10
|
use Moo; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
20
|
|
9
|
2
|
|
|
2
|
|
936
|
use feature 'state'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
997
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has url => (is => 'ro', required => 1); |
14
|
|
|
|
|
|
|
has q => (is => 'ro', required => 1); |
15
|
|
|
|
|
|
|
has client => (is => 'lazy'); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _build_client { |
18
|
0
|
|
|
0
|
|
|
my $self; |
19
|
0
|
|
|
|
|
|
REST::Client->new(); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub generator { |
23
|
|
|
|
|
|
|
my ($self) = @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub { |
26
|
|
|
|
|
|
|
state $response = $self->query($self->q(),1); |
27
|
|
|
|
|
|
|
state $idx = 0; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
unless (defined($response)) { |
30
|
|
|
|
|
|
|
print STDERR "Catmandu::Importer::Blacklight no response from: " . $self->url . "\n"; |
31
|
|
|
|
|
|
|
return undef; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
if (defined $response && ! defined $response->{docs}->[$idx]) { |
35
|
|
|
|
|
|
|
$response = $self->query($self->q(),$response->{pages}->{next_page}); |
36
|
|
|
|
|
|
|
$idx = 0; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
return unless defined($response->{docs}->[0]); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $doc = $response->{docs}->[$idx]; |
42
|
|
|
|
|
|
|
my $id = $doc->{id}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$idx++; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
{ '_id' => $id , %$doc}; |
47
|
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub query { |
51
|
0
|
|
|
0
|
0
|
|
my ($self,$q,$page) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
0
|
|
|
|
return undef unless defined($page) && $page =~ /^\d+$/; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $url = sprintf "%s?q=%s&page=%d" , $self->url, uri_escape($q), $page; |
56
|
0
|
|
|
|
|
|
my $response = $self->client->GET($url, { Accept => 'application/json' }); |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
return undef unless ($response->responseCode eq '200'); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $json = $response->responseContent; |
61
|
0
|
|
|
|
|
|
my $perl = decode_json($json); |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$perl->{response}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |