blib/lib/WebService/Zoopla/API.pm

filter: Statementstmt 39.5% 17 / 43 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 33.3% 3 / 9 Podpod n/a totaltotal 34.4% 20 / 58 CC 4 SCAR 15.9
CC
4
Cov
35%
AUTOLOAD
12.0
_call
6.0
__ANON__
2.0
CRAP 4.9
↑ Summary
1 package WebService::Zoopla::API;
2 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Net::HTTP::Spore;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 our $AUTOLOAD;
5 1 our $VERSION = '0.001';
6 1 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # ABSTRACT: Perl interface to the Zoopla API
9  
10 1 has api_key => (is => 'ro', isa => 'Str', required => 1);
11 1 has specification => (
12 is => 'ro',
13 isa => 'Str',
14 default => '{
15 "name" : "Zoopla",
16 "meta" : {
17 "documentation" : "http://developer.zoopla.com/docs"
18 },
19 "base_url" : "http://api.zoopla.co.uk/api/v1",
20 "version" : "1",
21 "methods" : {
22 "zed_index" : {
23 "required_params" : [
24 "api_key",
25 "output_type"
26 ],
27 "optional_params" : [
28 "session_id",
29 "area",
30 "street",
31 "town",
32 "postcode",
33 "county",
34 "latitude",
35 "longitude"
36 ],
37 "path" : "/zed_index.js",
38 "method" : "GET"
39 },
40 "area_value_graphs" : {
41 "required_params" : [
42 "api_key"
43 ],
44 "optional_params" : [
45 "session_id",
46 "area",
47 "street",
48 "town",
49 "postcode",
50 "county",
51 "latitude",
52 "longitude",
53 "size",
54 "output_type"
55 ],
56 "path":"/area_value_graphs.js",
57 "method" : "GET"
58 },
59 "richlist" : {
60 "required_params" : [
61 "api_key",
62 "output_type",
63 "area_type"
64 ],
65 "optional_params" : [
66 "session_id",
67 "area",
68 "street",
69 "town",
70 "postcode",
71 "county",
72 "latitude",
73 "longitude"
74 ],
75 "path":"/richlist.js",
76 "method" : "GET"
77 },
78 "average_area_sold_price" : {
79 "required_params" : [
80 "api_key",
81 "output_type"
82 ],
83 "optional_params" : [
84 "session_id",
85 "area",
86 "street",
87 "town",
88 "postcode",
89 "county",
90 "latitude",
91 "longitude"
92 ],
93 "path":"/average_area_sold_price.js",
94 "method" : "GET"
95 },
96 "zed_indices" : {
97 "required_params" : [
98 "api_key",
99 "output_type",
100 "area_type"
101 ],
102 "optional_params" : [
103 "session_id",
104 "area",
105 "street",
106 "town",
107 "postcode",
108 "county",
109 "latitude",
110 "longitude",
111 "ordering",
112 "page_number",
113 "page_size"
114 ],
115 "path":"/zed_indices.js",
116 "method" : "GET"
117 },
118 "zoopla_estimates" : {
119 "required_params" : [
120 "api_key"
121 ],
122 "optional_params" : [
123 "session_id",
124 "area",
125 "street",
126 "town",
127 "postcode",
128 "county",
129 "latitude",
130 "longitude",
131 "property_id",
132 "order_by",
133 "ordering",
134 "page_number",
135 "page_size",
136 "output_type"
137 ],
138 "path":"/zoopla_estimates.js",
139 "method" : "GET"
140 },
141 "property_listings" : {
142 "required_params" : [
143 "api_key"
144 ],
145 "optional_params" : [
146 "session_id",
147 "area",
148 "street",
149 "town",
150 "postcode",
151 "county",
152 "latitude",
153 "longitude",
154 "property_type",
155 "radius",
156 "order_by",
157 "ordering",
158 "page_number",
159 "page_size",
160 "output_type",
161 "listing_status",
162 "include_sold",
163 "include_rented",
164 "minimum_price",
165 "maximum_price",
166 "minimum_beds",
167 "maximum_beds",
168 "furnished",
169 "keywords",
170 "listing_id"
171 ],
172 "path":"/property_listings.js",
173 "method" : "GET"
174 },
175 "get_session_id" : {
176 "required_params" : [
177 "api_key"
178 ],
179 "path":"/get_session_id.js",
180 "method" : "GET"
181 },
182 "refine_estimate" : {
183 "required_params" : [
184 "api_key",
185 "property_id",
186 "property_type",
187 "tenure",
188 "num_bedrooms",
189 "num_bathrooms",
190 "num_receptions",
191 "session_id"
192 ],
193 "optional_params" : [
194 "area",
195 "street",
196 "town",
197 "postcode",
198 "county",
199 "latitude",
200 "longitude",
201 "output_type"
202 ],
203 "path":"/refine_estimate.js",
204 "method" : "GET"
205 },
206 "arrange_viewing" : {
207 "required_params" : [
208 "api_key",
209 "listing_id",
210 "name",
211 "email",
212 "phone",
213 "phone_type",
214 "best_time_to_call",
215 "message",
216 "session_id"
217 ],
218 "path":"/arrange_viewing.js",
219 "method" : "GET"
220 },
221 "average_sold_prices" : {
222 "required_params" : [
223 "api_key"
224 ],
225 "optional_params" : [
226 "session_id",
227 "area",
228 "street",
229 "town",
230 "postcode",
231 "county",
232 "latitude",
233 "longitude",
234 "area_type",
235 "page_number",
236 "page_size",
237 "ordering",
238 "output_type"
239 ],
240 "path":"/zoopla_estimates.js",
241 "method" : "GET"
242 }
243 },
244 "formats" : [
245 "json",
246 "xml"
247 ]
248 }'
249 );
250  
251 has api => (
252 is => 'ro',
253 lazy => 1,
254 isa => 'Object',
255 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
256 0 my $self = shift;
257 0 Net::HTTP::Spore->new_from_strings($self->specification)
258 ->enable('Format::JSON')->enable('Runtime');
259 }
260 1 );
261  
262 has session_id => (
263 is => 'ro',
264 lazy => 1,
265 isa => 'Str',
266 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
267 0 my $self = shift;
268 0 $self->_call('get_session_id', @_)->{'session_id'};
269 }
270 1 );
271  
272 1 __PACKAGE__->meta->make_immutable;
273  
274 0 ▶sub _call {
Subroutine _call: not called CC=2 SCAR=17.9
275 0 my $self = shift;
276 0 my $method = shift;
277 0 my $attrs = shift;
278 0 $attrs->{api_key} = $self->api_key;
279 0 $attrs->{format} = 'json';
280 0 ▶ $attrs->{session_id} = $self->session_id
Branch: 1 branch
BranchTrueFalseTotal
if $self->_need_session($method) 0 0 0
281 if ($self->_need_session($method));
282 0 return $self->api->$method(%{$attrs})->body;
283 }
284  
285 0 ▶sub _need_session {
Subroutine _need_session: not called CC=1 SCAR=6.9
286 0 my $self = shift;
287 0 my $method = shift;
288 0 ▶ return first { $_ eq 'session_id' } (
Subroutine __ANON__: not called CC=1 SCAR=6.9
289 @{ $self->api->meta->{methods}->{$method}
290 ->get_original_method->meta->{optional_params}
291 0 },
292 0 @{ $self->api->meta->{methods}->{$method}
293 ->get_original_method->meta->{required_params}
294 0 }
295 );
296 }
297  
298 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=3 SCAR=24.8
299 0 my $self = shift;
300 0 ▶ ref($self) || die "$self is not an object";
Branch: 1 branch
BranchTrueFalseTotal
ref $self or die "$self is not an object" 0 0 0
301 0 my $method = $AUTOLOAD;
302 0 $method =~ s/.*://;
303 die "Can't call $method()"
304 0 ▶ unless grep { $_ eq $method } @{$self->api->meta->local_spore_methods};
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $method;} @{$self->api->meta->local_spore_methods;} 0 0 0
305 0 return $self->_call($method, @_);
306 }
307  
308 1 1;
309  
310  
311 =pod
312  
313 =head1 NAME
314  
315 WebService::Zoopla::API - Perl interface to the Zoopla API
316  
317 =head1 VERSION
318  
319 version 0.001
320  
321 =head1 SYNOPSIS
322  
323 use WebService::Zoopla::API;
324  
325 my $zoopla = WebService::Zoopla::API->new(
326 api_key => 'xxxxxx');
327  
328 my $result = $zoopla->zed_index({area=>'SE4', output_type=>"outcode"});
329  
330 =head1 Constructor
331  
332 =head2 new()
333  
334 Creates and returns a new WebService::Zoopla::API object
335  
336 my $zoopla = WebService::Zoopla::API->new(
337 api_key => 'xxxxxx');
338  
339 =over 4
340  
341 =item * C<< api_key => 'xxxxx' >>
342  
343 Set the api key. This can be set up at:
344 http://developer.zoopla.com
345  
346 =back
347  
348 =head1 METHODS
349  
350 =head2 arrange_viewing
351  
352 =over 4
353  
354 Required Parameters
355  
356 =over 4
357  
358 =item * C<< api_key >>
359  
360 =item * C<< listing_id >>
361  
362 =item * C<< name >>
363  
364 =item * C<< email >>
365  
366 =item * C<< phone >>
367  
368 =item * C<< phone_type >>
369  
370 =item * C<< best_time_to_call >>
371  
372 =item * C<< message >>
373  
374 =item * C<< session_id >>
375  
376 =back
377  
378 =back
379  
380 =head2 average_area_sold_price
381  
382 =over 4
383  
384 Required Parameters
385  
386 =over 4
387  
388 =item * C<< api_key >>
389  
390 =item * C<< output_type >>
391  
392 =back
393  
394 =back
395  
396 =over 4
397  
398 Optional Parameters
399  
400 =over 4
401  
402 =item * C<< session_id >>
403  
404 =item * C<< area >>
405  
406 =item * C<< street >>
407  
408 =item * C<< town >>
409  
410 =item * C<< postcode >>
411  
412 =item * C<< county >>
413  
414 =item * C<< latitude >>
415  
416 =item * C<< longitude >>
417  
418 =back
419  
420 =back
421  
422 =head2 richlist
423  
424 =over 4
425  
426 Required Parameters
427  
428 =over 4
429  
430 =item * C<< api_key >>
431  
432 =item * C<< output_type >>
433  
434 =item * C<< area_type >>
435  
436 =back
437  
438 =back
439  
440 =over 4
441  
442 Optional Parameters
443  
444 =over 4
445  
446 =item * C<< session_id >>
447  
448 =item * C<< area >>
449  
450 =item * C<< street >>
451  
452 =item * C<< town >>
453  
454 =item * C<< postcode >>
455  
456 =item * C<< county >>
457  
458 =item * C<< latitude >>
459  
460 =item * C<< longitude >>
461  
462 =back
463  
464 =back
465  
466 =head2 property_listings
467  
468 =over 4
469  
470 Required Parameters
471  
472 =over 4
473  
474 =item * C<< api_key >>
475  
476 =back
477  
478 =back
479  
480 =over 4
481  
482 Optional Parameters
483  
484 =over 4
485  
486 =item * C<< session_id >>
487  
488 =item * C<< area >>
489  
490 =item * C<< street >>
491  
492 =item * C<< town >>
493  
494 =item * C<< postcode >>
495  
496 =item * C<< county >>
497  
498 =item * C<< latitude >>
499  
500 =item * C<< longitude >>
501  
502 =item * C<< property_type >>
503  
504 =item * C<< radius >>
505  
506 =item * C<< order_by >>
507  
508 =item * C<< ordering >>
509  
510 =item * C<< page_number >>
511  
512 =item * C<< page_size >>
513  
514 =item * C<< output_type >>
515  
516 =item * C<< listing_status >>
517  
518 =item * C<< include_sold >>
519  
520 =item * C<< include_rented >>
521  
522 =item * C<< minimum_price >>
523  
524 =item * C<< maximum_price >>
525  
526 =item * C<< minimum_beds >>
527  
528 =item * C<< maximum_beds >>
529  
530 =item * C<< furnished >>
531  
532 =item * C<< keywords >>
533  
534 =item * C<< listing_id >>
535  
536 =back
537  
538 =back
539  
540 =head2 area_value_graphs
541  
542 =over 4
543  
544 Required Parameters
545  
546 =over 4
547  
548 =item * C<< api_key >>
549  
550 =back
551  
552 =back
553  
554 =over 4
555  
556 Optional Parameters
557  
558 =over 4
559  
560 =item * C<< session_id >>
561  
562 =item * C<< area >>
563  
564 =item * C<< street >>
565  
566 =item * C<< town >>
567  
568 =item * C<< postcode >>
569  
570 =item * C<< county >>
571  
572 =item * C<< latitude >>
573  
574 =item * C<< longitude >>
575  
576 =item * C<< size >>
577  
578 =item * C<< output_type >>
579  
580 =back
581  
582 =back
583  
584 =head2 zed_index
585  
586 =over 4
587  
588 Required Parameters
589  
590 =over 4
591  
592 =item * C<< api_key >>
593  
594 =item * C<< output_type >>
595  
596 =back
597  
598 =back
599  
600 =over 4
601  
602 Optional Parameters
603  
604 =over 4
605  
606 =item * C<< session_id >>
607  
608 =item * C<< area >>
609  
610 =item * C<< street >>
611  
612 =item * C<< town >>
613  
614 =item * C<< postcode >>
615  
616 =item * C<< county >>
617  
618 =item * C<< latitude >>
619  
620 =item * C<< longitude >>
621  
622 =back
623  
624 =back
625  
626 =head2 get_session_id
627  
628 =over 4
629  
630 Required Parameters
631  
632 =over 4
633  
634 =item * C<< api_key >>
635  
636 =back
637  
638 =back
639  
640 =head2 zoopla_estimates
641  
642 =over 4
643  
644 Required Parameters
645  
646 =over 4
647  
648 =item * C<< api_key >>
649  
650 =back
651  
652 =back
653  
654 =over 4
655  
656 Optional Parameters
657  
658 =over 4
659  
660 =item * C<< session_id >>
661  
662 =item * C<< area >>
663  
664 =item * C<< street >>
665  
666 =item * C<< town >>
667  
668 =item * C<< postcode >>
669  
670 =item * C<< county >>
671  
672 =item * C<< latitude >>
673  
674 =item * C<< longitude >>
675  
676 =item * C<< property_id >>
677  
678 =item * C<< order_by >>
679  
680 =item * C<< ordering >>
681  
682 =item * C<< page_number >>
683  
684 =item * C<< page_size >>
685  
686 =item * C<< output_type >>
687  
688 =back
689  
690 =back
691  
692 =head2 average_sold_prices
693  
694 =over 4
695  
696 Required Parameters
697  
698 =over 4
699  
700 =item * C<< api_key >>
701  
702 =back
703  
704 =back
705  
706 =over 4
707  
708 Optional Parameters
709  
710 =over 4
711  
712 =item * C<< session_id >>
713  
714 =item * C<< area >>
715  
716 =item * C<< street >>
717  
718 =item * C<< town >>
719  
720 =item * C<< postcode >>
721  
722 =item * C<< county >>
723  
724 =item * C<< latitude >>
725  
726 =item * C<< longitude >>
727  
728 =item * C<< area_type >>
729  
730 =item * C<< page_number >>
731  
732 =item * C<< page_size >>
733  
734 =item * C<< ordering >>
735  
736 =item * C<< output_type >>
737  
738 =back
739  
740 =back
741  
742 =head2 refine_estimate
743  
744 =over 4
745  
746 Required Parameters
747  
748 =over 4
749  
750 =item * C<< api_key >>
751  
752 =item * C<< property_id >>
753  
754 =item * C<< property_type >>
755  
756 =item * C<< tenure >>
757  
758 =item * C<< num_bedrooms >>
759  
760 =item * C<< num_bathrooms >>
761  
762 =item * C<< num_receptions >>
763  
764 =item * C<< session_id >>
765  
766 =back
767  
768 =back
769  
770 =over 4
771  
772 Optional Parameters
773  
774 =over 4
775  
776 =item * C<< area >>
777  
778 =item * C<< street >>
779  
780 =item * C<< town >>
781  
782 =item * C<< postcode >>
783  
784 =item * C<< county >>
785  
786 =item * C<< latitude >>
787  
788 =item * C<< longitude >>
789  
790 =item * C<< output_type >>
791  
792 =back
793  
794 =back
795  
796 =head2 zed_indices
797  
798 =over 4
799  
800 Required Parameters
801  
802 =over 4
803  
804 =item * C<< api_key >>
805  
806 =item * C<< output_type >>
807  
808 =item * C<< area_type >>
809  
810 =back
811  
812 =back
813  
814 =over 4
815  
816 Optional Parameters
817  
818 =over 4
819  
820 =item * C<< session_id >>
821  
822 =item * C<< area >>
823  
824 =item * C<< street >>
825  
826 =item * C<< town >>
827  
828 =item * C<< postcode >>
829  
830 =item * C<< county >>
831  
832 =item * C<< latitude >>
833  
834 =item * C<< longitude >>
835  
836 =item * C<< ordering >>
837  
838 =item * C<< page_number >>
839  
840 =item * C<< page_size >>
841  
842 =back
843  
844 =back
845  
846 =head1 SEE ALSO
847  
848 L<Net::HTTP::Spore>
849  
850 =head1 INTERNAL METHODS
851  
852 =head2 _call($args)
853  
854 General method for calling the methods on the api
855 You don't need to call this directly
856  
857 =head2 _need_session($method)
858  
859 Internal method to check if a method needs a session id
860  
861 =head1 AUTHOR
862  
863 Willem Basson <willem.basson@gmail.com>
864  
865 =head1 COPYRIGHT AND LICENSE
866  
867 This software is copyright (c) 2011 by Willem Basson.
868  
869 This is free software; you can redistribute it and/or modify it under
870 the same terms as the Perl 5 programming language system itself.
871  
872 =cut
873  
874  
875 __END__
↑ Summary