blib/lib/WWW/ELISA.pm

filter: Statementstmt 53.7% 29 / 54 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 9 / 15 Podpod 100% 2 / 2 totaltotal 56.3% 40 / 71 CC 1 SCAR 3.4
CC
1
Cov
54%
push
2.0
_create_notepad
2.0
_authenticate
2.0
CRAP 1.4
↑ Summary Build »
1 package WWW::ELISA;
2  
3 1 our $VERSION = '0.05';
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 sub push {
22 0 ▶ my ($self, $notepad) = @_;
Subroutine push: not called CC=1 SCAR=6.9
Pod documented
23  
24 0 $self->_create_notepad($notepad);
25 }
26  
27 sub _create_notepad {
28 0 ▶ my ($self, $notepad) = @_;
Subroutine _create_notepad: not called CC=1 SCAR=6.9
29  
30 my $data = {
31 userID => $notepad->{userID},
32 token => $self->_authenticate(),
33 notepadName => $notepad->{notepadName},
34 titleList => $notepad->{titleList},
35 0 };
36  
37 0 my $response = $self->_do_request("/createNotepad", $data);
38 }
39  
40 sub _authenticate {
41 0 ▶ my $self = shift;
Subroutine _authenticate: not called CC=1 SCAR=6.9
42  
43 0 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)
44 = localtime(time);
45  
46 0 my $timestamp = sprintf(
47 "%04d-%02d-%02dT%02d:%02d:%02dZ",
48 $year + 1900,
49 $mon + 1, $mday, $hour, $min, $sec
50 );
51 0 my $timestamp2 = sprintf(
52 "%04d%02d%02dT%02d%02d%02dZ",
53 $year + 1900,
54 $mon + 1, $mday, $hour, $min, $sec
55 );
56  
57 my $auth = {
58 callerID => $self->{callerID},
59 timestamp => $timestamp,
60 0 hash => md5_hex($self->{callerID} . $timestamp2 . $self->{secret}),
61 };
62  
63 0 my $res = $self->_do_request("/authenticate", $auth);
64 0 return $res->{token};
65 }
66  
67 sub _do_request {
68 0 ▶ my ($self, $path, $content) = @_;
Subroutine _do_request: not called CC=1 SCAR=6.9
69  
70 0 my $endpoint = $self->{endpoint};
71  
72 try {
73 0 ▶ my $ua = LWP::UserAgent->new;
Subroutine __ANON__: not called CC=1 SCAR=6.9
74 0 $ua->timeout(20);
75 0 $ua->env_proxy;
76 0 $ua->ssl_opts(verify_hostname => 0, SSL_verify_mode => 0x00);
77  
78 0 my $req = HTTP::Request->new('POST', $endpoint . $path);
79 0 $req->header('Content-Type' => 'application/json');
80 0 $req->content(encode_json($content));
81  
82 0 my $res = $ua->request($req);
83  
84 0 return decode_json($res->decoded_content);
85 }
86 catch {
87 0 ▶ print STDERR "Error: " . $_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
88 }
89 0 }
90  
91 1 1;
92  
93 __END__
↑ Summary Build »