line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::ELISA; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
69280
|
use strict; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
28
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
7
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
8
|
1
|
|
|
1
|
|
5
|
use Digest::MD5 qw( md5_hex ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
59
|
|
9
|
1
|
|
|
1
|
|
456
|
use HTTP::Request; |
|
1
|
|
|
|
|
18950
|
|
|
1
|
|
|
|
|
64
|
|
10
|
1
|
|
|
1
|
|
654
|
use JSON::XS; |
|
1
|
|
|
|
|
5069
|
|
|
1
|
|
|
|
|
56
|
|
11
|
1
|
|
|
1
|
|
645
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
25798
|
|
|
1
|
|
|
|
|
31
|
|
12
|
1
|
|
|
1
|
|
6
|
use Try::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
565
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
2
|
|
|
2
|
1
|
970
|
my $class = shift; |
16
|
2
|
|
|
|
|
8
|
my %args = (endpoint => 'https://elisa.hbz-nrw.de:8091/api/rest', @_,); |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
|
|
14
|
return bless {%args}, $class; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# leave it for backwards compatibility |
22
|
|
|
|
|
|
|
sub push { |
23
|
0
|
|
|
0
|
1
|
|
my ($self, $notepad) = @_; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
$self->create_notepad($notepad); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub create_notepad { |
29
|
0
|
|
|
0
|
0
|
|
my ($self, $notepad) = @_; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $data = { |
32
|
|
|
|
|
|
|
userID => $notepad->{userID}, |
33
|
|
|
|
|
|
|
token => $self->_authenticate(), |
34
|
|
|
|
|
|
|
notepadName => $notepad->{notepadName}, |
35
|
|
|
|
|
|
|
titleList => $notepad->{titleList}, |
36
|
0
|
|
0
|
|
|
|
available_only => $notepad->{available_only} // "false", |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $response = $self->_do_request("/createNotepad", $data); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub create_basket { |
43
|
0
|
|
|
0
|
0
|
|
my ($self, $notepad) = @_; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $data = { |
46
|
|
|
|
|
|
|
userID => $notepad->{userID}, |
47
|
|
|
|
|
|
|
token => $self->_authenticate(), |
48
|
|
|
|
|
|
|
notepadName => $notepad->{notepadName}, |
49
|
|
|
|
|
|
|
titleList => $notepad->{titleList}, |
50
|
0
|
|
0
|
|
|
|
available_only => $notepad->{available_only} // "false", |
51
|
|
|
|
|
|
|
}; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $response = $self->_do_request("/createBasket", $data); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _authenticate { |
57
|
0
|
|
|
0
|
|
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) |
60
|
|
|
|
|
|
|
= localtime(time); |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $timestamp = sprintf( |
63
|
|
|
|
|
|
|
"%04d-%02d-%02dT%02d:%02d:%02dZ", |
64
|
|
|
|
|
|
|
$year + 1900, |
65
|
|
|
|
|
|
|
$mon + 1, $mday, $hour, $min, $sec |
66
|
|
|
|
|
|
|
); |
67
|
0
|
|
|
|
|
|
my $timestamp2 = sprintf( |
68
|
|
|
|
|
|
|
"%04d%02d%02dT%02d%02d%02dZ", |
69
|
|
|
|
|
|
|
$year + 1900, |
70
|
|
|
|
|
|
|
$mon + 1, $mday, $hour, $min, $sec |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $auth = { |
74
|
|
|
|
|
|
|
callerID => $self->{callerID}, |
75
|
|
|
|
|
|
|
timestamp => $timestamp, |
76
|
0
|
|
|
|
|
|
hash => md5_hex($self->{callerID} . $timestamp2 . $self->{secret}), |
77
|
|
|
|
|
|
|
}; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $res = $self->_do_request("/authenticate", $auth); |
80
|
0
|
|
|
|
|
|
return $res->{token}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _do_request { |
84
|
0
|
|
|
0
|
|
|
my ($self, $path, $content) = @_; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $endpoint = $self->{endpoint}; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
try { |
89
|
0
|
|
|
0
|
|
|
my $ua = LWP::UserAgent->new; |
90
|
0
|
|
|
|
|
|
$ua->timeout(20); |
91
|
0
|
|
|
|
|
|
$ua->env_proxy; |
92
|
0
|
|
|
|
|
|
$ua->ssl_opts(verify_hostname => 0, SSL_verify_mode => 0x00); |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new('POST', $endpoint . $path); |
95
|
0
|
|
|
|
|
|
$req->header('Content-Type' => 'application/json'); |
96
|
0
|
|
|
|
|
|
$req->content(encode_json($content)); |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my $res = $ua->request($req); |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
return decode_json($res->decoded_content); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
catch { |
103
|
0
|
|
|
0
|
|
|
print STDERR "Error: " . $_; |
104
|
|
|
|
|
|
|
} |
105
|
0
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |