| 1 | package OpenSourceOrg::API; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | our $VERSION = '0.001'; # VERSION | |||||||||
| 8 | |||||||||||
| 9 | # ABSTRACT: Perl API Bindings to the OSI License API | ||||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use REST::Client; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use Const::Fast; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 1 | const my $base_url => 'https://api.opensource.org'; | |||||||||
| 18 | |||||||||||
| 19 | 1 | has _api_client => ( is => 'lazy' ); | |||||||||
| 20 | |||||||||||
| 21 | 0 | ▶ | sub _build__api_client { | ||||||||
|
Subroutine
_build__api_client: not called CC=1 SCAR=6.9
| |||||||||||
| 22 | 0 | my $client = REST::Client->new(); | |||||||||
| 23 | 0 | $client->setHost($base_url); | |||||||||
| 24 | 0 | return $client; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 0 | ▶ | sub all { | ||||||||
|
Subroutine
all: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 28 | 0 | my $self = shift(); | |||||||||
| 29 | 0 | my $client = $self->_api_client; | |||||||||
| 30 | 0 | return $self->_handle_response( $client->GET('/licenses/') ); | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 0 | ▶ | sub tagged { | ||||||||
|
Subroutine
tagged: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 34 | 0 | 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 | 0 | ▶ | sub get { | ||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 41 | 0 | 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 | 0 | ▶ | sub get_by_scheme { | ||||||||
|
Subroutine
get_by_scheme: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 48 | 0 | 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 | 0 | ▶ | sub _handle_response { | ||||||||
|
Subroutine
_handle_response: not called CC=2 SCAR=17.9
| |||||||||||
| 56 | 0 | my $self = shift(); | |||||||||
| 57 | 0 | my $response = shift(); | |||||||||
| 58 | 0 | ▶ | if ( $response->responseCode() == 200 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 0 | return from_json( $response->responseContent ); | |||||||||
| 60 | } else { | ||||||||||
| 61 | 0 | croak 'Error: ' . $response->responseCode() . ". Content: " . $response->responseContent; | |||||||||
| 62 | } | ||||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 1 | 1; | |||||||||
| 66 | |||||||||||
| 67 | __END__ | ||||||||||