File Coverage

blib/lib/WebService/Recruit/HotPepper.pm
Criterion Covered Total %
statement 44 137 32.1
branch 0 48 0.0
condition 1 3 33.3
subroutine 14 26 53.8
pod 11 13 84.6
total 70 227 30.8


line stmt bran cond sub pod time code
1             package WebService::Recruit::HotPepper;
2 3     3   5509 use strict;
  3         10  
  3         132  
3 3     3   60 use base qw( Class::Accessor::Fast );
  3         6  
  3         3373  
4 3     3   20095 use vars qw( $VERSION );
  3         8  
  3         202  
5             $VERSION = '0.03';
6              
7 3     3   2440 use WebService::Recruit::HotPepper::GourmetSearch;
  3         15  
  3         51  
8 3     3   2475 use WebService::Recruit::HotPepper::ShopSearch;
  3         10  
  3         31  
9 3     3   2161 use WebService::Recruit::HotPepper::LargeServiceArea;
  3         9  
  3         28  
10 3     3   2485 use WebService::Recruit::HotPepper::ServiceArea;
  3         8  
  3         33  
11 3     3   2612 use WebService::Recruit::HotPepper::LargeArea;
  3         13  
  3         36  
12 3     3   4676 use WebService::Recruit::HotPepper::MiddleArea;
  3         11  
  3         33  
13 3     3   3261 use WebService::Recruit::HotPepper::SmallArea;
  3         11  
  3         31  
14 3     3   2604 use WebService::Recruit::HotPepper::Genre;
  3         9  
  3         33  
15 3     3   3834 use WebService::Recruit::HotPepper::Food;
  3         10  
  3         31  
16 3     3   2465 use WebService::Recruit::HotPepper::Budget;
  3         9  
  3         31  
