line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenSourceOrg::API; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
48667
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
5
|
1
|
|
|
1
|
|
3
|
use utf8; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
4
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Perl API Bindings to the OSI License API |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
530
|
use Moo; |
|
1
|
|
|
|
|
8962
|
|
|
1
|
|
|
|
|
5
|
|
12
|
1
|
|
|
1
|
|
1476
|
use REST::Client; |
|
1
|
|
|
|
|
33248
|
|
|
1
|
|
|
|
|
29
|
|
13
|
1
|
|
|
1
|
|
415
|
use Const::Fast; |
|
1
|
|
|
|
|
740
|
|
|
1
|
|
|
|
|
4
|
|
14
|
1
|
|
|
1
|
|
649
|
use JSON; |
|
1
|
|
|
|
|
8297
|
|
|
1
|
|
|
|
|
5
|
|
15
|
1
|
|
|
1
|
|
131
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
278
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
const my $base_url => 'https://api.opensource.org'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has _api_client => ( is => 'lazy' ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _build__api_client { |
22
|
0
|
|
|
0
|
|
|
my $client = REST::Client->new(); |
23
|
0
|
|
|
|
|
|
$client->setHost($base_url); |
24
|
0
|
|
|
|
|
|
return $client; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub all { |
28
|
0
|
|
|
0
|
1
|
|
my $self = shift(); |
29
|
0
|
|
|
|
|
|
my $client = $self->_api_client; |
30
|
0
|
|
|
|
|
|
return $self->_handle_response( $client->GET('/licenses/') ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub tagged { |
34
|
0
|
|
|
0
|
1
|
|
my $self = shift(); |
35
|
0
|
|
|
|
|
|
my $keyword = shift(); |
36
|
0
|
|
|
|
|
|
my $client = $self->_api_client; |
37
|
0
|
|
|
|
|
|
return $self->_handle_response( $client->GET( '/licenses/' . $keyword ) ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub get { |
41
|
0
|
|
|
0
|
1
|
|
my $self = shift(); |
42
|
0
|
|
|
|
|
|
my $osi_id = shift(); |
43
|
0
|
|
|
|
|
|
my $client = $self->_api_client; |
44
|
0
|
|
|
|
|
|
return $self->_handle_response( $client->GET( '/license/' . $osi_id ) ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub get_by_scheme { |
48
|
0
|
|
|
0
|
1
|
|
my $self = shift(); |
49
|
0
|
|
|
|
|
|
my $scheme = shift(); |
50
|
0
|
|
|
|
|
|
my $id = shift(); |
51
|
0
|
|
|
|
|
|
my $client = $self->_api_client; |
52
|
0
|
|
|
|
|
|
return $self->_handle_response( $client->GET( '/license/' . join( '/', $scheme, $id ) ) ); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _handle_response { |
56
|
0
|
|
|
0
|
|
|
my $self = shift(); |
57
|
0
|
|
|
|
|
|
my $response = shift(); |
58
|
0
|
0
|
|
|
|
|
if ( $response->responseCode() == 200 ) { |
59
|
0
|
|
|
|
|
|
return from_json( $response->responseContent ); |
60
|
|
|
|
|
|
|
} else { |
61
|
0
|
|
|
|
|
|
croak 'Error: ' . $response->responseCode() . ". Content: " . $response->responseContent; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |