| 1 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package Webservice::Judobase::Country; | ||||||||||
| 5 | 3 | $Webservice::Judobase::Country::VERSION = '0.10'; | |||||||||
| 6 | # ABSTRACT: This module wraps the www.judobase.org website API. | ||||||||||
| 7 | # VERSION | ||||||||||
| 8 | |||||||||||
| 9 | 3 | ▶ | use HTTP::Request; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 3 | ▶ | use JSON::Tiny 'decode_json'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 3 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | #extends 'Webservice::Judobase'; | ||||||||||
| 14 | 3 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 3 | has 'ua' => ( | |||||||||
| 17 | is => 'ro', | ||||||||||
| 18 | required => 1, | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | 3 | has 'url' => ( | |||||||||
| 22 | is => 'ro', | ||||||||||
| 23 | required => 1, | ||||||||||
| 24 | ); | ||||||||||
| 25 | |||||||||||
| 26 | 0 | ▶ | sub competitors_list { | ||||||||
|
Subroutine
competitors_list: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 27 | 0 | my ( $self, %args ) = @_; | |||||||||
| 28 | return { error => 'id_country parameter is required' } | ||||||||||
| 29 | 0 | ▶ | unless defined $args{id_country}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | return { error => 'id_country parameter must be an integer' } | ||||||||||
| 31 | 0 | ▶ | unless ( $args{id_country} =~ /\d+/ ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | |||||||||||
| 33 | my $url | ||||||||||
| 34 | = $self->url | ||||||||||
| 35 | . '?params[action]=country.competitors_list' | ||||||||||
| 36 | . '¶ms[id_country]=' | ||||||||||
| 37 | 0 | . $args{id_country}; | |||||||||
| 38 | |||||||||||
| 39 | 0 | my $request = HTTP::Request->new( GET => $url ); | |||||||||
| 40 | 0 | my $response = $self->ua->request($request); | |||||||||
| 41 | |||||||||||
| 42 | 0 | ▶ | if ( $response->code == 200 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 0 | my $data = decode_json $response->content; | |||||||||
| 44 | |||||||||||
| 45 | 0 | return $data->{competitors}; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 0 | return { error => 'Error retreiving country info' }; | |||||||||
| 49 | |||||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | sub get_list { | ||||||||
|
Subroutine
get_list: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 53 | 0 | my $self = shift; | |||||||||
| 54 | 0 | my $url = $self->url . '?params[action]=country.get_list'; | |||||||||
| 55 | |||||||||||
| 56 | 0 | my $request = HTTP::Request->new( GET => $url ); | |||||||||
| 57 | |||||||||||
| 58 | 0 | my $response = $self->ua->request($request); | |||||||||
| 59 | |||||||||||
| 60 | 0 | ▶ | if ( $response->code == 200 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 0 | my $data = decode_json $response->content; | |||||||||
| 62 | |||||||||||
| 63 | 0 | return $data; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 0 | return { error => 'Error retreiving country info' }; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 3 | 1; | |||||||||