File Coverage

blib/lib/WebService/Recruit/Aikento.pm
Criterion Covered Total %
statement 31 68 45.5
branch 3 24 12.5
condition 3 5 60.0
subroutine 9 14 64.2
pod 6 8 75.0
total 52 119 43.7


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