File Coverage

blib/lib/WebService/Recruit/Akasugu.pm
Criterion Covered Total %
statement 37 90 41.1
branch 3 32 9.3
condition 3 5 60.0
subroutine 11 18 61.1
pod 8 10 80.0
total 62 155 40.0


line stmt bran cond sub pod time code
1             package WebService::Recruit::Akasugu;
2              
3 2     2   45853 use strict;
  2         6  
  2         91  
4 2     2   10 use base qw( Class::Accessor::Fast );
  2         4  
  2         1984  
5 2     2   6994 use vars qw( $VERSION );
  2         4  
  2         120  
6             $VERSION = '0.0.1';
7              
8 2     2   1975 use WebService::Recruit::Akasugu::Item;
  2         8  
  2         21  
9 2     2   1292 use WebService::Recruit::Akasugu::LargeCategory;
  2         5  
  2         17  
10 2     2   1119 use WebService::Recruit::Akasugu::MiddleCategory;
  2         7  
  2         20  
11 2     2   1241 use WebService::Recruit::Akasugu::SmallCategory;
  2         6  
  2         16  
12 2     2   1072 use WebService::Recruit::Akasugu::Age;
  2         4  
  2         18  
13              
14              
15             my $TPPCFG = [qw( user_agent lwp_useragent http_lite utf8_flag )];
16             __PACKAGE__->mk_accessors( @$TPPCFG, 'param' );
17              
18             sub new {
19 2     2 1 23 my $package = shift;
20 2         6 my $self = {@_};
21 2   33     20 $self->{user_agent} ||= __PACKAGE__."/$VERSION ";
22 2         5 bless $self, $package;
23 2         6 $self;
24             }
25              
26             sub add_param {
27 2     2 1 664 my $self = shift;
28 2   100     10 my $param = $self->param() || {};
29 2 50       36 %$param = ( %$param, @_ ) if scalar @_;
30 2         8 $self->param($param);
31             }
32              
33             sub get_param {
34 3     3 1 59 my $self = shift;
35 3         5 my $key = shift;
36 3 50       7 my $param = $self->param() or return;
37 3 50       35 $param->{$key} if exists $param->{$key};
38             }
39              
40             sub init_treepp_config {
41 0     0 0   my $self = shift;
42 0           my $api = shift;
43 0           my $treepp = $api->treepp();
44 0           foreach my $key ( @$TPPCFG ) {
45 0 0         next unless exists $self->{$key};
46 0 0         next unless defined $self->{$key};
47 0           $treepp->set( $key => $self->{$key} );
48             }
49             }
50              
51             sub init_query_param {
52 0     0 0   my $self = shift;
53 0           my $api = shift;
54 0           my $param = $self->param();
55 0           foreach my $key ( keys %$param ) {
56 0 0         next unless defined $param->{$key};
57 0           $api->add_param( $key => $param->{$key} );
58             }
59             }
60              
61             sub item {
62 0 0   0 1   my $self = shift or return;
63 0 0         $self = $self->new() unless ref $self;
64 0           my $api = WebService::Recruit::Akasugu::Item->new();
65 0           $self->init_treepp_config( $api );
66 0           $self->init_query_param( $api );
67 0           $api->add_param( @_ );
68 0           $api->request();
69 0           $api;
70             }
71              
72             sub large_category {
73 0 0   0 1   my $self = shift or return;
74 0 0         $self = $self->new() unless ref $self;
75 0           my $api = WebService::Recruit::Akasugu::LargeCategory->new();
76 0           $self->init_treepp_config( $api );
77 0           $self->init_query_param( $api );
78 0           $api->add_param( @_ );
79 0           $api->request();
80 0           $api;
81             }
82              
83             sub middle_category {
84 0 0   0 1   my $self = shift or return;
85 0 0         $self = $self->new() unless ref $self;
86 0           my $api = WebService::Recruit::Akasugu::MiddleCategory->new();
87 0           $self->init_treepp_config( $api );
88 0           $self->init_query_param( $api );
89 0           $api->add_param( @_ );
90 0           $api->request();
91 0           $api;
92             }
93              
94             sub small_category {
95 0 0   0 1   my $self = shift or return;
96 0 0         $self = $self->new() unless ref $self;
97 0           my $api = WebService::Recruit::Akasugu::SmallCategory->new();
98 0           $self->init_treepp_config( $api );
99 0           $self->init_query_param( $api );
100 0           $api->add_param( @_ );
101 0           $api->request();
102 0           $api;
103             }
104              
105             sub age {
106 0 0   0 1   my $self = shift or return;
107 0 0         $self = $self->new() unless ref $self;
108 0           my $api = WebService::Recruit::Akasugu::Age->new();
109 0           $self->init_treepp_config( $api );
110 0           $self->init_query_param( $api );
111 0           $api->add_param( @_ );
112 0           $api->request();
113 0           $api;
114             }
115              
116              
117             =head1 NAME
118              
119             WebService::Recruit::Akasugu - An Interface for Akasugu.net Web Service
120              
121             =head1 SYNOPSIS
122              
123             use WebService::Recruit::Akasugu;
124            
125             my $service = WebService::Recruit::Akasugu->new();
126            
127             my $param = {
128             'key' => $ENV{'WEBSERVICE_RECRUIT_KEY'},
129             'large_category_cd' => '2',
130             };
131             my $res = $service->item( %$param );
132             my $root = $res->root;
133             printf("api_version: %s\n", $root->api_version);
134             printf("results_available: %s\n", $root->results_available);
135             printf("results_returned: %s\n", $root->results_returned);
136             printf("results_start: %s\n", $root->results_start);
137             printf("item: %s\n", $root->item);
138             print "...\n";
139              
140             =head1 DESCRIPTION
141              
142             赤すぐnetに掲載されている商品をさまざまな検索軸で探せる商品情報APIです。
143              
144             =head1 METHODS
145              
146             =head2 new
147              
148             This is the constructor method for this class.
149              
150             my $service = WebService::Recruit::Akasugu->new();
151              
152             This accepts optional parameters.
153              
154             my $conf = {
155             utf8_flag => 1,
156             param => {
157             # common parameters of this web service
158             },
159             };
160             my $service = WebService::Recruit::Akasugu->new( %$conf );
161              
162             =head2 add_param
163              
164             Add common parameter of tihs web service.
165              
166             $service->add_param( param_key => param_value );
167              
168             You can add multiple parameters by calling once.
169              
170             $service->add_param( param_key1 => param_value1,
171             param_key2 => param_value2,
172             ...);
173              
174             =head2 get_param
175              
176             Returns common parameter value of the specified key.
177              
178             my $param_value = $service->get( 'param_key' );
179              
180             =head2 item
181              
182             This makes a request for C API.
183             See L for details.
184              
185             my $res = $service->item( %$param );
186              
187             =head2 large_category
188              
189             This makes a request for C API.
190             See L for details.
191              
192             my $res = $service->large_category( %$param );
193              
194             =head2 middle_category
195              
196             This makes a request for C API.
197             See L for details.
198              
199             my $res = $service->middle_category( %$param );
200              
201             =head2 small_category
202              
203             This makes a request for C API.
204             See L for details.
205              
206             my $res = $service->small_category( %$param );
207              
208             =head2 age
209              
210             This makes a request for C API.
211             See L for details.
212              
213             my $res = $service->age( %$param );
214              
215             =head2 utf8_flag / user_agent / lwp_useragent / http_lite
216              
217             This modules uses L module internally.
218             Following methods are available to configure it.
219              
220             $service->utf8_flag( 1 );
221             $service->user_agent( 'Foo-Bar/1.0 ' );
222             $service->lwp_useragent( LWP::UserAgent->new() );
223             $service->http_lite( HTTP::Lite->new() );
224              
225             =head1 SEE ALSO
226              
227             http://webservice.recruit.co.jp/akasugu/
228              
229             =head1 AUTHOR
230              
231             RECRUIT Media Technology Labs
232              
233             =head1 COPYRIGHT
234              
235             Copyright 2008 RECRUIT Media Technology Labs
236              
237             =cut
238             1;