File Coverage

blib/lib/WebService/Recruit/Shingaku.pm
Criterion Covered Total %
statement 40 101 39.6
branch 3 36 8.3
condition 3 5 60.0
subroutine 12 20 60.0
pod 9 11 81.8
total 67 173 38.7


line stmt bran cond sub pod time code
1             package WebService::Recruit::Shingaku;
2              
3 2     2   49289 use strict;
  2         6  
  2         91  
4 2     2   12 use base qw( Class::Accessor::Fast );
  2         3  
  2         1950  
5 2     2   6934 use vars qw( $VERSION );
  2         5  
  2         125  
6             $VERSION = '0.0.1';
7              
8 2     2   1159 use WebService::Recruit::Shingaku::School;
  2         7  
  2         30  
9 2     2   2483 use WebService::Recruit::Shingaku::Subject;
  2         7  
  2         24  
10 2     2   1419 use WebService::Recruit::Shingaku::Work;
  2         5  
  2         21  
11 2     2   1361 use WebService::Recruit::Shingaku::License;
  2         7  
  2         21  
12 2     2   1157 use WebService::Recruit::Shingaku::Pref;
  2         5  
  2         19  
13 2     2   1154 use WebService::Recruit::Shingaku::Category;
  2         6  
  2         19  
14              
15              
16             my $TPPCFG = [qw( user_agent lwp_useragent http_lite utf8_flag )];
17             __PACKAGE__->mk_accessors( @$TPPCFG, 'param' );
18              
19             sub new {
20 2     2 1 26 my $package = shift;
21 2         6 my $self = {@_};
22 2   33     23 $self->{user_agent} ||= __PACKAGE__."/$VERSION ";
23 2         6 bless $self, $package;
24 2         7 $self;
25             }
26              
27             sub add_param {
28 2     2 1 652 my $self = shift;
29 2   100     11 my $param = $self->param() || {};
30 2 50       41 %$param = ( %$param, @_ ) if scalar @_;
31 2         8 $self->param($param);
32             }
33              
34             sub get_param {
35 3     3 1 14 my $self = shift;
36 3         5 my $key = shift;
37 3 50       11 my $param = $self->param() or return;
38 3 50       36 $param->{$key} if exists $param->{$key};
39             }
40              
41             sub init_treepp_config {
42 0     0 0   my $self = shift;
43 0           my $api = shift;
44 0           my $treepp = $api->treepp();
45 0           foreach my $key ( @$TPPCFG ) {
46 0 0         next unless exists $self->{$key};
47 0 0         next unless defined $self->{$key};
48 0           $treepp->set( $key => $self->{$key} );
49             }
50             }
51              
52             sub init_query_param {
53 0     0 0   my $self = shift;
54 0           my $api = shift;
55 0           my $param = $self->param();
56 0           foreach my $key ( keys %$param ) {
57 0 0         next unless defined $param->{$key};
58 0           $api->add_param( $key => $param->{$key} );
59             }
60             }
61              
62             sub school {
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::Shingaku::School->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 subject {
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::Shingaku::Subject->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 work {
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::Shingaku::Work->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 license {
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::Shingaku::License->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 pref {
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::Shingaku::Pref->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 category {
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::Shingaku::Category->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              
129             =head1 NAME
130              
131             WebService::Recruit::Shingaku - An Interface for Recruit Shingaku net Web Service
132              
133             =head1 SYNOPSIS
134              
135             use WebService::Recruit::Shingaku;
136            
137             my $service = WebService::Recruit::Shingaku->new();
138            
139             my $param = {
140             'key' => $ENV{'WEBSERVICE_RECRUIT_KEY'},
141             'keyword' => '数学',
142             'pref_cd' => '12',
143             };
144             my $res = $service->school( %$param );
145             my $root = $res->root;
146             printf("api_version: %s\n", $root->api_version);
147             printf("results_available: %s\n", $root->results_available);
148             printf("results_returned: %s\n", $root->results_returned);
149             printf("results_start: %s\n", $root->results_start);
150             printf("school: %s\n", $root->school);
151             print "...\n";
152              
153             =head1 DESCRIPTION
154              
155             リクルート進学ネットに掲載されている学校および各種学問・仕事・資格を様々な軸で検索できるAPIです。
156              
157             =head1 METHODS
158              
159             =head2 new
160              
161             This is the constructor method for this class.
162              
163             my $service = WebService::Recruit::Shingaku->new();
164              
165             This accepts optional parameters.
166              
167             my $conf = {
168             utf8_flag => 1,
169             param => {
170             # common parameters of this web service
171             },
172             };
173             my $service = WebService::Recruit::Shingaku->new( %$conf );
174              
175             =head2 add_param
176              
177             Add common parameter of tihs web service.
178              
179             $service->add_param( param_key => param_value );
180              
181             You can add multiple parameters by calling once.
182              
183             $service->add_param( param_key1 => param_value1,
184             param_key2 => param_value2,
185             ...);
186              
187             =head2 get_param
188              
189             Returns common parameter value of the specified key.
190              
191             my $param_value = $service->get( 'param_key' );
192              
193             =head2 school
194              
195             This makes a request for C API.
196             See L for details.
197              
198             my $res = $service->school( %$param );
199              
200             =head2 subject
201              
202             This makes a request for C API.
203             See L for details.
204              
205             my $res = $service->subject( %$param );
206              
207             =head2 work
208              
209             This makes a request for C API.
210             See L for details.
211              
212             my $res = $service->work( %$param );
213              
214             =head2 license
215              
216             This makes a request for C API.
217             See L for details.
218              
219             my $res = $service->license( %$param );
220              
221             =head2 pref
222              
223             This makes a request for C API.
224             See L for details.
225              
226             my $res = $service->pref( %$param );
227              
228             =head2 category
229              
230             This makes a request for C API.
231             See L for details.
232              
233             my $res = $service->category( %$param );
234              
235             =head2 utf8_flag / user_agent / lwp_useragent / http_lite
236              
237             This modules uses L module internally.
238             Following methods are available to configure it.
239              
240             $service->utf8_flag( 1 );
241             $service->user_agent( 'Foo-Bar/1.0 ' );
242             $service->lwp_useragent( LWP::UserAgent->new() );
243             $service->http_lite( HTTP::Lite->new() );
244              
245             =head1 SEE ALSO
246              
247             http://webservice.recruit.co.jp/shingaku/
248              
249             =head1 AUTHOR
250              
251             RECRUIT Media Technology Labs
252              
253             =head1 COPYRIGHT
254              
255             Copyright 2008 RECRUIT Media Technology Labs
256              
257             =cut
258             1;