hawatel_search_jobs 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.codeclimate.yml +18 -17
- data/.gitignore +11 -11
- data/.rspec +2 -2
- data/.rubocop.yml +1169 -1169
- data/.travis.yml +6 -6
- data/CODE_OF_CONDUCT.md +13 -13
- data/CONTRIBUTING.md +69 -69
- data/Gemfile +4 -4
- data/LICENSE.txt +21 -21
- data/README.md +152 -152
- data/Rakefile +6 -6
- data/hawatel_search_jobs.gemspec +32 -32
- data/lib/hawatel_search_jobs.rb +64 -64
- data/lib/hawatel_search_jobs/api.rb +9 -9
- data/lib/hawatel_search_jobs/api/careerbuilder.rb +169 -169
- data/lib/hawatel_search_jobs/api/careerjet.rb +126 -126
- data/lib/hawatel_search_jobs/api/indeed.rb +157 -157
- data/lib/hawatel_search_jobs/api/reed.rb +185 -185
- data/lib/hawatel_search_jobs/client.rb +172 -165
- data/lib/hawatel_search_jobs/version.rb +1 -1
- data/spec/careerbuilder_spec.rb +82 -86
- data/spec/careerjet_spec.rb +58 -58
- data/spec/client_spec.rb +87 -61
- data/spec/indeed_spec.rb +59 -61
- data/spec/reed_spec.rb +77 -80
- data/spec/spec_helper.rb +2 -2
- data/spec/xing_spec.rb +46 -47
- metadata +2 -2
@@ -1,186 +1,186 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
|
3
|
-
module HawatelSearchJobs
|
4
|
-
module Api
|
5
|
-
##
|
6
|
-
# = Reed.co.uk API
|
7
|
-
#
|
8
|
-
# @see https://www.reed.co.uk/developers/Jobseeker
|
9
|
-
module Reed
|
10
|
-
class << self
|
11
|
-
include HawatelSearchJobs::Helpers::Base
|
12
|
-
|
13
|
-
DEFAULT = {
|
14
|
-
:keywords => '',
|
15
|
-
:location => '',
|
16
|
-
}
|
17
|
-
|
18
|
-
RESULT_LIMIT = 25
|
19
|
-
|
20
|
-
# Search jobs by specific criteria
|
21
|
-
# @param [Hash] args
|
22
|
-
# @option args :settings [Hash] search criteria
|
23
|
-
# - *:api* (String) - URL API (default: reed.co.uk/api)
|
24
|
-
# - *:version* (String) - a version of API (default: 1.0)
|
25
|
-
# - *:clientid* (String) - API Key (see https://www.reed.co.uk/developers/Jobseeker)
|
26
|
-
# @option args :query [Hash] settings of API
|
27
|
-
# - *:keywors* (String)
|
28
|
-
# - *:location* (String)
|
29
|
-
# @example
|
30
|
-
# jobs = Reed.search({:settings => {
|
31
|
-
# :api => 'reed.co.uk/api',
|
32
|
-
# :version => '1.0',
|
33
|
-
# :clientid => 'secret-code'},
|
34
|
-
# :query => {
|
35
|
-
# :keywords => 'ruby',
|
36
|
-
# :location => 'London'})
|
37
|
-
# @return [Hash] First page of the result (see constant RESULT_LIMIT)
|
38
|
-
def search(args)
|
39
|
-
args[:query] = DEFAULT.merge(args[:query]) if args[:query]
|
40
|
-
|
41
|
-
if args[:query_key].nil?
|
42
|
-
url_request = prepare_conn_string(args) + prepare_query(args)
|
43
|
-
else
|
44
|
-
url_request = args[:query_key]
|
45
|
-
end
|
46
|
-
|
47
|
-
response = api_request(url_request, args[:settings][:clientid])
|
48
|
-
attributes = build_jobs_table(response, url_request)
|
49
|
-
OpenStruct.new(attributes)
|
50
|
-
end
|
51
|
-
|
52
|
-
# Get a specific page result
|
53
|
-
# At the beging you have to run {search} method and get :key from result and pass it to the argument :query_key
|
54
|
-
# @param [Hash] args
|
55
|
-
# @option args :settings [Hash] see {search}
|
56
|
-
# @option args [Integer] :page page number counted from 0
|
57
|
-
# @option args [String] :query_key
|
58
|
-
# @example
|
59
|
-
# jobs = Careerbuilder.page({:settings => {
|
60
|
-
# :api => 'api.careerbuilder.com',
|
61
|
-
# :version => 'v2',
|
62
|
-
# :clientid => 'secret-code'},
|
63
|
-
# :page => 5,
|
64
|
-
# :query_key => 'value from :key returned by search method'})
|
65
|
-
# @return [Hash] Job offers from specific page
|
66
|
-
def page(args)
|
67
|
-
page = args[:page].to_i || 0
|
68
|
-
if args[:query_key]
|
69
|
-
limit = result_limit(args[:query_key])
|
70
|
-
url_request = args[:query_key].gsub(/&resultsToSkip=\d+/, '') << "&resultsToSkip=#{page * limit}"
|
71
|
-
args[:query_key] = url_request
|
72
|
-
search(args)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
private
|
77
|
-
|
78
|
-
def build_jobs_table(response, url_request)
|
79
|
-
attributes = Hash.new
|
80
|
-
attributes[:code] = response.code.to_i
|
81
|
-
attributes[:msg] = response.message
|
82
|
-
|
83
|
-
attributes[:totalResults] = 0
|
84
|
-
attributes[:page] = nil
|
85
|
-
attributes[:last] = nil
|
86
|
-
attributes[:key] = url_request
|
87
|
-
attributes[:jobs] = nil
|
88
|
-
|
89
|
-
|
90
|
-
if response.code.to_i == 200
|
91
|
-
json_response = JSON.parse(response.body)
|
92
|
-
begin
|
93
|
-
if !json_response['results'].to_s.empty?
|
94
|
-
attributes[:totalResults] = json_response['totalResults'] || 0
|
95
|
-
|
96
|
-
page_info = paging_info(url_request, attributes[:totalResults])
|
97
|
-
attributes[:page] = page_info.page
|
98
|
-
attributes[:last] = page_info.last
|
99
|
-
|
100
|
-
attributes[:key] = url_request
|
101
|
-
attributes[:jobs] = parse_raw_data(json_response)
|
102
|
-
end
|
103
|
-
rescue
|
104
|
-
raise "Something wrong with returned data: #{json_response}"
|
105
|
-
end
|
106
|
-
end
|
107
|
-
attributes
|
108
|
-
end
|
109
|
-
|
110
|
-
def api_request(url, clientid = nil)
|
111
|
-
opt = Hash.new
|
112
|
-
|
113
|
-
if clientid
|
114
|
-
opt = { :basic_auth => {
|
115
|
-
:username => clientid,
|
116
|
-
:password => ''
|
117
|
-
}}
|
118
|
-
end
|
119
|
-
|
120
|
-
send_request(url, opt)
|
121
|
-
end
|
122
|
-
|
123
|
-
def prepare_query(args)
|
124
|
-
"keywords=#{args[:query][:keywords]}&locationName=#{args[:query][:location]}"
|
125
|
-
end
|
126
|
-
|
127
|
-
def prepare_conn_string(args)
|
128
|
-
conn_string = "https://#{args[:settings][:api]}/#{args[:settings][:version]}/search?resultsToTake=#{RESULT_LIMIT}&"
|
129
|
-
conn_string
|
130
|
-
end
|
131
|
-
|
132
|
-
def parse_raw_data(data)
|
133
|
-
jobs = Array.new
|
134
|
-
data['results'].each do |offer|
|
135
|
-
job = Hash.new
|
136
|
-
job[:jobtitle] = offer['jobTitle'] if offer['jobTitle']
|
137
|
-
job[:location] = "United Kingdom, #{offer['locationName']}"
|
138
|
-
job[:company] = offer['employerName']
|
139
|
-
job[:date] = convert_date_to_format(offer['date'],'%d/%m/%y')
|
140
|
-
job[:url] = offer['jobUrl']
|
141
|
-
|
142
|
-
job = convert_empty_to_nil(job)
|
143
|
-
|
144
|
-
jobs << OpenStruct.new(job)
|
145
|
-
end
|
146
|
-
jobs
|
147
|
-
rescue
|
148
|
-
raise "Cannot parse raw data: #{data}"
|
149
|
-
end
|
150
|
-
|
151
|
-
def result_limit(url)
|
152
|
-
result = url.match(/\resultsToTake=(\d+)/)
|
153
|
-
result ? result[1].to_i : RESULT_LIMIT
|
154
|
-
end
|
155
|
-
|
156
|
-
def result_skip(url)
|
157
|
-
result = url.match(/\&resultsToSkip=(\d+)/)
|
158
|
-
result ? result[1].to_i : 0
|
159
|
-
end
|
160
|
-
|
161
|
-
def paging_info(url, total_result)
|
162
|
-
return OpenStruct.new({:page => nil, :last => nil}) if total_result == 0
|
163
|
-
|
164
|
-
result_limit = result_limit(url)
|
165
|
-
result_skip = result_skip(url)
|
166
|
-
|
167
|
-
if result_skip == 0 && total_result > 0
|
168
|
-
page = 0
|
169
|
-
else
|
170
|
-
page = (result_skip / result_limit).to_i
|
171
|
-
end
|
172
|
-
|
173
|
-
mod = total_result.to_i % result_limit.to_i
|
174
|
-
if mod == 0
|
175
|
-
last = (total_result.to_i / result_limit.to_i) - 1
|
176
|
-
else
|
177
|
-
last = (total_result.to_i / result_limit.to_i).to_i
|
178
|
-
end
|
179
|
-
|
180
|
-
OpenStruct.new({:page => page, :last => last})
|
181
|
-
end
|
182
|
-
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module HawatelSearchJobs
|
4
|
+
module Api
|
5
|
+
##
|
6
|
+
# = Reed.co.uk API
|
7
|
+
#
|
8
|
+
# @see https://www.reed.co.uk/developers/Jobseeker
|
9
|
+
module Reed
|
10
|
+
class << self
|
11
|
+
include HawatelSearchJobs::Helpers::Base
|
12
|
+
|
13
|
+
DEFAULT = {
|
14
|
+
:keywords => '',
|
15
|
+
:location => '',
|
16
|
+
}
|
17
|
+
|
18
|
+
RESULT_LIMIT = 25
|
19
|
+
|
20
|
+
# Search jobs by specific criteria
|
21
|
+
# @param [Hash] args
|
22
|
+
# @option args :settings [Hash] search criteria
|
23
|
+
# - *:api* (String) - URL API (default: reed.co.uk/api)
|
24
|
+
# - *:version* (String) - a version of API (default: 1.0)
|
25
|
+
# - *:clientid* (String) - API Key (see https://www.reed.co.uk/developers/Jobseeker)
|
26
|
+
# @option args :query [Hash] settings of API
|
27
|
+
# - *:keywors* (String)
|
28
|
+
# - *:location* (String)
|
29
|
+
# @example
|
30
|
+
# jobs = Reed.search({:settings => {
|
31
|
+
# :api => 'reed.co.uk/api',
|
32
|
+
# :version => '1.0',
|
33
|
+
# :clientid => 'secret-code'},
|
34
|
+
# :query => {
|
35
|
+
# :keywords => 'ruby',
|
36
|
+
# :location => 'London'})
|
37
|
+
# @return [Hash] First page of the result (see constant RESULT_LIMIT)
|
38
|
+
def search(args)
|
39
|
+
args[:query] = DEFAULT.merge(args[:query]) if args[:query]
|
40
|
+
|
41
|
+
if args[:query_key].nil?
|
42
|
+
url_request = prepare_conn_string(args) + prepare_query(args)
|
43
|
+
else
|
44
|
+
url_request = args[:query_key]
|
45
|
+
end
|
46
|
+
|
47
|
+
response = api_request(url_request, args[:settings][:clientid])
|
48
|
+
attributes = build_jobs_table(response, url_request)
|
49
|
+
OpenStruct.new(attributes)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Get a specific page result
|
53
|
+
# At the beging you have to run {search} method and get :key from result and pass it to the argument :query_key
|
54
|
+
# @param [Hash] args
|
55
|
+
# @option args :settings [Hash] see {search}
|
56
|
+
# @option args [Integer] :page page number counted from 0
|
57
|
+
# @option args [String] :query_key
|
58
|
+
# @example
|
59
|
+
# jobs = Careerbuilder.page({:settings => {
|
60
|
+
# :api => 'api.careerbuilder.com',
|
61
|
+
# :version => 'v2',
|
62
|
+
# :clientid => 'secret-code'},
|
63
|
+
# :page => 5,
|
64
|
+
# :query_key => 'value from :key returned by search method'})
|
65
|
+
# @return [Hash] Job offers from specific page
|
66
|
+
def page(args)
|
67
|
+
page = args[:page].to_i || 0
|
68
|
+
if args[:query_key]
|
69
|
+
limit = result_limit(args[:query_key])
|
70
|
+
url_request = args[:query_key].gsub(/&resultsToSkip=\d+/, '') << "&resultsToSkip=#{page * limit}"
|
71
|
+
args[:query_key] = url_request
|
72
|
+
search(args)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def build_jobs_table(response, url_request)
|
79
|
+
attributes = Hash.new
|
80
|
+
attributes[:code] = response.code.to_i
|
81
|
+
attributes[:msg] = response.message
|
82
|
+
|
83
|
+
attributes[:totalResults] = 0
|
84
|
+
attributes[:page] = nil
|
85
|
+
attributes[:last] = nil
|
86
|
+
attributes[:key] = url_request
|
87
|
+
attributes[:jobs] = nil
|
88
|
+
|
89
|
+
|
90
|
+
if response.code.to_i == 200
|
91
|
+
json_response = JSON.parse(response.body)
|
92
|
+
begin
|
93
|
+
if !json_response['results'].to_s.empty?
|
94
|
+
attributes[:totalResults] = json_response['totalResults'] || 0
|
95
|
+
|
96
|
+
page_info = paging_info(url_request, attributes[:totalResults])
|
97
|
+
attributes[:page] = page_info.page
|
98
|
+
attributes[:last] = page_info.last
|
99
|
+
|
100
|
+
attributes[:key] = url_request
|
101
|
+
attributes[:jobs] = parse_raw_data(json_response)
|
102
|
+
end
|
103
|
+
rescue
|
104
|
+
raise "Something wrong with returned data: #{json_response}"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
attributes
|
108
|
+
end
|
109
|
+
|
110
|
+
def api_request(url, clientid = nil)
|
111
|
+
opt = Hash.new
|
112
|
+
|
113
|
+
if clientid
|
114
|
+
opt = { :basic_auth => {
|
115
|
+
:username => clientid,
|
116
|
+
:password => ''
|
117
|
+
}}
|
118
|
+
end
|
119
|
+
|
120
|
+
send_request(url, opt)
|
121
|
+
end
|
122
|
+
|
123
|
+
def prepare_query(args)
|
124
|
+
"keywords=#{args[:query][:keywords]}&locationName=#{args[:query][:location]}"
|
125
|
+
end
|
126
|
+
|
127
|
+
def prepare_conn_string(args)
|
128
|
+
conn_string = "https://#{args[:settings][:api]}/#{args[:settings][:version]}/search?resultsToTake=#{RESULT_LIMIT}&"
|
129
|
+
conn_string
|
130
|
+
end
|
131
|
+
|
132
|
+
def parse_raw_data(data)
|
133
|
+
jobs = Array.new
|
134
|
+
data['results'].each do |offer|
|
135
|
+
job = Hash.new
|
136
|
+
job[:jobtitle] = offer['jobTitle'] if offer['jobTitle']
|
137
|
+
job[:location] = "United Kingdom, #{offer['locationName']}"
|
138
|
+
job[:company] = offer['employerName']
|
139
|
+
job[:date] = convert_date_to_format(offer['date'],'%d/%m/%y')
|
140
|
+
job[:url] = offer['jobUrl']
|
141
|
+
|
142
|
+
job = convert_empty_to_nil(job)
|
143
|
+
|
144
|
+
jobs << OpenStruct.new(job)
|
145
|
+
end
|
146
|
+
jobs
|
147
|
+
rescue
|
148
|
+
raise "Cannot parse raw data: #{data}"
|
149
|
+
end
|
150
|
+
|
151
|
+
def result_limit(url)
|
152
|
+
result = url.match(/\resultsToTake=(\d+)/)
|
153
|
+
result ? result[1].to_i : RESULT_LIMIT
|
154
|
+
end
|
155
|
+
|
156
|
+
def result_skip(url)
|
157
|
+
result = url.match(/\&resultsToSkip=(\d+)/)
|
158
|
+
result ? result[1].to_i : 0
|
159
|
+
end
|
160
|
+
|
161
|
+
def paging_info(url, total_result)
|
162
|
+
return OpenStruct.new({:page => nil, :last => nil}) if total_result == 0
|
163
|
+
|
164
|
+
result_limit = result_limit(url)
|
165
|
+
result_skip = result_skip(url)
|
166
|
+
|
167
|
+
if result_skip == 0 && total_result > 0
|
168
|
+
page = 0
|
169
|
+
else
|
170
|
+
page = (result_skip / result_limit).to_i
|
171
|
+
end
|
172
|
+
|
173
|
+
mod = total_result.to_i % result_limit.to_i
|
174
|
+
if mod == 0
|
175
|
+
last = (total_result.to_i / result_limit.to_i) - 1
|
176
|
+
else
|
177
|
+
last = (total_result.to_i / result_limit.to_i).to_i
|
178
|
+
end
|
179
|
+
|
180
|
+
OpenStruct.new({:page => page, :last => last})
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
186
|
end
|
@@ -1,165 +1,172 @@
|
|
1
|
-
module HawatelSearchJobs
|
2
|
-
##
|
3
|
-
# = Client for a jobs search engine
|
4
|
-
#
|
5
|
-
# @!attribute [rw] indeed
|
6
|
-
# @return [Hash] settings of API
|
7
|
-
# @!attribute [rw] xing
|
8
|
-
# @return [Hash] settings of API
|
9
|
-
# @!attribute [rw] reed
|
10
|
-
# @return [Hash] settings of API
|
11
|
-
# @!attribute [rw] careerbuilder
|
12
|
-
# @return [Hash] settings of API
|
13
|
-
# @!attribute [rw] careerjet
|
14
|
-
# @return [Hash] settings of API
|
15
|
-
class Client
|
16
|
-
include HawatelSearchJobs::Api
|
17
|
-
|
18
|
-
# Values have to be the same name like module name of usesd APIs (HawatelSearchJobs::Api::[ApiName])
|
19
|
-
APIS = ['Indeed', 'Xing', 'Reed', 'Careerbuilder', 'CareerJet']
|
20
|
-
|
21
|
-
attr_reader :jobs_table
|
22
|
-
|
23
|
-
DEFAULT = {
|
24
|
-
:keywords => '',
|
25
|
-
:location => '',
|
26
|
-
:company => '',
|
27
|
-
}
|
28
|
-
|
29
|
-
def initialize
|
30
|
-
APIS.each do |api|
|
31
|
-
metaclasses.send(:attr_reader, api.downcase.to_sym)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
# config.
|
55
|
-
# config.
|
56
|
-
# config.
|
57
|
-
#
|
58
|
-
#
|
59
|
-
# config.
|
60
|
-
# config.
|
61
|
-
# config.
|
62
|
-
#
|
63
|
-
# config.
|
64
|
-
#
|
65
|
-
# config.
|
66
|
-
# config.
|
67
|
-
#
|
68
|
-
# config.
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
#
|
130
|
-
#
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
1
|
+
module HawatelSearchJobs
|
2
|
+
##
|
3
|
+
# = Client for a jobs search engine
|
4
|
+
#
|
5
|
+
# @!attribute [rw] indeed
|
6
|
+
# @return [Hash] settings of API
|
7
|
+
# @!attribute [rw] xing
|
8
|
+
# @return [Hash] settings of API
|
9
|
+
# @!attribute [rw] reed
|
10
|
+
# @return [Hash] settings of API
|
11
|
+
# @!attribute [rw] careerbuilder
|
12
|
+
# @return [Hash] settings of API
|
13
|
+
# @!attribute [rw] careerjet
|
14
|
+
# @return [Hash] settings of API
|
15
|
+
class Client
|
16
|
+
include HawatelSearchJobs::Api
|
17
|
+
|
18
|
+
# Values have to be the same name like module name of usesd APIs (HawatelSearchJobs::Api::[ApiName])
|
19
|
+
APIS = ['Indeed', 'Xing', 'Reed', 'Careerbuilder', 'CareerJet']
|
20
|
+
|
21
|
+
attr_reader :jobs_table
|
22
|
+
|
23
|
+
DEFAULT = {
|
24
|
+
:keywords => '',
|
25
|
+
:location => '',
|
26
|
+
:company => '',
|
27
|
+
}
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
APIS.each do |api|
|
31
|
+
metaclasses.send(:attr_reader, api.downcase.to_sym)
|
32
|
+
api_conf = HawatelSearchJobs.instance_variable_get("@"+api.downcase)
|
33
|
+
|
34
|
+
if api_conf.nil?
|
35
|
+
HawatelSearchJobs.configure
|
36
|
+
api_conf = HawatelSearchJobs.instance_variable_get("@"+api.downcase)
|
37
|
+
end
|
38
|
+
|
39
|
+
instance_variable_set("@#{api.downcase}", api_conf.dup)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def metaclasses
|
44
|
+
class << self; self; end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Search Jobs by specific criteria
|
48
|
+
# @param query [Hash]
|
49
|
+
# @option query [String] :keywords
|
50
|
+
# @option query [String] :location
|
51
|
+
# @option query [String] :company not working in Reed API
|
52
|
+
# @example
|
53
|
+
# HawatelSearchJobs.configure do |config|
|
54
|
+
# config.indeed[:activated] = true
|
55
|
+
# config.indeed[:api] = 'api.indeed.com'
|
56
|
+
# config.indeed[:version] = '2'
|
57
|
+
# config.indeed[:publisher] = 'secret-key'
|
58
|
+
#
|
59
|
+
# config.xing[:activated] = true
|
60
|
+
# config.xing[:consumer_key] = 'secret-key'
|
61
|
+
# config.xing[:consumer_secret] = 'secret-key'
|
62
|
+
# config.xing[:oauth_token] = 'secret-key'
|
63
|
+
# config.xing[:oauth_token_secret] = 'secret-key'
|
64
|
+
#
|
65
|
+
# config.reed[:activated] = true
|
66
|
+
# config.reed[:api] = 'reed.co.uk/api'
|
67
|
+
# config.reed[:clientid] = 'secret-key'
|
68
|
+
# config.reed[:version] = '1.0'
|
69
|
+
#
|
70
|
+
# config.careerbuilder[:activated] = true
|
71
|
+
# config.careerbuilder[:api] = 'api.careerbuilder.com'
|
72
|
+
# config.careerbuilder[:clientid] = 'secret-key'
|
73
|
+
# config.careerbuilder[:version] = 'v2'
|
74
|
+
#
|
75
|
+
# config.careerjet[:activated] = true
|
76
|
+
# config.careerjet[:api] = 'public.api.careerjet.net'
|
77
|
+
# end
|
78
|
+
#
|
79
|
+
# client = HawatelSearchJobs::Client.new
|
80
|
+
# client.search_jobs({:keywords => 'ruby'})
|
81
|
+
#
|
82
|
+
# p client.jobs_table[:indeed]
|
83
|
+
# p client.jobs_table[:xing]
|
84
|
+
# p client.jobs_table[:reed]
|
85
|
+
# p client.jobs_table[:careerbuilder]
|
86
|
+
# p client.jobs_table[:careerjet]
|
87
|
+
#
|
88
|
+
# client.next
|
89
|
+
# @return [Hash] First page of result for all providers (default maximum 25 records for each page)
|
90
|
+
def search_jobs(query = {})
|
91
|
+
query = DEFAULT.merge(query)
|
92
|
+
|
93
|
+
@jobs_table = Hash.new
|
94
|
+
|
95
|
+
APIS.each do |api|
|
96
|
+
api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
|
97
|
+
api_inst_var = instance_variable_get("@"+api.downcase)
|
98
|
+
@jobs_table[api.downcase.to_sym] = api_module_name.search({:settings => api_inst_var, :query => query}) if api_inst_var[:activated]
|
99
|
+
end
|
100
|
+
|
101
|
+
@jobs_table
|
102
|
+
end
|
103
|
+
|
104
|
+
# Get next page of result
|
105
|
+
# @example
|
106
|
+
# p client.next
|
107
|
+
# p client.jobs_table
|
108
|
+
# @return [Hash] Next page of result for all providers (default maximum 25 records for each)
|
109
|
+
def next
|
110
|
+
next_result = Hash.new
|
111
|
+
APIS.each do |api|
|
112
|
+
api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
|
113
|
+
api_inst_var = instance_variable_get("@"+api.downcase)
|
114
|
+
api_sym_name = api.downcase.to_sym
|
115
|
+
|
116
|
+
if api_inst_var[:activated] && next_result?(api_sym_name)
|
117
|
+
next_result[api_sym_name] = api_module_name.page({:settings => api_inst_var,
|
118
|
+
:page => @jobs_table[api_sym_name].page + 1,
|
119
|
+
:query_key => @jobs_table[api_sym_name].key})
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
return nil if next_result.empty?
|
124
|
+
|
125
|
+
@jobs_table = next_result
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
# Sum jobs offers from specified api or count all
|
130
|
+
#
|
131
|
+
# @param args [Hash]
|
132
|
+
# @option args [String] :api name
|
133
|
+
# @example
|
134
|
+
# p client.count
|
135
|
+
# p client.count('indeed')
|
136
|
+
#
|
137
|
+
# @return [Integer]
|
138
|
+
def count(api = nil)
|
139
|
+
sum = 0
|
140
|
+
|
141
|
+
if api
|
142
|
+
api = api.downcase
|
143
|
+
api_inst_var = instance_variable_get("@"+api)
|
144
|
+
if api_inst_var[:activated]
|
145
|
+
sum = @jobs_table[:"#{api}"].totalResults if @jobs_table[:"#{api}"].totalResults
|
146
|
+
end
|
147
|
+
else
|
148
|
+
APIS.each do |provider|
|
149
|
+
api_inst_var = instance_variable_get("@"+provider.downcase)
|
150
|
+
if api_inst_var[:activated]
|
151
|
+
provider = provider.downcase
|
152
|
+
sum += @jobs_table[:"#{provider}"].totalResults if @jobs_table[:"#{provider}"].totalResults
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
return sum
|
157
|
+
end
|
158
|
+
|
159
|
+
private
|
160
|
+
def next_result?(provider)
|
161
|
+
if @jobs_table[provider] && @jobs_table[provider].page && @jobs_table[provider].last &&
|
162
|
+
@jobs_table[provider].page < @jobs_table[provider].last
|
163
|
+
true
|
164
|
+
else
|
165
|
+
false
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|