| 1 | package WWW::ELISA; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | our $VERSION = '0.06'; | |||||||||||
| 4 | |||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 1 | ▶ | use Digest::MD5 qw( md5_hex ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 1 | ▶ | use HTTP::Request; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 1 | ▶ | use JSON::XS; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 1 | ▶ | use LWP::UserAgent; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 1 | ▶ | use Try::Tiny; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | sub new { | ||||||||||||
| 15 | 2 | ▶ | my $class = shift; | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 16 | 2 | my %args = (endpoint => 'https://elisa.hbz-nrw.de:8091/api/rest', @_,); | |||||||||||
| 17 | |||||||||||||
| 18 | 2 | return bless {%args}, $class; | |||||||||||
| 19 | } | ||||||||||||
| 20 | |||||||||||||
| 21 | # leave it for backwards compatibility | ||||||||||||
| 22 | sub push { | ||||||||||||
| 23 | 0 | ▶ | my ($self, $notepad) = @_; | ||||||||||
|
Subroutine
push: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 24 | |||||||||||||
| 25 | 0 | $self->create_notepad($notepad); | |||||||||||
| 26 | } | ||||||||||||
| 27 | |||||||||||||
| 28 | sub create_notepad { | ||||||||||||
| 29 | 0 | ▶ | my ($self, $notepad) = @_; | ||||||||||
|
Subroutine
create_notepad: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 30 | |||||||||||||
| 31 | my $data = { | ||||||||||||
| 32 | userID => $notepad->{userID}, | ||||||||||||
| 33 | token => $self->_authenticate(), | ||||||||||||
| 34 | notepadName => $notepad->{notepadName}, | ||||||||||||
| 35 | titleList => $notepad->{titleList}, | ||||||||||||
| 36 | 0 | ▶ | available_only => $notepad->{available_only} // "false", | ||||||||||
|
Condition0%0/2
$notepad->{"available_only"} // "false"
MC/DC0%0/1
$notepad->{"available_only"} // "false"
$notepad->{"available_only"}
Truth table0%0/2
A
A= $notepad->{"available_only"}
| |||||||||||||
| 37 | }; | ||||||||||||
| 38 | |||||||||||||
| 39 | 0 | my $response = $self->_do_request("/createNotepad", $data); | |||||||||||
| 40 | } | ||||||||||||
| 41 | |||||||||||||
| 42 | sub create_basket { | ||||||||||||
| 43 | 0 | ▶ | my ($self, $notepad) = @_; | ||||||||||
|
Subroutine
create_basket: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 44 | |||||||||||||
| 45 | my $data = { | ||||||||||||
| 46 | userID => $notepad->{userID}, | ||||||||||||
| 47 | token => $self->_authenticate(), | ||||||||||||
| 48 | notepadName => $notepad->{notepadName}, | ||||||||||||
| 49 | titleList => $notepad->{titleList}, | ||||||||||||
| 50 | 0 | ▶ | available_only => $notepad->{available_only} // "false", | ||||||||||
|
Condition0%0/2
$notepad->{"available_only"} // "false"
MC/DC0%0/1
$notepad->{"available_only"} // "false"
$notepad->{"available_only"}
Truth table0%0/2
A
A= $notepad->{"available_only"}
| |||||||||||||
| 51 | }; | ||||||||||||
| 52 | |||||||||||||
| 53 | 0 | my $response = $self->_do_request("/createBasket", $data); | |||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | sub _authenticate { | ||||||||||||
| 57 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_authenticate: not called CC=1 SCAR=6.9
| |||||||||||||
| 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 | ▶ | my ($self, $path, $content) = @_; | ||||||||||
|
Subroutine
_do_request: not called CC=1 SCAR=6.9
| |||||||||||||
| 85 | |||||||||||||
| 86 | 0 | my $endpoint = $self->{endpoint}; | |||||||||||
| 87 | |||||||||||||
| 88 | try { | ||||||||||||
| 89 | 0 | ▶ | my $ua = LWP::UserAgent->new; | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 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 | ▶ | print STDERR "Error: " . $_; | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 104 | } | ||||||||||||
| 105 | 0 | } | |||||||||||
| 106 | |||||||||||||
| 107 | 1 | 1; | |||||||||||
| 108 | |||||||||||||
| 109 | __END__ | ||||||||||||