17              
18             my $PARAMS = [qw( key Count Start )];
19             my $TPPCFG = [qw( user_agent lwp_useragent http_lite utf8_flag )];
20             __PACKAGE__->mk_accessors( @$PARAMS, @$TPPCFG );
21              
22             sub new {
23 2     2 1 1055 my $package = shift;
24 2         6 my $self = {@_};
25 2   33     26 $self->{user_agent} ||= __PACKAGE__."/$VERSION ";
26 2         7 bless $self, $package;
27 2         8 $self;
28             }
29              
30             sub init_treepp_config {
31 0     0 0   my $self = shift;
32 0           my $api = shift;
33 0           my $treepp = $api->treepp();
34 0           foreach my $key ( @$TPPCFG ) {
35 0 0         next unless exists $self->{$key};
36 0 0         next unless defined $self->{$key};
37 0           $treepp->set( $key => $self->{$key} );
38             }
39             }
40              
41             sub init_query_param {
42 0     0 0   my $self = shift;
43 0           my $api = shift;
44 0           foreach my $key ( @$PARAMS ) {
45 0 0         next unless exists $self->{$key};
46 0 0         next unless defined $self->{$key};
47 0           $api->add_param( $key => $self->{$key} );
48             }
49             }
50              
51             sub GourmetSearch {
52 0 0   0 1   my $self = shift or return;
53 0 0         $self = $self->new() unless ref $self;
54 0           my $api = WebService::Recruit::HotPepper::GourmetSearch->new();
55 0           $self->init_treepp_config( $api );
56 0           $self->init_query_param( $api );
57 0           $api->add_param( @_ );
58 0           $api->request();
59 0           $api;
60             }
61              
62             sub ShopSearch {
63 0 0   0 1   my $self = shift or return;
64 0 0         $self = $self->new() unless ref $self;
65 0           my $api = WebService::Recruit::HotPepper::ShopSearch->new();
66 0           $self->init_treepp_config( $api );
67 0           $self->init_query_param( $api );
68 0           $api->add_param( @_ );
69 0           $api->request();
70 0           $api;
71             }
72              
73             sub LargeServiceArea {
74 0 0   0 1   my $self = shift or return;
75 0 0         $self = $self->new() unless ref $self;
76 0           my $api = WebService::Recruit::HotPepper::LargeServiceArea->new();
77 0           $self->init_treepp_config( $api );
78 0           $self->init_query_param( $api );
79 0           $api->add_param( @_ );
80 0           $api->request();
81 0           $api;
82             }
83              
84             sub ServiceArea {
85 0 0   0 1   my $self = shift or return;
86 0 0         $self = $self->new() unless ref $self;
87 0           my $api = WebService::Recruit::HotPepper::ServiceArea->new();
88 0           $self->init_treepp_config( $api );
89 0           $self->init_query_param( $api );
90 0           $api->add_param( @_ );
91 0           $api->request();
92 0           $api;
93             }
94              
95             sub LargeArea {
96 0 0   0 1   my $self = shift or return;
97 0 0         $self = $self->new() unless ref $self;
98 0           my $api = WebService::Recruit::HotPepper::LargeArea->new();
99 0           $self->init_treepp_config( $api );
100 0           $self->init_query_param( $api );
101 0           $api->add_param( @_ );
102 0           $api->request();
103 0           $api;
104             }
105              
106             sub MiddleArea {
107 0 0   0 1   my $self = shift or return;
108 0 0         $self = $self->new() unless ref $self;
109 0           my $api = WebService::Recruit::HotPepper::MiddleArea->new();
110 0           $self->init_treepp_config( $api );
111 0           $self->init_query_param( $api );
112 0           $api->add_param( @_ );
113 0           $api->request();
114 0           $api;
115             }
116              
117             sub SmallArea {
118 0 0   0 1   my $self = shift or return;
119 0 0         $self = $self->new() unless ref $self;
120 0           my $api = WebService::Recruit::HotPepper::SmallArea->new();
121 0           $self->init_treepp_config( $api );
122 0           $self->init_query_param( $api );
123 0           $api->add_param( @_ );
124 0           $api->request();
125 0           $api;
126             }
127              
128             sub Genre {
129 0 0   0 1   my $self = shift or return;
130 0 0         $self = $self->new() unless ref $self;
131 0           my $api = WebService::Recruit::HotPepper::Genre->new();
132 0           $self->init_treepp_config( $api );
133 0           $self->init_query_param( $api );
134 0           $api->add_param( @_ );
135 0           $api->request();
136 0           $api;
137             }
138              
139             sub Food {
140 0 0   0 1   my $self = shift or return;
141 0 0         $self = $self->new() unless ref $self;
142 0           my $api = WebService::Recruit::HotPepper::Food->new();
143 0           $self->init_treepp_config( $api );
144 0           $self->init_query_param( $api );
145 0           $api->add_param( @_ );
146 0           $api->request();
147 0           $api;
148             }
149              
150             sub Budget {
151 0 0   0 1   my $self = shift or return;
152 0 0         $self = $self->new() unless ref $self;
153 0           my $api = WebService::Recruit::HotPepper::Budget->new();
154 0           $self->init_treepp_config( $api );
155 0           $self->init_query_param( $api );
156 0           $api->add_param( @_ );
157 0           $api->request();
158 0           $api;
159             }
160              
161             =head1 NAME
162              
163             WebService::Recruit::HotPepper - perl interface for HotPepper Web Service
164              
165             =head1 SYNOPSIS
166              
167             use WebService::Recruit::HotPepper;
168              
169             my $api = WebService::Recruit::HotPepper->new();
170             $api->key( 'xxxxxxxxxxxxxxxx' );
171              
172             my $param = {
173             ServiceAreaCD => 'SA11',
174             GenreCD => 'G002',
175             };
176             my $res = $api->GourmetSearch( %$param );
177             my $list = $res->root->Shop;
178             foreach my $shop ( @$list ) {
179             print "name: ", $shop->ShopName, "\n";
180             print "addr: ", $shop->ShopAddress, "\n";
181             print "photo: ", $shop->PictureUrl->PcLargeImg, "\n";
182             print "\n";
183             }
184              
185             =head1 DESCRIPTION
186              
187             This module is a perl interface for the HotPepper Web Service
188             (L), provided by Recruit Co., Ltd., Japan. It provides API methods: L, L, L, L, L, L, L, L, L, and L. With these methods, you can find restaurants and their discount coupons in Japan.
189              
190             =head1 METHODS
191              
192             =head2 new
193              
194             This is the constructor method for this class.
195              
196             my $api = WebService::Recruit::HotPepper->new();
197              
198             This accepts optional parameters.
199              
200             my $conf = { key => 'your_auth_key', utf8_flag => 1 };
201             my $api = WebService::Recruit::HotPepper->new( %$conf );
202              
203             =head2 key
204              
205             A valid developer key is required to make a request.
206              
207             $api->key( 'your_auth_key' );
208              
209             =head2 GourmetSearch
210              
211             This makes a request for C API.
212             See L for details.
213              
214             my $res = $api->GourmetSearch( ServiceAreaCD=>'SA11' );
215              
216             =head2 ShopSearch
217              
218             This makes a request for C API.
219             See L for details.
220              
221             my $res = $api->ShopSearch( Keyword=>'pizza' );
222              
223             =head2 LargeServiceArea
224              
225             This makes a request for C API.
226             See L for details.
227              
228             my $res = $api->LargeServiceArea();
229              
230             =head2 ServiceArea
231              
232             This makes a request for C API.
233             See L for details.
234              
235             my $res = $api->ServiceArea();
236              
237             =head2 LargeArea
238              
239             This makes a request for C API.
240             See L for details.
241              
242             my $res = $api->LargeArea();
243              
244             =head2 MiddleArea
245              
246             This makes a request for C API.
247             See L for details.
248              
249             my $res = $api->MiddleArea();
250              
251             =head2 SmallArea
252              
253             This makes a request for C API.
254             See L for details.
255              
256             my $res = $api->SmallArea();
257              
258             =head2 Genre
259              
260             This makes a request for C API.
261             See L for details.
262              
263             my $res = $api->Genre();
264              
265             =head2 Food
266              
267             This makes a request for C API.
268             See L for details.
269              
270             my $res = $api->Food();
271              
272             =head2 Budget
273              
274             This makes a request for C API.
275             See L for details.
276              
277             my $res = $api->Budget();
278              
279             =head2 utf8_flag / user_agent / lwp_useragent / http_lite
280              
281             This modules uses L module internally.
282             The following methods are available to configure it.
283              
284             $api->utf8_flag( 1 );
285             $api->user_agent( 'Foo-Bar/1.0 ' );
286             $api->lwp_useragent( LWP::UserAgent->new() );
287             $api->http_lite( HTTP::Lite->new() );
288              
289             =head1 SEE ALSO
290              
291             http://api.hotpepper.jp/
292              
293             =head1 AUTHOR
294              
295             Toshimasa Ishibashi L
296              
297             This module is unofficial and released by the author in person.
298              
299             =head1 THANKS TO
300              
301             Yusuke Kawasaki L
302              
303             For creating/preparing all the base modules and stuff.
304              
305             =head1 COPYRIGHT AND LICENSE
306              
307             Copyright (c) 2007 Toshimasa Ishibashi. All rights reserved.
308             This program is free software; you can redistribute it and/or
309             modify it under the same terms as Perl itself.
310              
311             =cut
312              
313             1;