line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Importer::MediaHaven; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Catmandu::Importer::MediaHaven - Package that imports Zeticon MediaHaven records |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# From the command line |
10
|
|
|
|
|
|
|
$ cat catmandu.yml |
11
|
|
|
|
|
|
|
--- |
12
|
|
|
|
|
|
|
importer: |
13
|
|
|
|
|
|
|
mh: |
14
|
|
|
|
|
|
|
package: MediaHaven |
15
|
|
|
|
|
|
|
options: |
16
|
|
|
|
|
|
|
url: https://archief.viaa.be/mediahaven-rest-api/resources/media |
17
|
|
|
|
|
|
|
username: ... |
18
|
|
|
|
|
|
|
password: ... |
19
|
|
|
|
|
|
|
$ catmandu convert mh to YAML |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Catmandu |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $importer = Catmandu->importer('BagIt', |
24
|
|
|
|
|
|
|
url => ... , |
25
|
|
|
|
|
|
|
username => ... , |
26
|
|
|
|
|
|
|
password => ... , |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $n = $importer->each(sub { |
30
|
|
|
|
|
|
|
my $hashref = $_[0]; |
31
|
|
|
|
|
|
|
# ... |
32
|
|
|
|
|
|
|
}); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 METHODS |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
This module inherits all methods of L<Catmandu::Importer> and by this |
38
|
|
|
|
|
|
|
L<Catmandu::Iterable>. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 CONFIGURATION |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
In addition to the configuration provided by L<Catmandu::Importer> the importer can |
43
|
|
|
|
|
|
|
be configured with the following parameters: |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=over |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item url |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Required. The URL to the MediaHaven REST endpoint. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item username |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Required. Username used to connect to MediaHaven. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item password |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Required. Password used to connect to MediaHaven. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=back |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SEE ALSO |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
L<Catmandu>, |
64
|
|
|
|
|
|
|
L<Catmandu::Importer>, |
65
|
|
|
|
|
|
|
L<Catmandu::MediaHaven> |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 AUTHOR |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Patrick Hochstenbach <Patrick.Hochstenbach@UGent.be> |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under the terms |
74
|
|
|
|
|
|
|
of either: the GNU General Public License as published by the Free Software Foundation; |
75
|
|
|
|
|
|
|
or the Artistic License. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
See L<http://dev.perl.org/licenses/> for more information. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
1
|
|
82702
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
156567
|
|
|
1
|
|
|
|
|
9
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
84
|
|
|
|
|
|
|
|
85
|
1
|
|
|
1
|
|
445
|
use Moo; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
9
|
|
86
|
1
|
|
|
1
|
|
1194
|
use Catmandu::MediaHaven; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
45
|
|
87
|
1
|
|
|
1
|
|
8
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
has 'url' => (is => 'ro' , required => 1); |
92
|
|
|
|
|
|
|
has 'username' => (is => 'ro' , required => 1); |
93
|
|
|
|
|
|
|
has 'password' => (is => 'ro' , required => 1); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub generator { |
96
|
|
|
|
|
|
|
my ($self) = @_; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $mh = Catmandu::MediaHaven->new( |
99
|
|
|
|
|
|
|
url => $self->url, |
100
|
|
|
|
|
|
|
username => $self->username, |
101
|
|
|
|
|
|
|
password => $self->password, |
102
|
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my $res = $mh->search(); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub { |
107
|
|
|
|
|
|
|
state $results = $res->{mediaDataList}; |
108
|
|
|
|
|
|
|
state $total = $res->{totalNrOfResults}; |
109
|
|
|
|
|
|
|
state $index = 0; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
$index++; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
if (@$results > 1) { |
114
|
|
|
|
|
|
|
return shift @$results; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
elsif ($index < $total) { |
117
|
|
|
|
|
|
|
my $res = $mh->search(undef, start => $index+1); |
118
|
|
|
|
|
|
|
$results = $res->{mediaDataList}; |
119
|
|
|
|
|
|
|
$index++; |
120
|
|
|
|
|
|
|
return shift @$results; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
return undef; |
123
|
|
|
|
|
|
|
}; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |