File Coverage

blib/lib/Webservice/Judobase/Country.pm
Criterion Covered Total %
statement 18 36 50.0
branch 0 8 0.0
condition n/a
subroutine 6 8 75.0
pod 2 2 100.0
total 26 54 48.1


line stmt bran cond sub pod time code
1 1     1   6 use strict;
  1         2  
  1         25  
2 1     1   5 use warnings;
  1         1  
  1         38  
3              
4             package Webservice::Judobase::Country;
5             $Webservice::Judobase::Country::VERSION = '0.09';
6             # ABSTRACT: This module wraps the www.judobase.org website API.
7             # VERSION
8              
9 1     1   4 use HTTP::Request;
  1         2  
  1         27  
10 1     1   5 use JSON::Tiny 'decode_json';
  1         1  
  1         35  
11 1     1   4 use Moo;
  1         2  
  1         4  
12              
13             #extends 'Webservice::Judobase';
14 1     1   332 use namespace::clean;
  1         2  
  1         5  
15              
16             has 'ua' => (
17             is => 'ro',
18             required => 1,
19             );
20              
21             has 'url' => (
22             is => 'ro',
23             required => 1,
24             );
25              
26             sub competitors_list {
27 0     0 1   my ( $self, %args ) = @_;
28             return { error => 'id_country parameter is required' }
29 0 0         unless defined $args{id_country};
30             return { error => 'id_country parameter must be an integer' }
31 0 0         unless ( $args{id_country} =~ /\d+/ );
32              
33             my $url
34             = $self->url
35             . '?params[action]=country.competitors_list'
36             . '&params[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 0         if ( $response->code == 200 ) {
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             sub get_list {
53 0     0 1   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 0         if ( $response->code == 200 ) {
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             1;