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