File Coverage

blib/lib/WebService/Recruit/Eyeco.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::Eyeco;
2              
3 2     2   46645 use strict;
  2         4  
  2         76  
4 2     2   11 use base qw( Class::Accessor::Fast );
  2         4  
  2         2004  
5 2     2   7458 use vars qw( $VERSION );
  2         3  
  2         121  
6             $VERSION = '0.0.1';
7              
8 2     2   1140 use WebService::Recruit::Eyeco::Item;
  2         8  
  2         25  
9 2     2   1464 use WebService::Recruit::Eyeco::LargeCategory;
  2         8  
  2         22  
10 2     2   1237 use WebService::Recruit::Eyeco::SmallCategory;
  2         6  
  2         19  
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 29 my $package = shift;
18 2         7 my $self = {@_};
19 2   33     25 $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 657 my $self = shift;
26 2   100     10 my $param = $self->param() || {};
27 2 50       42 %$param = ( %$param, @_ ) if scalar @_;
28 2         7 $self->param($param);
29             }
30              
31             sub get_param {
32 3     3 1 24 my $self = shift;
33 3         5 my $key = shift;
34 3 50       10 my $param = $self->param() or return;
35 3 50       54 $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::Eyeco::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::Eyeco::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::Eyeco::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::Eyeco - An Interface for Eyeco Web Service
96              
97             =head1 SYNOPSIS
98              
99             use WebService::Recruit::Eyeco;
100            
101             my $service = WebService::Recruit::Eyeco->new();
102            
103             my $param = {
104             'key' => $ENV{'WEBSERVICE_RECRUIT_KEY'},
105             'large_category' => '101',
106             'order' => '1',
107             'price_max' => '5000',
108             };
109             my $res = $service->item( %$param );
110             my $root = $res->root;
111             printf("api_version: %s\n", $root->api_version);
112             printf("results_available: %s\n", $root->results_available);
113             printf("results_returned: %s\n", $root->results_returned);
114             printf("results_start: %s\n", $root->results_start);
115             printf("item: %s\n", $root->item);
116             print "...\n";
117              
118             =head1 DESCRIPTION
119              
120             eyeco[アイコ]に掲載されている商品をさまざまな検索軸で探せる商品情報APIです。
121              
122             =head1 METHODS
123              
124             =head2 new
125              
126             This is the constructor method for this class.
127              
128             my $service = WebService::Recruit::Eyeco->new();
129              
130             This accepts optional parameters.
131              
132             my $conf = {
133             utf8_flag => 1,
134             param => {
135             # common parameters of this web service
136             },
137             };
138             my $service = WebService::Recruit::Eyeco->new( %$conf );
139              
140             =head2 add_param
141              
142             Add common parameter of tihs web service.
143              
144             $service->add_param( param_key => param_value );
145              
146             You can add multiple parameters by calling once.
147              
148             $service->add_param( param_key1 => param_value1,
149             param_key2 => param_value2,
150             ...);
151              
152             =head2 get_param
153              
154             Returns common parameter value of the specified key.
155              
156             my $param_value = $service->get( 'param_key' );
157              
158             =head2 item
159              
160             This makes a request for C API.
161             See L for details.
162              
163             my $res = $service->item( %$param );
164              
165             =head2 large_category
166              
167             This makes a request for C API.
168             See L for details.
169              
170             my $res = $service->large_category( %$param );
171              
172             =head2 small_category
173              
174             This makes a request for C API.
175             See L for details.
176              
177             my $res = $service->small_category( %$param );
178              
179             =head2 utf8_flag / user_agent / lwp_useragent / http_lite
180              
181             This modules uses L module internally.
182             Following methods are available to configure it.
183              
184             $service->utf8_flag( 1 );
185             $service->user_agent( 'Foo-Bar/1.0 ' );
186             $service->lwp_useragent( LWP::UserAgent->new() );
187             $service->http_lite( HTTP::Lite->new() );
188              
189             =head1 SEE ALSO
190              
191             http://webservice.recruit.co.jp/eyeco/
192              
193             =head1 AUTHOR
194              
195             RECRUIT Media Technology Labs
196              
197             =head1 COPYRIGHT
198              
199             Copyright 2008 RECRUIT Media Technology Labs
200              
201             =cut
202             1;