| 1 | package WWW::Freelancer; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use version; our $VERSION = qv('0.0.1'); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use LWP::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use JSON qw( from_json ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use WWW::Freelancer::Project; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use WWW::Freelancer::User; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 2 | my $user_agent = LWP::UserAgent->new( 'agent' => __PACKAGE__ . '/' . $VERSION ); | |||||||||
| 14 | |||||||||||
| 15 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 16 | 1 | my $class = shift; | |||||||||
| 17 | 1 | return bless {}, __PACKAGE__; | |||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | 1 | ▶ | sub get_project { | ||||||||
|
Subroutine
get_project: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 21 | 1 | my ( $self, $id ) = @_; | |||||||||
| 22 | |||||||||||
| 23 | 1 | my $content = $user_agent->get("http://api.freelancer.com/Project/$id.json") | |||||||||
| 24 | ->decoded_content(); | ||||||||||
| 25 | |||||||||||
| 26 | 1 | return bless from_json($content)->{'project'}, 'WWW::Freelancer::Project'; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 0 | ▶ | sub get_user { | ||||||||
|
Subroutine
get_user: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 30 | 0 | my ( $self, $id_or_username ) = @_; | |||||||||
| 31 | |||||||||||
| 32 | 0 | my $query_string = "?id=$id_or_username"; | |||||||||
| 33 | 0 | my $content | |||||||||
| 34 | = $user_agent->get( | ||||||||||
| 35 | "http://api.freelancer.com/User/Properties.json$query_string") | ||||||||||
| 36 | ->decoded_content(); | ||||||||||
| 37 | |||||||||||
| 38 | 0 | return bless from_json($content)->{'profile'}, 'WWW::Freelancer::User'; | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | sub search_project { | ||||||||
|
Subroutine
search_project: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 42 | 0 | my ( $self, %parametres ) = @_; | |||||||||
| 43 | |||||||||||
| 44 | 0 | _move_key_to_api_key( | |||||||||
| 45 | \%parametres, | ||||||||||
| 46 | { 'jobs' => 'jobs[]', | ||||||||||
| 47 | 'maximum_budget' => 'max_budget', | ||||||||||
| 48 | 'minimum_budget' => 'min_budget', | ||||||||||
| 49 | 'order_direction' => 'order_dir', | ||||||||||
| 50 | } | ||||||||||
| 51 | ); | ||||||||||
| 52 | |||||||||||
| 53 | 0 | ▶ | if ( defined $parametres{'order'}->{'random'} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | $parametres{'order'}->{'rand'} = $parametres{'order'}->{'random'}; | |||||||||
| 55 | 0 | delete $parametres{'order'}->{'random'}; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 0 | my $query_string = _build_query_string(%parametres); | |||||||||
| 59 | 0 | my $content | |||||||||
| 60 | = $user_agent->get( | ||||||||||
| 61 | "http://api.freelancer.com/Project/Search.json$query_string") | ||||||||||
| 62 | ->decoded_content(); | ||||||||||
| 63 | 0 | my @projects = @{ from_json($content)->{'projects'}->{'items'} }; | |||||||||
| 64 | 0 | map { bless $_, 'WWW::Freelancer::Project' } @projects; | |||||||||
| 65 | |||||||||||
| 66 | 0 | return @projects; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 0 | ▶ | sub _move_key_to_api_key { | ||||||||
|
Subroutine
_move_key_to_api_key: not called CC=3 SCAR=24.8
| |||||||||||
| 70 | 0 | my ( $parametres_ref, $keys_and_api_keys_ref ) = @_; | |||||||||
| 71 | |||||||||||
| 72 | 0 | for my $key ( keys %{$keys_and_api_keys_ref} ) { | |||||||||
| 73 | 0 | ▶ | if ( defined $parametres_ref->{$key} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | $parametres_ref->{ $keys_and_api_keys_ref->{$key} } | ||||||||||
| 75 | 0 | = $parametres_ref->{$key}; | |||||||||
| 76 | 0 | delete $parametres_ref->{$key}; | |||||||||
| 77 | } | ||||||||||
| 78 | } | ||||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 0 | ▶ | sub _build_query_string { | ||||||||
|
Subroutine
_build_query_string: not called CC=4 SCAR=30.0
| |||||||||||
| 82 | 0 | my %parametres = @_; | |||||||||
| 83 | 0 | my @query_strings; | |||||||||
| 84 | |||||||||||
| 85 | 0 | for my $key ( keys %parametres ) { | |||||||||
| 86 | 0 | ▶ | if ( ref $parametres{$key} eq 'ARRAY' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 0 | for my $element ( @{ $parametres{$key} } ) { | |||||||||
| 88 | 0 | push @query_strings, $key . '=' . $element; | |||||||||
| 89 | } | ||||||||||
| 90 | } | ||||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | 0 | return '?' . join '&', @query_strings; | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 2 | 1; | |||||||||
| 97 | |||||||||||
| 98 | __END__ | ||||||||||