File Coverage

blib/lib/WebService/Careerjet.pm
Criterion Covered Total %
statement 24 52 46.1
branch 0 8 0.0
condition 0 2 0.0
subroutine 8 11 72.7
pod 2 2 100.0
total 34 75 45.3


line stmt bran cond sub pod time code
1             package WebService::Careerjet;
2              
3 1     1   14941 use warnings;
  1         2  
  1         24  
4 1     1   3 use strict;
  1         1  
  1         23  
5              
6 1     1   3 use base qw/Class::AutoAccess/;
  1         4  
  1         354  
7              
8 1     1   632 use URI::Escape;
  1         867  
  1         44  
9 1     1   630 use LWP::UserAgent;
  1         32167  
  1         24  
10 1     1   5 use HTTP::Request;
  1         1  
  1         14  
11 1     1   3 use Carp;
  1         1  
  1         52  
12 1     1   516 use JSON;
  1         7534  
  1         3  
13              
14             =head1 NAME
15              
16             WebService::Careerjet - Perl interface to Careerjet's public job offers search API
17              
18             =head1 VERSION
19              
20             Version 3.0
21              
22             =cut
23              
24             our $VERSION = '3.0';
25              
26             =head1 SYNOPSIS
27              
28             This module provides a Perl interface to the public search API of Careerjet,
29             a vertical search engine for job offers that features job offers in over 60 countries.
30             (http://www.careerjet.co.uk/?worldwide)
31              
32             Command line tool:
33              
34             jobsearch [ -L ] [ -d ] [ -p ] [ -n ] [ -l ]
35             jobsearch -h
36              
37             Example code:
38              
39             use WebService::Careerjet;
40              
41             # Create Perl interface to API
42             my $careerjet = WebService::Careerjet->new('en_GB');
43              
44             # Perform a search
45             my $result = $careerjet->search({
46             'keywords' => 'perl developer',
47             'location' => 'london',
48             'affid' => '0afaf0173305e4b9',
49             'user_ip' => '11.22.33.44',
50             'user_agent' => 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0',
51             });
52              
53             # Go through results
54             if ($result->{'type'} eq 'JOBS') {
55             print "Found ". $result->{'hits'}. " jobs\n";
56             my $jobs = $result->{'jobs'};
57              
58             foreach my $j(@$jobs) {
59             print "URL :".$j->{'url'}."\n";
60             print "TITLE :".$j->{'title'}."\n";
61             print "COMPANY :".$j->{'company'}."\n";
62             print "SALARY :".$j->{'salary'}."\n";
63             print "DATE :".$j->{'date'}."\n";
64             print "DESCRIPTION :".$j->{'description'}."\n";
65             print "SITE :".$j->{'site'}."\n";
66             print "LOCATIONS :".$j->{'locations'}."\n";
67             print "\n";
68             }
69             }
70              
71             =head2 PROXY SETTINGS
72            
73             This module uses LWP::UserAgent for web access. Please refer to the LWP documentation
74             for proxy settings.
75              
76             =cut
77              
78             =head1 FUNCTIONS
79              
80             =head2 new
81              
82             Creates a Webservice::Careerjet search object for a given UNIX locale.
83             Each locale corresponds to an existing Careerjet site and determines
84             which language job-related information is returned as well
85             as which default location filter is used. For example, if your users
86             are primarily Dutch-speaking Belgians use "nl_BE".
87              
88             First two letters : ISO 639-1 alpha-2 language code
89              
90             See http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
91              
92             Last two letters : ISO 3166-1 alpha-2 country code
93              
94             See http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
95              
96              
97             Usage:
98             my $careerjet = WebService::Careerjet->new($locale);
99              
100             Available locales:
101              
102             LOCALE LANGUAGE DEFAULT LOCATION CAREERJET SITE
103             cs_CZ Czech Czech Republic http://www.careerjet.cz
104             da_DK Danish Denmark http://www.careerjet.dk
105             de_AT German Austria http://www.careerjet.at
106             de_CH German Switzerland http://www.careerjet.ch
107             de_DE German Germany http://www.careerjet.de
108             en_AE English United Arab Emirates http://www.careerjet.ae
109             en_AU English Australia http://www.careerjet.com.au
110             en_BD English Bangladesh http://www.careerjet.com.bd
111             en_CA English Canada http://www.careerjet.ca
112             en_CN English China http://en.careerjet.cn
113             en_HK English Hong Kong http://www.careerjet.hk
114             en_IE English Ireland http://www.careerjet.ie
115             en_IN English India http://www.careerjet.co.in
116             en_KW English Kuwait http://www.careerjet.com.kw
117             en_MY English Malaysia http://www.careerjet.com.my
118             en_NZ English New Zealand http://www.careerjet.co.nz
119             en_OM English Oman http://www.careerjet.com.om
120             en_PH English Philippines http://www.careerjet.ph
121             en_PK English Pakistan http://www.careerjet.com.pk
122             en_QA English Qatar http://www.careerjet.com.qa
123             en_SG English Singapore http://www.careerjet.sg
124             en_GB English United Kingdom http://www.careerjet.co.uk
125             en_US English United States http://www.careerjet.com
126             en_ZA English South Africa http://www.careerjet.co.za
127             en_SA English Saudi Arabia http://www.careerjet-saudi-arabia.com
128             en_TW English Taiwan http://www.careerjet.com.tw
129             en_VN English Vietnam http://www.careerjet.vn
130             es_AR Spanish Argentina http://www.opcionempleo.com.ar
131             es_BO Spanish Bolivia http://www.opcionempleo.com.bo
132             es_CL Spanish Chile http://www.opcionempleo.cl
133             es_CO Spanish Colombia http://www.opcionempleo.com.co
134             es_CR Spanish Costa Rica http://www.opcionempleo.co.cr
135             es_DO Spanish Dominican Republic http://www.opcionempleo.com.do
136             es_EC Spanish Ecuador http://www.opcionempleo.ec
137             es_ES Spanish Spain http://www.opcionempleo.com
138             es_GT Spanish Guatemala http://www.opcionempleo.com.gt
139             es_MX Spanish Mexico http://www.opcionempleo.com.mx
140             es_PA Spanish Panama http://www.opcionempleo.com.pa
141             es_PE Spanish Peru http://www.opcionempleo.com.pe
142             es_PR Spanish Puerto Rico http://www.opcionempleo.com.pr
143             es_PY Spanish Paraguay http://www.opcionempleo.com.py
144             es_UY Spanish Uruguay http://www.opcionempleo.com.uy
145             es_VE Spanish Venezuela http://www.opcionempleo.com.ve
146             fi_FI Finnish Finland http://www.careerjet.fi
147             fr_CA French Canada http://fr.careerjet.ca
148             fr_BE French Belgium http://www.optioncarriere.be
149             fr_CH French Switzerland http://www.optioncarriere.ch
150             fr_FR French France http://www.optioncarriere.com
151             fr_LU French Luxembourg http://www.optioncarriere.lu
152             fr_MA French Morocco http://www.optioncarriere.ma
153             hu_HU Hungarian Hungary http://www.careerjet.hu
154             it_IT Italian Italy http://www.careerjet.it
155             ja_JP Japanese Japan http://www.careerjet.jp
156             ko_KR Korean Korea http://www.careerjet.co.kr
157             nl_BE Dutch Belgium http://www.careerjet.be
158             nl_NL Dutch Netherlands http://www.careerjet.nl
159             no_NO Norwegian Norway http://www.careerjet.no
160             pl_PL Polish Poland http://www.careerjet.pl
161             pt_PT Portuguese Portugal http://www.careerjet.pt
162             pt_BR Portuguese Brazil http://www.careerjet.com.br
163             ru_RU Russian Russia http://www.careerjet.ru
164             ru_UA Russian Ukraine http://www.careerjet.com.ua
165             sv_SE Swedish Sweden http://www.careerjet.se
166             sk_SK Slovak Slovakia http://www.careerjet.sk
167             tr_TR Turkish Turkey http://www.careerjet.com.tr
168             uk_UA Ukrainian Ukraine http://www.careerjet.ua
169             vi_VN Vietnamese Vietnam http://www.careerjet.com.vn
170             zh_CN Chinese China http://www.careerjet.cn
171              
172              
173             =head2 agent
174              
175             Gets/sets the LWP::UserAgent to be used in the API calls.
176              
177             Usage:
178              
179             $this->agent();
180             $this->agent($myAgent);
181              
182             =cut
183              
184             sub new {
185 0     0 1   my ($class, $locale) = @_;
186 0   0       $locale ||= 'en_GB';
187              
188 0           my $ua = LWP::UserAgent->new();
189 0           $ua->agent('careerjet-api-client-v' . $VERSION . '-perl-v' . $]);
190              
191 0           my $self = {
192             'locale' => $locale,
193             'agent' => $ua,
194             'debug' => 0,
195             };
196              
197 0           return bless $self, $class;
198             }
199              
200             =head2 debug
201              
202             Enables/disables debug mode
203              
204             Usage:
205              
206             ## enable debug mode
207             $careerjet->debug(1);
208              
209             ## disable debug mode
210             $careerjet->debug(0);
211              
212             =cut
213              
214             sub _call {
215 0     0     my ($self, $function, $args) = @_;
216              
217 0           my $url = "http://public.api.careerjet.net/$function?locale_code=" . $self->{locale};
218 0           foreach my $k (keys %$args) {
219 0           $url .= '&' . $k . '=' . URI::Escape::uri_escape_utf8($args->{$k});
220             }
221              
222 0 0         print "GETTING " . $url . "\n" if ($self->debug());
223 0           my $req = HTTP::Request->new('GET' => $url);
224              
225 0           my $ret = undef;
226              
227 0           my $res = $self->{'agent'}->request($req);
228 0 0         if ($res->is_success()) {
229 0           my $content = $res->content();
230 0           my $json = new JSON;
231 0           $ret = $json->decode($content);
232             } else {
233 0           $ret->{'type'} = 'ERROR';
234 0           $ret->{'error'} = $res->status_line();
235             }
236              
237 0 0         unless (defined $ret) {
238 0           $ret = {
239             'type' => 'ERROR',
240             'error' => 'Json parsing error'
241             };
242             }
243              
244 0           return $ret;
245              
246             }
247              
248             =head2 search
249              
250             Performs a search using Careerjet's public search API.
251             Search parameters are passed on as a reference to a hash.
252              
253             The end-users IP address and user agent are mandatory parameters.
254             Also a Careerjet affiliate ID is required.
255              
256             Example:
257            
258             my $result = $api->search({
259             'keywords' => 'perl developer',
260             'location' => 'london',
261             'user_ip' => '11.22.33.44',
262             'user_agent' => 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0',
263             });
264              
265             # The result is a job list if the location is not ambiguous
266             if ($result->{'type'} eq 'JOBS') {
267             print "Found ". $result->{'hits'}. " jobs\n";
268             print "Total number of result pages: ". $result->{'pages'}. "\n";
269             my $jobs = $result->{'jobs'};
270             foreach my $j (@$jobs) {
271             print "URL :".$j->{'url'}."\n";
272             print "TITLE :".$j->{'title'}."\n";
273             print "COMPANY :".$j->{'company'}."\n";
274             print "SALARY :".$j->{'salary'}."\n";
275             print "DATE :".$j->{'date'}."\n";
276             print "DESCRIPTION :".$j->{'description'}."\n";
277             print "SITE :".$j->{'site'}."\n";
278             print "\n" ;
279             }
280            
281             }
282              
283             # If the location is ambiguous, a list of suggested locations
284             # is returned
285             if ($result->{'type'} eq 'LOCATIONS') {
286             print "Suggested locations:\n" ;
287             my $locations = $result->{'solveLocations'};
288             foreach my $l (@$locations) {
289             print $l->{'name'}."\n" ; ## For end-user display
290             ## Use $l->{'location_id'} when making next search call
291             ## as 'location_id' parameter (see parameters below)
292             }
293             }
294              
295             Mandatory parameters:
296              
297             affid : Affiliate ID provided by Careerjet. Requires to open a Careerjet partner
298             account (http://www.careerjet.com/partners/).
299              
300             user_ip : IP address of the end-user to whom the search results will be displayed.
301              
302             user_agent : User agent of the end-user's browser.
303            
304             Options:
305              
306             All options have default values and are not mandatory
307            
308             keywords : Keywords to match either title, content or company name of job offer
309             Examples: 'perl developer', 'ibm', 'software architect'
310             Default : none
311            
312             location : Location of requested job postings.
313             Examples: 'London' , 'Yorkshire', 'France'
314             Default: country specified by country code
315              
316             location_id : Location ID. Use values comming from the search function when location is ambiguous.
317             Default: none
318            
319             sort : Type of sort. This can be:
320             'relevance' - sorted by decreasing relevancy (default)
321             'date' - sorted by decreasing date
322             'salary' - sorted by decreasing salary
323            
324             start_num : Position of returned job postings within the entire result space.
325             This should be a least 1 but not more than the total number of job offers.
326             Default : 1
327            
328             pagesize : Number of returned results
329             Default : 20
330              
331             page : Page number of returned job postings within the entire result space.
332             This can be used instead of start_num. The minimum page number is 1.
333             The maximum number of pages is given by $result->{'pages'}
334             If this value is set, it overrides start_num.
335            
336             contracttype : Selected contract type. The following codes can be used:
337             'p' - permanent
338             'c' - contract
339             't' - temporary
340             'i' - training
341             'v' - voluntary
342             Default: none (all contract types)
343            
344             contractperiod : Selected contract period. The following codes can be used:
345             'f' - full time
346             'p' - part time
347             Default: none (all contract periods)
348              
349            
350             =cut
351              
352             sub search {
353 0     0 1   my ($self, $args) = @_;
354 0           my $ret = $self->_call('search', $args);
355              
356 0 0         if ($ret->{'type'} eq 'ERROR') {
357 0           confess "CAREERJET ERROR: " . $ret->{'error'};
358             }
359 0           return $ret;
360             }
361              
362             =head1 AUTHORS
363              
364             Thomas Busch (version 0.13 onwards)
365              
366             Jerome Eteve (version 0.01-0.12)
367              
368             =head1 FEEDBACK
369              
370             Any feedback is welcome. Please send your suggestions to
371              
372             =head1 COPYRIGHT & LICENSE
373              
374             Copyright 2007-2015 Careerjet Ltd. All rights reserved.
375              
376             This program is free software; you can redistribute it and/or modify it
377             under the same terms as Perl itself.
378              
379             =head1 DISCLAIMER OF WARRANTY
380              
381             BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE
382             SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE
383             STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE
384             SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
385             INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
386             FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
387             PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE,
388             YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
389              
390             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY
391             COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE
392             SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES,
393             INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
394             OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO
395             LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR
396             THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER
397             SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
398             POSSIBILITY OF SUCH DAMAGES.
399              
400             =cut
401              
402             1; # End of WebService::Careerjet