File Coverage

blib/lib/WebService/Recruit/AkasuguUchiiwai.pm
Criterion Covered Total %
statement 34 79 43.0
branch 3 28 10.7
condition 3 5 60.0
subroutine 10 16 62.5
pod 7 9 77.7
total 57 137 41.6


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