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   29462 use warnings;
  1         3  
  1         37  
4 1     1   6 use strict;
  1         2  
  1         44  
5              
6 1     1   6 use base qw/Class::AutoAccess/;
  1         5  
  1         720  
7              
8 1     1   1225 use URI::Escape;
  1         1354  
  1         70  
9 1     1   825 use LWP::UserAgent;
  1         67006  
  1         29  
10 1     1   8 use HTTP::Request;
  1         1  
  1         15  
11 1     1   3 use Carp;
  1         2  
  1         83  
12 1     1   653 use JSON;
  1         14756  
  1         6  
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 1.14
21              
22             =cut
23              
24             our $VERSION = '1.14';
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($class . '/' . $VERSION);
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             ## enable debug mode
206             $careerjet->debug(1);
207              
208             ## disable debug mode
209             $careerjet->debug(0);
210              
211             =cut
212              
213             sub _call {
214 0     0     my ($self, $function, $args) = @_;
215              
216 0           my $url = "http://public.api.careerjet.net/$function?locale_code=" . $self->{locale};
217 0           foreach my $k (keys %$args) {
218 0           $url .= '&' . $k . '=' . URI::Escape::uri_escape_utf8($args->{$k});
219             }
220              
221 0 0         print "GETTING " . $url . "\n" if ($self->debug());
222 0           my $req = HTTP::Request->new('GET' => $url);
223              
224 0           my $ret = undef;
225              
226 0           my $res = $self->{'agent'}->request($req);
227 0 0         if ($res->is_success()) {
228 0           my $content = $res->content();
229 0           my $json = new JSON;
230 0           $ret = $json->decode($content);
231             } else {
232 0           $ret->{'type'} = 'ERROR';
233 0           $ret->{'error'} = $res->status_line();
234             }
235              
236 0 0         unless (defined $ret) {
237 0           $ret = {
238             'type' => 'ERROR',
239             'error' => 'Json parsing error'
240             };
241             }
242              
243 0           return $ret;
244              
245             }
246              
247             =head2 search
248              
249             Performs a search using Careerjet's public search API.
250             Search parameters are passed on as a reference to a hash.
251              
252             The end-users IP address and user agent are mandatory parameters.
253             Also a Careerjet affiliate ID is required.
254              
255             Example:
256            
257             my $result = $api->search({
258             'keywords' => 'perl developer',
259             'location' => 'london',
260             'user_ip' => '11.22.33.44',
261             'user_agent' => 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0',
262             });
263              
264             # The result is a job list if the location is not ambiguous
265             if ($result->{'type'} eq 'JOBS') {
266             print "Found ". $result->{'hits'}. " jobs\n";
267             print "Total number of result pages: ". $result->{'pages'}. "\n";
268             my $jobs = $result->{'jobs'};
269             foreach my $j (@$jobs) {
270             print "URL :".$j->{'url'}."\n";
271             print "TITLE :".$j->{'title'}."\n";
272             print "COMPANY :".$j->{'company'}."\n";
273             print "SALARY :".$j->{'salary'}."\n";
274             print "DATE :".$j->{'date'}."\n";
275             print "DESCRIPTION :".$j->{'description'}."\n";
276             print "SITE :".$j->{'site'}."\n";
277             print "\n" ;
278             }
279            
280             }
281              
282             # If the location is ambiguous, a list of suggested locations
283             # is returned
284             if ($result->{'type'} eq 'LOCATIONS') {
285             print "Suggested locations:\n" ;
286             my $locations = $result->{'solveLocations'};
287             foreach my $l (@$locations) {
288             print $l->{'name'}."\n" ; ## For end-user display
289             ## Use $l->{'location_id'} when making next search call
290             ## as 'location_id' parameter (see parameters below)
291             }
292             }
293              
294             Mandatory parameters:
295              
296             affid : Affiliate ID provided by Careerjet. Requires to open a Careerjet partner
297             account (http://www.careerjet.com/partners/).
298              
299             user_ip : IP address of the end-user to whom the search results will be displayed.
300              
301             user_agent : User agent of the end-user's browser.
302            
303             Options:
304              
305             All options have default values and are not mandatory
306            
307             keywords : Keywords to match either title, content or company name of job offer
308             Examples: 'perl developer', 'ibm', 'software architect'
309             Default : none
310            
311             location : Location of requested job postings.
312             Examples: 'London' , 'Yorkshire', 'France'
313             Default: country specified by country code
314              
315             location_id : Location ID. Use values comming from the search function when location is ambiguous.
316             Default: none
317            
318             sort : Type of sort. This can be:
319             'relevance' - sorted by decreasing relevancy (default)
320             'date' - sorted by decreasing date
321             'salary' - sorted by decreasing salary
322            
323             start_num : Position of returned job postings within the entire result space.
324             This should be a least 1 but not more than the total number of job offers.
325             Default : 1
326            
327             pagesize : Number of returned results
328             Default : 20
329              
330             page : Page number of returned job postings within the entire result space.
331             This can be used instead of start_num. The minimum page number is 1.
332             The maximum number of pages is given by $result->{'pages'}
333             If this value is set, it overrides start_num.
334            
335             contracttype : Selected contract type. The following codes can be used:
336             'p' - permanent
337             'c' - contract
338             't' - temporary
339             'i' - training
340             'v' - voluntary
341             Default: none (all contract types)
342            
343             contractperiod : Selected contract period. The following codes can be used:
344             'f' - full time
345             'p' - part time
346             Default: none (all contract periods)
347              
348            
349             =cut
350              
351             sub search {
352 0     0 1   my ($self, $args) = @_;
353 0           my $ret = $self->_call('search', $args);
354              
355 0 0         if ($ret->{'type'} eq 'ERROR') {
356 0           confess "CAREERJET ERROR: " . $ret->{'error'};
357             }
358 0           return $ret;
359             }
360              
361             =head1 AUTHORS
362              
363             Thomas Busch (version 0.13 onwards)
364              
365             Jerome Eteve (version 0.01-0.12)
366              
367             =head1 FEEDBACK
368              
369             Any feedback is welcome. Please send your suggestions to
370              
371             =head1 COPYRIGHT & LICENSE
372              
373             Copyright 2007-2015 Careerjet Ltd. All rights reserved.
374              
375             This program is free software; you can redistribute it and/or modify it
376             under the same terms as Perl itself.
377              
378             =head1 DISCLAIMER OF WARRANTY
379              
380             BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE
381             SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE
382             STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE
383             SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
384             INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
385             FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
386             PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE,
387             YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
388              
389             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY
390             COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE
391             SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES,
392             INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
393             OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO
394             LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR
395             THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER
396             SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
397             POSSIBILITY OF SUCH DAMAGES.
398              
399             =cut
400              
401             1; # End of WebService::Careerjet