line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::OverheidIO; |
2
|
4
|
|
|
4
|
|
85223
|
use Moose; |
|
4
|
|
|
|
|
358044
|
|
|
4
|
|
|
|
|
25
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: A (semi) abstract class that implements logic to talk to Overheid.IO |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.1'; |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
24945
|
use LWP::UserAgent; |
|
4
|
|
|
|
|
87136
|
|
|
4
|
|
|
|
|
114
|
|
9
|
4
|
|
|
4
|
|
28
|
use URI; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
76
|
|
10
|
4
|
|
|
4
|
|
18
|
use Carp; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
199
|
|
11
|
4
|
|
|
4
|
|
1481
|
use JSON; |
|
4
|
|
|
|
|
26913
|
|
|
4
|
|
|
|
|
20
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has ua => ( |
14
|
|
|
|
|
|
|
is => 'ro', |
15
|
|
|
|
|
|
|
isa => 'LWP::UserAgent', |
16
|
|
|
|
|
|
|
builder => '_build_useragent', |
17
|
|
|
|
|
|
|
lazy => 1, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has base_uri => ( |
21
|
|
|
|
|
|
|
is => 'ro', |
22
|
|
|
|
|
|
|
isa => 'URI', |
23
|
|
|
|
|
|
|
builder => '_build_base_uri', |
24
|
|
|
|
|
|
|
lazy => 1, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has max_query_size => ( |
28
|
|
|
|
|
|
|
is => 'ro', |
29
|
|
|
|
|
|
|
isa => 'Int', |
30
|
|
|
|
|
|
|
default => 30, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has key => ( |
35
|
|
|
|
|
|
|
is => 'ro', |
36
|
|
|
|
|
|
|
isa => 'Str', |
37
|
|
|
|
|
|
|
required => 1, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has type => ( |
42
|
|
|
|
|
|
|
is => 'ro', |
43
|
|
|
|
|
|
|
isa => 'Str', |
44
|
|
|
|
|
|
|
lazy => 1, |
45
|
|
|
|
|
|
|
builder => '_build_type', |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has fieldnames => ( |
50
|
|
|
|
|
|
|
is => 'rw', |
51
|
|
|
|
|
|
|
isa => 'ArrayRef', |
52
|
|
|
|
|
|
|
lazy => 1, |
53
|
|
|
|
|
|
|
builder => '_build_fieldnames', |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
has queryfields => ( |
57
|
|
|
|
|
|
|
is => 'rw', |
58
|
|
|
|
|
|
|
isa => 'ArrayRef', |
59
|
|
|
|
|
|
|
lazy => 1, |
60
|
|
|
|
|
|
|
builder => '_build_queryfields', |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub search { |
64
|
6
|
|
|
6
|
1
|
29997
|
my $self = shift; |
65
|
6
|
|
|
|
|
11
|
my $search_term = shift; |
66
|
6
|
|
|
|
|
13
|
my $opts = {@_}; |
67
|
|
|
|
|
|
|
|
68
|
6
|
|
|
|
|
11
|
my $filter = $opts->{filter}; |
69
|
6
|
100
|
|
|
|
178
|
$filter->{actief} = 'true' if $self->type eq 'kvk'; |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
15
|
my %query = map { sprintf('filters[%s]', $_), => $filter->{$_} } |
72
|
6
|
|
|
|
|
12
|
grep { defined $filter->{$_} } keys %{$filter}; |
|
2
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
18
|
|
73
|
|
|
|
|
|
|
|
74
|
6
|
|
|
|
|
157
|
$query{size} = $self->max_query_size; |
75
|
|
|
|
|
|
|
|
76
|
6
|
|
|
|
|
142
|
my $uri = $self->base_uri->clone; |
77
|
|
|
|
|
|
|
|
78
|
6
|
|
|
|
|
194
|
$uri->query_form( |
79
|
|
|
|
|
|
|
%query, |
80
|
|
|
|
|
|
|
'fields[]' => $self->fieldnames, |
81
|
|
|
|
|
|
|
'queryfields[]' => $self->queryfields, |
82
|
|
|
|
|
|
|
query => $search_term, |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
6
|
|
|
|
|
914
|
return $self->_call_overheid_io($uri); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _build_base_uri { |
89
|
3
|
|
|
3
|
|
6
|
my $self = shift; |
90
|
3
|
|
|
|
|
69
|
return URI->new_abs( "/api/". $self->type, 'https://overheid.io'); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _build_useragent { |
94
|
3
|
|
|
3
|
|
6
|
my $self = shift; |
95
|
3
|
|
|
|
|
27
|
my $ua = LWP::UserAgent->new( |
96
|
|
|
|
|
|
|
ssl_opts => { |
97
|
|
|
|
|
|
|
SSL_ca_path => '/etc/ssl/certs', |
98
|
|
|
|
|
|
|
verify_hostname => 1, |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
); |
101
|
3
|
|
|
|
|
5918
|
$ua->default_header('ovio-api-key', $self->key); |
102
|
3
|
|
|
|
|
256
|
return $ua; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _call_overheid_io { |
106
|
4
|
|
|
4
|
|
12
|
my ($self, $uri) = @_; |
107
|
|
|
|
|
|
|
|
108
|
4
|
|
|
|
|
107
|
my $res = $self->ua->get($uri->as_string); |
109
|
4
|
|
|
|
|
6502
|
my $decoded = $res->decoded_content; |
110
|
|
|
|
|
|
|
|
111
|
4
|
100
|
|
|
|
564
|
if (!$res->is_success) { |
112
|
1
|
|
|
|
|
9
|
die sprintf("%s - %s", $res->status_line, $res->decoded_content), $/; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
3
|
|
|
|
|
124
|
my $json = JSON->new->decode($decoded); |
116
|
|
|
|
|
|
|
|
117
|
3
|
|
|
|
|
31
|
return $json; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=pod |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=encoding UTF-8 |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 NAME |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
WebService::OverheidIO - A (semi) abstract class that implements logic to talk to Overheid.IO |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 VERSION |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
version 1.1 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 SYNOPSIS |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
package WebService::OverheidIO::Foo; |
140
|
|
|
|
|
|
|
use Moose; |
141
|
|
|
|
|
|
|
extends 'WebService::OverheidIO'; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# You must implement the following builders: |
144
|
|
|
|
|
|
|
# _build_type |
145
|
|
|
|
|
|
|
# _build_fieldnames |
146
|
|
|
|
|
|
|
# _build_queryfields |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 DESCRIPTION |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
L<Overheid.IO|https://overheid.io> is a open data initiative to expose |
151
|
|
|
|
|
|
|
data the Dutch government exposes via a JSON API. This is a Perl |
152
|
|
|
|
|
|
|
implemenation for talking to that JSON API. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 ua |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
An L<LWP::UserAgent> object |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 base_uri |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
The base URI of the Overheid.IO, lazy loaded. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 max_query_size |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
The max query size, defaults to 30. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 key |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
The required Overheid.IO API key. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 type |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
The type of Overheid.IO api |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 fieldnames |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
The names of the fields which the Overheid.IO will respond with |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 queryfields |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
The names of the fields which will be used to query on |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 METHODS |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 search |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Search OverheidIO by a search term, you can apply additional filters for zipcodes and such |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
$overheidio->search( |
191
|
|
|
|
|
|
|
"Mintlab", |
192
|
|
|
|
|
|
|
filter => { |
193
|
|
|
|
|
|
|
postcode => '1051JL', |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
); |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 SEE ALSO |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=over |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=item L<WebService::OverheidIO::KvK> |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Chamber of commerce data |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=item L<WebService::OverheidIO::BAG> |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
BAG stands for Basis Administratie Gebouwen. This is basicly a huge |
208
|
|
|
|
|
|
|
address table. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=back |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 AUTHOR |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Wesley Schwengle <wesley@mintlab.nl> |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
This software is Copyright (c) 2017 by Mintlab BV. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
This is free software, licensed under: |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
The European Union Public License (EUPL) v1.1 |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=cut |