File Coverage

blib/lib/WebService/Lobid.pm
Criterion Covered Total %
statement 20 25 80.0
branch 2 4 50.0
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 27 35 77.1


line stmt bran cond sub pod time code
1             package WebService::Lobid;
2              
3             our $VERSION = 0.005;
4              
5 2     2   1097 use strict;
  2         5  
  2         59  
6 2     2   17 use warnings;
  2         6  
  2         52  
7              
8 2     2   11 use HTTP::Tiny;
  2         4  
  2         44  
9 2     2   10 use Moo;
  2         4  
  2         11  
10              
11             has api_url => ( is => 'rw', default=> 'https://lobid.org/');
12             has api_status => (is => 'rw');
13             has api_timeout => (is => 'rw', default => 3);
14             has use_ssl => ( is => 'rw' );
15              
16             has status => ( is => 'rw');
17             has error => ( is => 'rw');
18              
19             sub BUILD {
20 2     2 0 2474 my $self = shift;
21 2         15 my $api_url = $self->api_url;
22 2         7 my $response = undef;
23              
24 2 50       20 if ( HTTP::Tiny->can_ssl() ) {
25 2         51658 $self->use_ssl("true");
26             }
27             else {
28 0         0 $api_url =~ s/https/http/;
29 0         0 $self->api_url($api_url);
30 0         0 $self->use_ssl("false");
31             }
32              
33 2         20 $response = HTTP::Tiny->new(timeout => $self->api_timeout)->get( $self->api_url );
34              
35 2 50       544038 if ( $response->{success} ) {
36 2         1245 $self->api_status("OK");
37             }
38             else {
39 0           $self->api_status("Error");
40             warn sprintf( "API URL %s is not reachable: %s (%s)",
41             $self->api_url, $response->{reason},
42 0           $response->{status} );
43             }
44             } ## end sub BUILD
45              
46             1;