File Coverage

blib/lib/WebService/Tagzania/Request.pm
Criterion Covered Total %
statement 36 40 90.0
branch 2 8 25.0
condition 12 45 26.6
subroutine 9 9 100.0
pod 3 3 100.0
total 62 105 59.0


line stmt bran cond sub pod time code
1             package WebService::Tagzania::Request ;
2              
3 2     2   14 use warnings ;
  2         4  
  2         51  
4 2     2   10 use strict ;
  2         4  
  2         51  
5              
6 2     2   10 use Carp ;
  2         3  
  2         177  
7 2     2   1823 use URI ;
  2         15712  
  2         72  
8 2     2   1924 use HTTP::Request ;
  2         48153  
  2         77  
9 2     2   2300 use Data::Dumper ;
  2         24343  
  2         858  
10              
11             our $VERSION = 0.01 ;
12             our @ISA = qw ( HTTP::Request ) ;
13              
14             sub new {
15 1     1 1 2 my $class = shift ;
16 1         2 my $rh_params = shift ;
17              
18 1         10 my $self = new HTTP::Request ;
19            
20 1 50 33     94 return unless $rh_params
      33        
21             && defined $rh_params
22             && ref $rh_params eq 'HASH' ;
23            
24 1         3 $self->{args} = $rh_params ;
25            
26            
27 1         7 $self->method('POST') ;
28 1         11 my $uri = 'http://www.tagzania.com/xml/bounds/index_html' ;
29            
30 1         4 $self->{uri} = $uri ;
31            
32 1         3 bless $self, $class ;
33 1         5 return $self ;
34             }
35              
36             =head2 encode_arguments
37              
38             internal function: encode the arguments into the url
39              
40             =cut
41              
42             sub encode_arguments {
43 1     1 1 2 my $self = shift ;
44            
45 1         10 my $rh_params = $self->{args} ;
46 1         10 my $url = URI->new( $self->{uri}, 'http' ) ;
47            
48 1 0       9368 unless ( &validate_arguments( $rh_params ) ) {
49 0         0 croak "Invalid or missing arguments\n" ;
50             }
51            
52 0         0 $url->query_form( %$rh_params ) ;
53 0         0 return $url ;
54            
55             }
56              
57             =head2 validate_arguments
58              
59             internal function: validate the query arguments
60              
61             =cut
62              
63             sub validate_arguments {
64 1     1 1 3 my $rh_params = shift ;
65              
66 1 50 33     13 return unless $rh_params
      33        
67             && defined $rh_params
68             && ref $rh_params eq 'HASH' ;
69            
70 1 0 33     29 unless ( exists $rh_params->{start} && defined $rh_params->{start}
      33        
      33        
      33        
      33        
      33        
      33        
      33        
      0        
      0        
      0        
71             && exists $rh_params->{number} && defined $rh_params->{number}
72             && exists $rh_params->{minlng} && defined $rh_params->{minlng}
73             && exists $rh_params->{minlat} && defined $rh_params->{minlat}
74             && exists $rh_params->{maxlng} && defined $rh_params->{maxlng}
75             && exists $rh_params->{maxlat} && defined $rh_params->{maxlat}
76             ) {
77 1         23 croak "Invalid or missing arguments.\nPlease reffer to the documentation for required arguments." ;
78             }
79            
80 0           return 1 ;
81              
82             }
83              
84             =head1 NAME
85              
86             WebService::Tagzania::API - Tagzania API Interface
87              
88             =head1 SYNOPSIS
89              
90             use WebService::Tagzania::API;
91             my $tagobj = new WebService::Tagzania::API() ;
92            
93             my $rh_params = {
94             start => 0,
95             number => 200,
96             minlng => -9.25,
97             minlat => 35.35,
98             maxlng => 4.55,
99             maxlat => 43.80,
100             } ;
101              
102             my $results = $api->query( $rh_params ) ;
103            
104             next unless
105             $results->{_msg} eq 'OK' ;
106            
107             my $content = $results->{_content} ;
108            
109             # do something with the XML inside $content
110              
111             =head1 DESCRIPTION
112              
113             Base class for the Tagzania API Request object.
114              
115             =head1 BUGS
116              
117             None.
118             That I know of ;)
119              
120             =head1 AUTHOR
121              
122             Spiros Denaxas
123             CPAN ID: SDEN
124             Lokku Ltd
125             s [dot] denaxas [@] gmail [dot]com
126             http://idaru.blogspot.com
127             http://www.nestoria.co.uk
128              
129             =head1 COPYRIGHT
130              
131             This program is free software; you can redistribute
132             it and/or modify it under the same terms as Perl itself.
133              
134             The full text of the license can be found in the
135             LICENSE file included with this module.
136              
137              
138             =head1 SEE ALSO
139              
140             L, L, L
141              
142             =cut
143              
144              
145             1 ;