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
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require "rspec/core/rake_task"
|
3
|
-
|
4
|
-
RSpec::Core::RakeTask.new(:spec)
|
5
|
-
|
6
|
-
task :default => :spec
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
task :default => :spec
|
data/hawatel_search_jobs.gemspec
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'hawatel_search_jobs/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "hawatel_search_jobs"
|
8
|
-
spec.version = HawatelSearchJobs::VERSION
|
9
|
-
spec.authors = ['Przemyslaw Mantaj','Daniel Iwaniuk']
|
10
|
-
spec.email = ['przemyslaw.mantaj@hawatel.com', 'daniel.iwaniuk@hawatel.com']
|
11
|
-
|
12
|
-
spec.summary = %q{Hawatel_search_jobs, it is gem which provides ease access to API from popular job websites to get current job offers.}
|
13
|
-
spec.description = %q{Hawatel_search_jobs, it is gem which provides ease access to API from popular job websites
|
14
|
-
to get current job offers. At this moment, supported backends are indeed.com, careerjet.com,
|
15
|
-
xing.com, careerbuilder.com and reed.co.uk.}
|
16
|
-
spec.homepage = "http://github.com/Hawatel/hawatel_search_jobs"
|
17
|
-
spec.license = "MIT"
|
18
|
-
|
19
|
-
spec.files = `git ls-files`.split($/)
|
20
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
-
spec.require_paths = ["lib"]
|
23
|
-
|
24
|
-
spec.required_ruby_version = '>= 2.0.0'
|
25
|
-
|
26
|
-
spec.add_runtime_dependency 'xing_api'
|
27
|
-
spec.add_runtime_dependency 'activesupport'
|
28
|
-
|
29
|
-
spec.add_development_dependency "bundler", "~> 1.10"
|
30
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
-
spec.add_development_dependency "rspec"
|
32
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hawatel_search_jobs/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hawatel_search_jobs"
|
8
|
+
spec.version = HawatelSearchJobs::VERSION
|
9
|
+
spec.authors = ['Przemyslaw Mantaj','Daniel Iwaniuk']
|
10
|
+
spec.email = ['przemyslaw.mantaj@hawatel.com', 'daniel.iwaniuk@hawatel.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Hawatel_search_jobs, it is gem which provides ease access to API from popular job websites to get current job offers.}
|
13
|
+
spec.description = %q{Hawatel_search_jobs, it is gem which provides ease access to API from popular job websites
|
14
|
+
to get current job offers. At this moment, supported backends are indeed.com, careerjet.com,
|
15
|
+
xing.com, careerbuilder.com and reed.co.uk.}
|
16
|
+
spec.homepage = "http://github.com/Hawatel/hawatel_search_jobs"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.files = `git ls-files`.split($/)
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.required_ruby_version = '>= 2.0.0'
|
25
|
+
|
26
|
+
spec.add_runtime_dependency 'xing_api'
|
27
|
+
spec.add_runtime_dependency 'activesupport'
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec"
|
32
|
+
end
|
data/lib/hawatel_search_jobs.rb
CHANGED
@@ -1,64 +1,64 @@
|
|
1
|
-
##
|
2
|
-
# = Hawatel Search Jobs
|
3
|
-
# More details how to use it was described here {HawatelSearchJobs::Client}
|
4
|
-
module HawatelSearchJobs
|
5
|
-
require 'hawatel_search_jobs/helpers'
|
6
|
-
require 'hawatel_search_jobs/api'
|
7
|
-
require 'hawatel_search_jobs/client'
|
8
|
-
|
9
|
-
class << self
|
10
|
-
attr_accessor :indeed, :xing, :reed, :careerbuilder, :careerjet
|
11
|
-
|
12
|
-
##
|
13
|
-
# How to configure APIs go to example {HawatelSearchJobs::Client#search_jobs}
|
14
|
-
def configure
|
15
|
-
@indeed = default_indeed(Hash.new)
|
16
|
-
@xing = default_xing(Hash.new)
|
17
|
-
@reed = default_reed(Hash.new)
|
18
|
-
@careerbuilder = default_careerbuilder(Hash.new)
|
19
|
-
@careerjet = default_careerjet(Hash.new)
|
20
|
-
yield self
|
21
|
-
true
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def default_xing(settings)
|
27
|
-
settings[:activated] = false
|
28
|
-
settings[:consumer_key] = ''
|
29
|
-
settings[:consumer_secret] = ''
|
30
|
-
settings[:oauth_token] = ''
|
31
|
-
settings[:oauth_token_secret] = ''
|
32
|
-
return settings
|
33
|
-
end
|
34
|
-
|
35
|
-
def default_indeed(settings)
|
36
|
-
settings[:activated] = false
|
37
|
-
settings[:api] = 'api.indeed.com'
|
38
|
-
settings[:version] = '2'
|
39
|
-
settings[:publisher] = ''
|
40
|
-
return settings
|
41
|
-
end
|
42
|
-
|
43
|
-
def default_careerjet(settings)
|
44
|
-
settings[:activated] = false
|
45
|
-
settings[:api] = 'public.api.careerjet.net'
|
46
|
-
return settings
|
47
|
-
end
|
48
|
-
|
49
|
-
def default_reed(settings)
|
50
|
-
settings[:activated] = false
|
51
|
-
settings[:api] = 'reed.co.uk/api'
|
52
|
-
settings[:version] = '1.0'
|
53
|
-
return settings
|
54
|
-
end
|
55
|
-
|
56
|
-
def default_careerbuilder(settings)
|
57
|
-
settings[:activated] = false
|
58
|
-
settings[:api] = 'api.careerbuilder.com'
|
59
|
-
settings[:version] = 'v2'
|
60
|
-
return settings
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
1
|
+
##
|
2
|
+
# = Hawatel Search Jobs
|
3
|
+
# More details how to use it was described here {HawatelSearchJobs::Client}
|
4
|
+
module HawatelSearchJobs
|
5
|
+
require 'hawatel_search_jobs/helpers'
|
6
|
+
require 'hawatel_search_jobs/api'
|
7
|
+
require 'hawatel_search_jobs/client'
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_accessor :indeed, :xing, :reed, :careerbuilder, :careerjet
|
11
|
+
|
12
|
+
##
|
13
|
+
# How to configure APIs go to example {HawatelSearchJobs::Client#search_jobs}
|
14
|
+
def configure
|
15
|
+
@indeed = default_indeed(Hash.new)
|
16
|
+
@xing = default_xing(Hash.new)
|
17
|
+
@reed = default_reed(Hash.new)
|
18
|
+
@careerbuilder = default_careerbuilder(Hash.new)
|
19
|
+
@careerjet = default_careerjet(Hash.new)
|
20
|
+
yield self if block_given?
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def default_xing(settings)
|
27
|
+
settings[:activated] = false
|
28
|
+
settings[:consumer_key] = ''
|
29
|
+
settings[:consumer_secret] = ''
|
30
|
+
settings[:oauth_token] = ''
|
31
|
+
settings[:oauth_token_secret] = ''
|
32
|
+
return settings
|
33
|
+
end
|
34
|
+
|
35
|
+
def default_indeed(settings)
|
36
|
+
settings[:activated] = false
|
37
|
+
settings[:api] = 'api.indeed.com'
|
38
|
+
settings[:version] = '2'
|
39
|
+
settings[:publisher] = ''
|
40
|
+
return settings
|
41
|
+
end
|
42
|
+
|
43
|
+
def default_careerjet(settings)
|
44
|
+
settings[:activated] = false
|
45
|
+
settings[:api] = 'public.api.careerjet.net'
|
46
|
+
return settings
|
47
|
+
end
|
48
|
+
|
49
|
+
def default_reed(settings)
|
50
|
+
settings[:activated] = false
|
51
|
+
settings[:api] = 'reed.co.uk/api'
|
52
|
+
settings[:version] = '1.0'
|
53
|
+
return settings
|
54
|
+
end
|
55
|
+
|
56
|
+
def default_careerbuilder(settings)
|
57
|
+
settings[:activated] = false
|
58
|
+
settings[:api] = 'api.careerbuilder.com'
|
59
|
+
settings[:version] = 'v2'
|
60
|
+
return settings
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module HawatelSearchJobs
|
2
|
-
module Api
|
3
|
-
require 'hawatel_search_jobs/api/indeed'
|
4
|
-
require 'hawatel_search_jobs/api/reed'
|
5
|
-
require 'hawatel_search_jobs/api/xing'
|
6
|
-
require 'hawatel_search_jobs/api/careerbuilder'
|
7
|
-
require 'hawatel_search_jobs/api/careerjet'
|
8
|
-
end
|
9
|
-
end
|
1
|
+
module HawatelSearchJobs
|
2
|
+
module Api
|
3
|
+
require 'hawatel_search_jobs/api/indeed'
|
4
|
+
require 'hawatel_search_jobs/api/reed'
|
5
|
+
require 'hawatel_search_jobs/api/xing'
|
6
|
+
require 'hawatel_search_jobs/api/careerbuilder'
|
7
|
+
require 'hawatel_search_jobs/api/careerjet'
|
8
|
+
end
|
9
|
+
end
|
@@ -1,170 +1,170 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
require 'active_support/core_ext/hash'
|
3
|
-
|
4
|
-
module HawatelSearchJobs
|
5
|
-
module Api
|
6
|
-
##
|
7
|
-
# = Carerrbuilder API
|
8
|
-
#
|
9
|
-
# @see http://api.careerbuilder.com/Search/jobsearch/jobsearchinfo.aspx
|
10
|
-
module Careerbuilder
|
11
|
-
class << self
|
12
|
-
include HawatelSearchJobs::Helpers::Base
|
13
|
-
|
14
|
-
DEFAULT = {
|
15
|
-
:keywords => '',
|
16
|
-
:location => '',
|
17
|
-
:company => ''
|
18
|
-
}
|
19
|
-
|
20
|
-
RESULT_LIMIT = 25
|
21
|
-
|
22
|
-
# Search jobs by specific criteria
|
23
|
-
# @param [Hash] args
|
24
|
-
# @option args :settings [Hash] search criteria
|
25
|
-
# - *:api* (String) - URL API (default: api.careerbuilder.com)
|
26
|
-
# - *:version* (String) - a version of API (default: v2)
|
27
|
-
# - *:clientid* (String) - Private Developer Key (see http://developer.careerbuilder.com)
|
28
|
-
# @option args :query [Hash] settings of API
|
29
|
-
# - *:keywors* (String)
|
30
|
-
# - *:location* (String)
|
31
|
-
# - *:company* (String)
|
32
|
-
# @example
|
33
|
-
# jobs = Careerbuilder.search({:settings => {
|
34
|
-
# :api => 'api.careerbuilder.com',
|
35
|
-
# :version => 'v2',
|
36
|
-
# :clientid => 'secret-code'},
|
37
|
-
# :query => {
|
38
|
-
# :keywords => 'ruby',
|
39
|
-
# :location => 'London',
|
40
|
-
# :company => ''}})
|
41
|
-
# @return [Hash] First page of the result (see constant RESULT_LIMIT)
|
42
|
-
def search(args)
|
43
|
-
args[:query] = DEFAULT.merge(args[:query]) if args[:query]
|
44
|
-
|
45
|
-
if args[:query_key].nil?
|
46
|
-
url_request = prepare_conn_string(args) + prepare_query(args)
|
47
|
-
else
|
48
|
-
url_request = args[:query_key]
|
49
|
-
end
|
50
|
-
|
51
|
-
response = send_request(url_request)
|
52
|
-
attributes = build_jobs_table(response, url_request)
|
53
|
-
OpenStruct.new(attributes)
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
# Get a specific page result
|
58
|
-
# At the beging you have to run {search} method and get :key from result and pass it to the argument :query_key
|
59
|
-
# @param [Hash] args
|
60
|
-
# @option args :settings [Hash] see {search}
|
61
|
-
# @option args [Integer] :page page number counted from 0
|
62
|
-
# @option args [String] :query_key
|
63
|
-
# @example
|
64
|
-
# jobs = Careerbuilder.page({:settings => {
|
65
|
-
# :api => 'api.careerbuilder.com',
|
66
|
-
# :version => 'v2',
|
67
|
-
# :clientid => 'secret-code'},
|
68
|
-
# :page => 5,
|
69
|
-
# :query_key => 'value from :key returned by search method'})
|
70
|
-
# @return [Hash] Job offers from specific page
|
71
|
-
def page(args)
|
72
|
-
page = args[:page].to_i || 0
|
73
|
-
if args[:query_key]
|
74
|
-
url_request = args[:query_key].gsub(/&PageNumber=\d+/, '') << "&PageNumber=#{page+1}"
|
75
|
-
args[:query_key] = url_request
|
76
|
-
search(args)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
private
|
81
|
-
|
82
|
-
def build_jobs_table(response, url_request)
|
83
|
-
attributes = Hash.new
|
84
|
-
attributes[:code] = response.code.to_i
|
85
|
-
attributes[:msg] = response.message
|
86
|
-
|
87
|
-
attributes[:totalResults] = 0
|
88
|
-
attributes[:page] = nil
|
89
|
-
attributes[:last] = nil
|
90
|
-
attributes[:key] = url_request
|
91
|
-
attributes[:jobs] = nil
|
92
|
-
|
93
|
-
if response.code.to_i == 200
|
94
|
-
xml_response = Hash.from_xml(response.body.gsub('\n', ''))
|
95
|
-
begin
|
96
|
-
if xml_response['ResponseJobSearch'] && xml_response['ResponseJobSearch']['Results']
|
97
|
-
attributes[:totalResults] = xml_response['ResponseJobSearch']['TotalCount'].to_i || 0
|
98
|
-
attributes[:page] = get_page_number(url_request) - 1
|
99
|
-
attributes[:last] = xml_response['ResponseJobSearch']['TotalPages'].to_i - 1
|
100
|
-
attributes[:key] = url_request
|
101
|
-
attributes[:jobs] = parse_raw_data(xml_response)
|
102
|
-
end
|
103
|
-
rescue
|
104
|
-
raise "Something wrong with returned data: #{xml_response}"
|
105
|
-
end
|
106
|
-
end
|
107
|
-
attributes
|
108
|
-
end
|
109
|
-
|
110
|
-
def prepare_query(args)
|
111
|
-
"Keywords=#{args[:query][:keywords]}&" \
|
112
|
-
"Location=#{args[:query][:location]}&" \
|
113
|
-
"CompanyName=#{args[:query][:company]}"
|
114
|
-
end
|
115
|
-
|
116
|
-
def prepare_conn_string(args)
|
117
|
-
conn_string = "https://#{args[:settings][:api]}/#{args[:settings][:version]}/jobsearch?" \
|
118
|
-
"PerPage=#{RESULT_LIMIT}&DeveloperKey=#{args[:settings][:clientid]}&"
|
119
|
-
|
120
|
-
conn_string
|
121
|
-
end
|
122
|
-
|
123
|
-
def parse_raw_data(data)
|
124
|
-
jobs = Array.new
|
125
|
-
data['ResponseJobSearch']['Results']['JobSearchResult'].each do |offer|
|
126
|
-
job = Hash.new
|
127
|
-
job[:jobtitle] = offer['JobTitle'] if offer['JobTitle']
|
128
|
-
|
129
|
-
country = get_country_name(offer['State'], data['ResponseJobSearch']['SearchMetaData']['SearchLocations'])
|
130
|
-
location = country
|
131
|
-
location += ", #{offer['City']}" if offer['City'] && country != offer['City']
|
132
|
-
job[:location] = location
|
133
|
-
job[:company] = offer['Company']
|
134
|
-
|
135
|
-
newdate = offer['PostedDate'].split('/')
|
136
|
-
job[:date] = "#{newdate[1]}/#{newdate[0]}/#{newdate[2]}"
|
137
|
-
|
138
|
-
job[:date] = convert_date_to_format(job[:date],'%d/%m/%y')
|
139
|
-
job[:url] = offer['JobDetailsURL']
|
140
|
-
|
141
|
-
job = convert_empty_to_nil(job)
|
142
|
-
|
143
|
-
jobs << OpenStruct.new(job)
|
144
|
-
end
|
145
|
-
jobs
|
146
|
-
rescue
|
147
|
-
raise "Cannot parse raw data - #{data.inspect}"
|
148
|
-
end
|
149
|
-
|
150
|
-
def get_country_name(code, locations)
|
151
|
-
locations.each do |loc|
|
152
|
-
if loc[1]['StateCode'] && code && code.to_s == loc[1]['StateCode'].to_s
|
153
|
-
return loc[1]['City'] if loc[1]['City']
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
'United States'
|
158
|
-
rescue
|
159
|
-
raise "Cannot get country name (code=#{code}, locations=#{locations}"
|
160
|
-
end
|
161
|
-
|
162
|
-
def get_page_number(url)
|
163
|
-
result = url.match(/\&PageNumber=(\d+)/)
|
164
|
-
result ? result[1].to_i : 1
|
165
|
-
end
|
166
|
-
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
1
|
+
require 'ostruct'
|
2
|
+
require 'active_support/core_ext/hash'
|
3
|
+
|
4
|
+
module HawatelSearchJobs
|
5
|
+
module Api
|
6
|
+
##
|
7
|
+
# = Carerrbuilder API
|
8
|
+
#
|
9
|
+
# @see http://api.careerbuilder.com/Search/jobsearch/jobsearchinfo.aspx
|
10
|
+
module Careerbuilder
|
11
|
+
class << self
|
12
|
+
include HawatelSearchJobs::Helpers::Base
|
13
|
+
|
14
|
+
DEFAULT = {
|
15
|
+
:keywords => '',
|
16
|
+
:location => '',
|
17
|
+
:company => ''
|
18
|
+
}
|
19
|
+
|
20
|
+
RESULT_LIMIT = 25
|
21
|
+
|
22
|
+
# Search jobs by specific criteria
|
23
|
+
# @param [Hash] args
|
24
|
+
# @option args :settings [Hash] search criteria
|
25
|
+
# - *:api* (String) - URL API (default: api.careerbuilder.com)
|
26
|
+
# - *:version* (String) - a version of API (default: v2)
|
27
|
+
# - *:clientid* (String) - Private Developer Key (see http://developer.careerbuilder.com)
|
28
|
+
# @option args :query [Hash] settings of API
|
29
|
+
# - *:keywors* (String)
|
30
|
+
# - *:location* (String)
|
31
|
+
# - *:company* (String)
|
32
|
+
# @example
|
33
|
+
# jobs = Careerbuilder.search({:settings => {
|
34
|
+
# :api => 'api.careerbuilder.com',
|
35
|
+
# :version => 'v2',
|
36
|
+
# :clientid => 'secret-code'},
|
37
|
+
# :query => {
|
38
|
+
# :keywords => 'ruby',
|
39
|
+
# :location => 'London',
|
40
|
+
# :company => ''}})
|
41
|
+
# @return [Hash] First page of the result (see constant RESULT_LIMIT)
|
42
|
+
def search(args)
|
43
|
+
args[:query] = DEFAULT.merge(args[:query]) if args[:query]
|
44
|
+
|
45
|
+
if args[:query_key].nil?
|
46
|
+
url_request = prepare_conn_string(args) + prepare_query(args)
|
47
|
+
else
|
48
|
+
url_request = args[:query_key]
|
49
|
+
end
|
50
|
+
|
51
|
+
response = send_request(url_request)
|
52
|
+
attributes = build_jobs_table(response, url_request)
|
53
|
+
OpenStruct.new(attributes)
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
# Get a specific page result
|
58
|
+
# At the beging you have to run {search} method and get :key from result and pass it to the argument :query_key
|
59
|
+
# @param [Hash] args
|
60
|
+
# @option args :settings [Hash] see {search}
|
61
|
+
# @option args [Integer] :page page number counted from 0
|
62
|
+
# @option args [String] :query_key
|
63
|
+
# @example
|
64
|
+
# jobs = Careerbuilder.page({:settings => {
|
65
|
+
# :api => 'api.careerbuilder.com',
|
66
|
+
# :version => 'v2',
|
67
|
+
# :clientid => 'secret-code'},
|
68
|
+
# :page => 5,
|
69
|
+
# :query_key => 'value from :key returned by search method'})
|
70
|
+
# @return [Hash] Job offers from specific page
|
71
|
+
def page(args)
|
72
|
+
page = args[:page].to_i || 0
|
73
|
+
if args[:query_key]
|
74
|
+
url_request = args[:query_key].gsub(/&PageNumber=\d+/, '') << "&PageNumber=#{page+1}"
|
75
|
+
args[:query_key] = url_request
|
76
|
+
search(args)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def build_jobs_table(response, url_request)
|
83
|
+
attributes = Hash.new
|
84
|
+
attributes[:code] = response.code.to_i
|
85
|
+
attributes[:msg] = response.message
|
86
|
+
|
87
|
+
attributes[:totalResults] = 0
|
88
|
+
attributes[:page] = nil
|
89
|
+
attributes[:last] = nil
|
90
|
+
attributes[:key] = url_request
|
91
|
+
attributes[:jobs] = nil
|
92
|
+
|
93
|
+
if response.code.to_i == 200
|
94
|
+
xml_response = Hash.from_xml(response.body.gsub('\n', ''))
|
95
|
+
begin
|
96
|
+
if xml_response['ResponseJobSearch'] && xml_response['ResponseJobSearch']['Results']
|
97
|
+
attributes[:totalResults] = xml_response['ResponseJobSearch']['TotalCount'].to_i || 0
|
98
|
+
attributes[:page] = get_page_number(url_request) - 1
|
99
|
+
attributes[:last] = xml_response['ResponseJobSearch']['TotalPages'].to_i - 1
|
100
|
+
attributes[:key] = url_request
|
101
|
+
attributes[:jobs] = parse_raw_data(xml_response)
|
102
|
+
end
|
103
|
+
rescue
|
104
|
+
raise "Something wrong with returned data: #{xml_response}"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
attributes
|
108
|
+
end
|
109
|
+
|
110
|
+
def prepare_query(args)
|
111
|
+
"Keywords=#{args[:query][:keywords]}&" \
|
112
|
+
"Location=#{args[:query][:location]}&" \
|
113
|
+
"CompanyName=#{args[:query][:company]}"
|
114
|
+
end
|
115
|
+
|
116
|
+
def prepare_conn_string(args)
|
117
|
+
conn_string = "https://#{args[:settings][:api]}/#{args[:settings][:version]}/jobsearch?" \
|
118
|
+
"PerPage=#{RESULT_LIMIT}&DeveloperKey=#{args[:settings][:clientid]}&"
|
119
|
+
|
120
|
+
conn_string
|
121
|
+
end
|
122
|
+
|
123
|
+
def parse_raw_data(data)
|
124
|
+
jobs = Array.new
|
125
|
+
data['ResponseJobSearch']['Results']['JobSearchResult'].each do |offer|
|
126
|
+
job = Hash.new
|
127
|
+
job[:jobtitle] = offer['JobTitle'] if offer['JobTitle']
|
128
|
+
|
129
|
+
country = get_country_name(offer['State'], data['ResponseJobSearch']['SearchMetaData']['SearchLocations'])
|
130
|
+
location = country
|
131
|
+
location += ", #{offer['City']}" if offer['City'] && country != offer['City']
|
132
|
+
job[:location] = location
|
133
|
+
job[:company] = offer['Company']
|
134
|
+
|
135
|
+
newdate = offer['PostedDate'].split('/')
|
136
|
+
job[:date] = "#{newdate[1]}/#{newdate[0]}/#{newdate[2]}"
|
137
|
+
|
138
|
+
job[:date] = convert_date_to_format(job[:date],'%d/%m/%y')
|
139
|
+
job[:url] = offer['JobDetailsURL']
|
140
|
+
|
141
|
+
job = convert_empty_to_nil(job)
|
142
|
+
|
143
|
+
jobs << OpenStruct.new(job)
|
144
|
+
end
|
145
|
+
jobs
|
146
|
+
rescue
|
147
|
+
raise "Cannot parse raw data - #{data.inspect}"
|
148
|
+
end
|
149
|
+
|
150
|
+
def get_country_name(code, locations)
|
151
|
+
locations.each do |loc|
|
152
|
+
if loc[1]['StateCode'] && code && code.to_s == loc[1]['StateCode'].to_s
|
153
|
+
return loc[1]['City'] if loc[1]['City']
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
'United States'
|
158
|
+
rescue
|
159
|
+
raise "Cannot get country name (code=#{code}, locations=#{locations}"
|
160
|
+
end
|
161
|
+
|
162
|
+
def get_page_number(url)
|
163
|
+
result = url.match(/\&PageNumber=(\d+)/)
|
164
|
+
result ? result[1].to_i : 1
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
170
|
end
|