| 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::General; | ||||||||||
| 5 | 3 | $Webservice::Judobase::General::VERSION = '0.10'; | |||||||||
| 6 | # VERSION | ||||||||||
| 7 | |||||||||||
| 8 | 3 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 LWP::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 3 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 3 | has 'ua' => ( | |||||||||
| 16 | is => 'ro', | ||||||||||
| 17 | required => 1, | ||||||||||
| 18 | ); | ||||||||||
| 19 | |||||||||||
| 20 | 3 | has 'url' => ( | |||||||||
| 21 | is => 'ro', | ||||||||||
| 22 | required => 1, | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | sub competition { | ||||||||
|
Subroutine
competition: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 26 | 0 | my ( $self, %args ) = @_; | |||||||||
| 27 | 0 | ▶ | return { error => 'id parameter is required' } unless defined $args{id}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | |||||||||||
| 29 | my $url | ||||||||||
| 30 | = $self->url | ||||||||||
| 31 | . '?params[action]=general.get_one' | ||||||||||
| 32 | . '¶ms[module]=competition' | ||||||||||
| 33 | . '¶ms[id]=' | ||||||||||
| 34 | 0 | . $args{id}; | |||||||||
| 35 | |||||||||||
| 36 | 0 | my $request = HTTP::Request->new( GET => $url ); | |||||||||
| 37 | |||||||||||
| 38 | 0 | my $response = $self->ua->request($request); | |||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | return decode_json $response->content | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | if $response->code == 200; | ||||||||||
| 42 | |||||||||||
| 43 | 0 | return { error => 'Error retreiving competitor info' }; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | sub competitions { | ||||||||
|
Subroutine
competitions: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 47 | 0 | my $self = shift; | |||||||||
| 48 | |||||||||||
| 49 | 0 | my $url | |||||||||
| 50 | = $self->url | ||||||||||
| 51 | . '?params[action]=competition.get_list' | ||||||||||
| 52 | . '¶ms[limit]=9999' | ||||||||||
| 53 | . '¶ms[sort]=-1'; | ||||||||||
| 54 | |||||||||||
| 55 | 0 | my $request = HTTP::Request->new( GET => $url ); | |||||||||
| 56 | |||||||||||
| 57 | 0 | my $response = $self->ua->request($request); | |||||||||
| 58 | |||||||||||
| 59 | 0 | ▶ | return decode_json $response->content | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | if $response->code == 200; | ||||||||||
| 61 | |||||||||||
| 62 | 0 | return { error => 'Error retreiving competitions info' }; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 0 | ▶ | sub competitors { | ||||||||
|
Subroutine
competitors: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 66 | 0 | my ( $self, %args ) = @_; | |||||||||
| 67 | return { error => 'event_id parameter is required' } | ||||||||||
| 68 | 0 | ▶ | unless defined $args{event_id}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | |||||||||||
| 70 | my $url | ||||||||||
| 71 | = $self->url | ||||||||||
| 72 | . '?params[action]=competition.competitors' | ||||||||||
| 73 | . '¶ms[id_competition]=' | ||||||||||
| 74 | 0 | . $args{event_id}; | |||||||||
| 75 | |||||||||||
| 76 | 0 | my $request = HTTP::Request->new( GET => $url ); | |||||||||
| 77 | |||||||||||
| 78 | 0 | my $response = $self->ua->request($request); | |||||||||
| 79 | |||||||||||
| 80 | 0 | my @competitors = (); | |||||||||
| 81 | 0 | ▶ | if ( $response->code == 200 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 0 | my $info = decode_json $response->content; | |||||||||
| 83 | |||||||||||
| 84 | 0 | for my $gender ( values %{ $info->{categories} } ) { | |||||||||
| 85 | 0 | for my $cat ( values %$gender ) { | |||||||||
| 86 | 0 | for my $person ( values %{ $cat->{persons} } ) { | |||||||||
| 87 | 0 | push @competitors, $person; | |||||||||
| 88 | } | ||||||||||
| 89 | } | ||||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 0 | return \@competitors; | |||||||||
| 93 | } | ||||||||||
| 94 | else { | ||||||||||
| 95 | 0 | return { error => 'Error retreiving competitors info' }; | |||||||||
| 96 | } | ||||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | 3 | 1; | |||||||||