line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Lobid::Organisation; |
2
|
|
|
|
|
|
|
$WebService::Lobid::Organisation::VERSION = '0.00421'; |
3
|
|
|
|
|
|
|
# ABSTRACT: interface to the lobid-Organisations API |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=for html |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
WebService::Lobid::Organisation - interface to the lobid-Organisations API |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $Library = WebService::Lobid::Organisation->new(isil=> 'DE-380'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
printf("This Library is called '%s', its homepage is at '%s' |
16
|
|
|
|
|
|
|
and it can be found at %f/%f", |
17
|
|
|
|
|
|
|
$Library->name, $Library->url, $Library->lat, $Library->long); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
if ($Library->has_wikipedia){ |
20
|
|
|
|
|
|
|
printf("%s has its own wikipedia entry: %s", |
21
|
|
|
|
|
|
|
$Library->name, $Library->wikipedia); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
if ($Library->has_multiple_emails){ |
25
|
|
|
|
|
|
|
print $Library->email->[0]; |
26
|
|
|
|
|
|
|
}else{ |
27
|
|
|
|
|
|
|
print $Library->email; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 METHODS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=over 4 |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=item new(isil=>$isil) |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
tries to fetch data for the organisation identified by the ISIL C<$isil>. If an entry is found then the attribute C is set to I |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=back |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
currently the following attributes are supported |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=over 4 |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item * B |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
inherited from L, default is I |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item * B |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
inherited from L, I if C reachable, otherwise C |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item * B |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
inherited from L, I if L can use SSL, otherwise C |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item * B (true|false) |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
indicates if an entry is found |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item * B |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
the L of the organisation. Has the predicate function I. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item * B |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Has the predicate function I. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item * B |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Has the predicate function I |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item * B |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Service URL, normally the OPAC, Has the predicate function I |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item * B |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Has the predicate function I |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item * B |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
The city or town where institution resides. Has the predicate function I |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item * B |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Has the predicate function I |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item * B |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Has the predicate function I |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item * B |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Has the predicate function I. The email address for the instition including a I prefix. A scalar if there ist just one email address, an array reference if there are more than one adresses (in this case C is set to I<1> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item * B |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
set to I<1> if there is more than one address in C |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item * B |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
The longitude of the place. Has the predicate function I. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item * B |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
The latitude of the place. Has the predicate function I |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=back |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
L, L, L, L, L |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 LOGGING |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This module uses the L Framework |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 AUTHOR |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Peter Mayr |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 REPOSITORY |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
The source code is also on GitHub . Pull requests and bug reports welcome! |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 LICENCE AND COPYRIGHT |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
GNU GPL V3 |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Peter Mayr 2016 |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
2
|
|
|
2
|
|
113219
|
use strict; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
50
|
|
136
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
46
|
|
137
|
|
|
|
|
|
|
|
138
|
2
|
|
|
2
|
|
1155
|
use HTTP::Tiny; |
|
2
|
|
|
|
|
82742
|
|
|
2
|
|
|
|
|
70
|
|
139
|
2
|
|
|
2
|
|
1117
|
use JSON; |
|
2
|
|
|
|
|
19902
|
|
|
2
|
|
|
|
|
11
|
|
140
|
2
|
|
|
2
|
|
978
|
use Log::Any; |
|
2
|
|
|
|
|
12987
|
|
|
2
|
|
|
|
|
10
|
|
141
|
2
|
|
|
2
|
|
943
|
use Moo; |
|
2
|
|
|
|
|
18354
|
|
|
2
|
|
|
|
|
12
|
|
142
|
2
|
|
|
2
|
|
3207
|
use Try::Tiny; |
|
2
|
|
|
|
|
2126
|
|
|
2
|
|
|
|
|
1319
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
extends 'WebService::Lobid'; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
has isil => ( is => 'rw', predicate => 1, required => 1 ); |
147
|
|
|
|
|
|
|
has name => ( is => 'rw', predicate => 1 ); |
148
|
|
|
|
|
|
|
has url => ( is => 'rw', predicate => 1 ); |
149
|
|
|
|
|
|
|
has provides => ( is => 'rw', predicate => 1 ); |
150
|
|
|
|
|
|
|
has addressCountry => ( is => 'rw', predicate => 1 ); |
151
|
|
|
|
|
|
|
has addressLocality => ( is => 'rw', predicate => 1 ); |
152
|
|
|
|
|
|
|
has postalCode => ( is => 'rw', predicate => 1 ); |
153
|
|
|
|
|
|
|
has streetAddress => ( is => 'rw', predicate => 1 ); |
154
|
|
|
|
|
|
|
has email => ( is => 'rw', predicate => 1 ); |
155
|
|
|
|
|
|
|
has has_multiple_emails => ( is => 'rw', default => 0 ); |
156
|
|
|
|
|
|
|
has lon => ( is => 'rw', predicate => 1 ); |
157
|
|
|
|
|
|
|
has lat => ( is => 'rw', predicate => 1 ); |
158
|
|
|
|
|
|
|
has found => ( is => 'rw', default => 'false' ); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
has log => ( |
161
|
|
|
|
|
|
|
is => 'ro', |
162
|
|
|
|
|
|
|
default => sub { Log::Any->get_logger }, |
163
|
|
|
|
|
|
|
); |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub BUILD { |
166
|
2
|
|
|
2
|
0
|
8
|
my $self = shift; |
167
|
|
|
|
|
|
|
|
168
|
2
|
|
|
|
|
5
|
my $query_string = undef; |
169
|
2
|
|
|
|
|
4
|
my $response = undef; |
170
|
2
|
|
|
|
|
4
|
my $json_result = undef; |
171
|
2
|
|
|
|
|
5
|
my $result_ref = undef; |
172
|
2
|
|
|
|
|
2
|
my $no_of_results = undef; |
173
|
2
|
|
|
|
|
7
|
my %data = (); |
174
|
2
|
|
|
|
|
4
|
my $email = undef; |
175
|
2
|
|
|
|
|
28
|
my $uri = sprintf( "%s%s/%s", $self->api_url, "organisation", $self->isil ); |
176
|
|
|
|
|
|
|
|
177
|
2
|
|
|
|
|
20
|
$query_string = sprintf( "%s%s/%s.json", |
178
|
|
|
|
|
|
|
$self->api_url, "organisations", $self->isil ); |
179
|
|
|
|
|
|
|
|
180
|
2
|
|
|
|
|
21
|
$self->log->infof( "URL: %s", $query_string ); |
181
|
2
|
|
|
|
|
26
|
$response = HTTP::Tiny->new->get($query_string); |
182
|
|
|
|
|
|
|
|
183
|
2
|
100
|
|
|
|
434325
|
if ( $response->{success} ) { |
184
|
1
|
|
|
|
|
410
|
$json_result = $response->{content}; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
else { |
187
|
|
|
|
|
|
|
|
188
|
1
|
50
|
|
|
|
420
|
if ( $response->{status} eq '404' ) { |
189
|
1
|
|
|
|
|
16
|
$self->log->warnf( "ISIL %s not found!", $self->isil ); |
190
|
1
|
|
|
|
|
10
|
$self->found("false"); |
191
|
1
|
|
|
|
|
43
|
return; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
else { |
194
|
|
|
|
|
|
|
$self->log->errorf( "Problem accessing the API: %s!", |
195
|
0
|
|
|
|
|
0
|
$response->{status} ); |
196
|
0
|
|
|
|
|
0
|
$result_ref->{success} = 0; |
197
|
0
|
|
|
|
|
0
|
$result_ref->{error_msg} = $response->{status}; |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
0
|
return $result_ref; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
1
|
|
|
|
|
20
|
$self->log->debugf( "Got JSON Result: %s", $json_result ); |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
try { |
206
|
1
|
|
|
1
|
|
137
|
$result_ref = decode_json($json_result); |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
catch { |
209
|
0
|
|
|
0
|
|
0
|
$self->log->errorf( "Decoding of response '%s' failed: %s", |
210
|
|
|
|
|
|
|
$json_result, $_ ); |
211
|
1
|
|
|
|
|
20
|
}; |
212
|
|
|
|
|
|
|
|
213
|
1
|
50
|
|
|
|
33
|
if ( $result_ref->{isil} eq $self->isil ) { |
214
|
1
|
|
|
|
|
10
|
$self->log->infof( "Got result for ISIL %s", $self->isil ); |
215
|
1
|
|
|
|
|
7
|
$self->found("true"); |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
1
|
50
|
|
|
|
4
|
if ( $result_ref->{email} ) { |
219
|
1
|
|
|
|
|
3
|
$email = $result_ref->{email}; |
220
|
1
|
50
|
|
|
|
4
|
if ( ref($email) eq 'ARRAY' ) { # multiple E-Mail Adresses |
221
|
0
|
|
|
|
|
0
|
$self->has_multiple_emails(1); |
222
|
0
|
|
|
|
|
0
|
for ( my $i = 0; $i < scalar( @{$email} ); $i++ ) { |
|
0
|
|
|
|
|
0
|
|
223
|
0
|
|
|
|
|
0
|
$email->[$i] =~ s/^mailto://; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
else { |
227
|
|
|
|
|
|
|
|
228
|
1
|
|
|
|
|
19
|
$email =~ s/^mailto://; |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
} |
231
|
1
|
|
|
|
|
7
|
$self->email($email); |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
1
|
50
|
|
|
|
7
|
$self->name( $result_ref->{name} ) if ( $result_ref->{name} ); |
235
|
1
|
50
|
|
|
|
6
|
$self->url( $result_ref->{url} ) if ( $result_ref->{url} ); |
236
|
1
|
50
|
|
|
|
7
|
$self->provides( $result_ref->{provides} ) if ( $result_ref->{provides} ); |
237
|
|
|
|
|
|
|
|
238
|
1
|
50
|
33
|
|
|
14
|
if ( ( defined( $result_ref->{location} ) ) |
239
|
|
|
|
|
|
|
&& ( ref( $result_ref->{location} ) eq 'ARRAY' ) ) |
240
|
|
|
|
|
|
|
{ |
241
|
1
|
50
|
|
|
|
4
|
if ( $result_ref->{location}->[0]->{geo} ) { |
242
|
1
|
|
|
|
|
6
|
$self->lat( $result_ref->{location}->[0]->{geo}->{lat} ); |
243
|
1
|
|
|
|
|
5
|
$self->lon( $result_ref->{location}->[0]->{geo}->{lon} ); |
244
|
|
|
|
|
|
|
} |
245
|
1
|
50
|
|
|
|
7
|
if ( $result_ref->{location}->[0]->{address} ) { |
246
|
|
|
|
|
|
|
$self->addressCountry( |
247
|
1
|
|
|
|
|
6
|
$result_ref->{location}->[0]->{address}->{addressCountry} ); |
248
|
|
|
|
|
|
|
$self->addressLocality( |
249
|
1
|
|
|
|
|
4
|
$result_ref->{location}->[0]->{address}->{addressLocality} ); |
250
|
|
|
|
|
|
|
$self->postalCode( |
251
|
1
|
|
|
|
|
6
|
$result_ref->{location}->[0]->{address}->{postalCode} ); |
252
|
|
|
|
|
|
|
$self->streetAddress( |
253
|
1
|
|
|
|
|
25
|
$result_ref->{location}->[0]->{address}->{streetAddress} ); |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
} ## end sub BUILD |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
1; |