hawatel_search_jobs 0.1.3 → 0.2.0
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 +17 -18
- 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 +12 -7
- 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 +172 -169
- data/lib/hawatel_search_jobs/api/careerjet.rb +131 -126
- data/lib/hawatel_search_jobs/api/indeed.rb +166 -157
- data/lib/hawatel_search_jobs/api/reed.rb +189 -185
- data/lib/hawatel_search_jobs/api/xing.rb +16 -6
- data/lib/hawatel_search_jobs/client.rb +170 -172
- data/lib/hawatel_search_jobs/version.rb +1 -1
- data/spec/careerbuilder_spec.rb +142 -82
- data/spec/careerjet_spec.rb +97 -58
- data/spec/client_spec.rb +75 -87
- data/spec/indeed_spec.rb +97 -59
- data/spec/reed_spec.rb +93 -77
- data/spec/spec_helper.rb +2 -2
- data/spec/xing_spec.rb +66 -46
- metadata +2 -2
@@ -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,173 @@
|
|
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
|
-
|
118
|
-
|
119
|
-
|
120
|
-
conn_string
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
job[:
|
137
|
-
|
138
|
-
|
139
|
-
job[:
|
140
|
-
|
141
|
-
job
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
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
|
+
page_size = args[:settings][:page_size].to_s.empty? ? RESULT_LIMIT : args[:settings][:page_size].to_i
|
118
|
+
page_size = RESULT_LIMIT if page_size <= 0 || page_size > 100
|
119
|
+
|
120
|
+
conn_string = "https://#{args[:settings][:api]}/#{args[:settings][:version]}/jobsearch?" \
|
121
|
+
"PerPage=#{page_size}&OrderBy=Date&DeveloperKey=#{args[:settings][:clientid]}&"
|
122
|
+
|
123
|
+
conn_string
|
124
|
+
end
|
125
|
+
|
126
|
+
def parse_raw_data(data)
|
127
|
+
jobs = Array.new
|
128
|
+
data['ResponseJobSearch']['Results']['JobSearchResult'].each do |offer|
|
129
|
+
job = Hash.new
|
130
|
+
job[:jobtitle] = offer['JobTitle'] if offer['JobTitle']
|
131
|
+
|
132
|
+
country = get_country_name(offer['State'], data['ResponseJobSearch']['SearchMetaData']['SearchLocations'])
|
133
|
+
location = country
|
134
|
+
location += ", #{offer['City']}" if offer['City'] && country != offer['City']
|
135
|
+
job[:location] = location
|
136
|
+
job[:company] = offer['Company']
|
137
|
+
|
138
|
+
newdate = offer['PostedDate'].split('/')
|
139
|
+
job[:date] = "#{newdate[1]}/#{newdate[0]}/#{newdate[2]}"
|
140
|
+
|
141
|
+
job[:date] = convert_date_to_format(job[:date],'%d/%m/%y')
|
142
|
+
job[:url] = offer['JobDetailsURL']
|
143
|
+
|
144
|
+
job = convert_empty_to_nil(job)
|
145
|
+
|
146
|
+
jobs << OpenStruct.new(job)
|
147
|
+
end
|
148
|
+
jobs
|
149
|
+
rescue
|
150
|
+
raise "Cannot parse raw data - #{data.inspect}"
|
151
|
+
end
|
152
|
+
|
153
|
+
def get_country_name(code, locations)
|
154
|
+
locations.each do |loc|
|
155
|
+
if loc[1]['StateCode'] && code && code.to_s == loc[1]['StateCode'].to_s
|
156
|
+
return loc[1]['City'] if loc[1]['City']
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
'United States'
|
161
|
+
rescue
|
162
|
+
raise "Cannot get country name (code=#{code}, locations=#{locations}"
|
163
|
+
end
|
164
|
+
|
165
|
+
def get_page_number(url)
|
166
|
+
result = url.match(/\&PageNumber=(\d+)/)
|
167
|
+
result ? result[1].to_i : 1
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
170
173
|
end
|
@@ -1,126 +1,131 @@
|
|
1
|
-
module HawatelSearchJobs
|
2
|
-
module Api
|
3
|
-
module CareerJet
|
4
|
-
class << self
|
5
|
-
include HawatelSearchJobs::Helpers::Base
|
6
|
-
|
7
|
-
DEFAULT = {
|
8
|
-
:keywords => '',
|
9
|
-
:location => '',
|
10
|
-
:company => ''
|
11
|
-
}
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# @option args [
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# @
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
if args[:
|
31
|
-
|
32
|
-
|
33
|
-
url_request = args
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
attributes[:
|
52
|
-
attributes[:
|
53
|
-
attributes[:
|
54
|
-
|
55
|
-
|
56
|
-
OpenStruct.new(
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
#
|
63
|
-
#
|
64
|
-
# @
|
65
|
-
#
|
66
|
-
# @
|
67
|
-
#
|
68
|
-
#
|
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
|
-
job
|
117
|
-
job =
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
end
|
1
|
+
module HawatelSearchJobs
|
2
|
+
module Api
|
3
|
+
module CareerJet
|
4
|
+
class << self
|
5
|
+
include HawatelSearchJobs::Helpers::Base
|
6
|
+
|
7
|
+
DEFAULT = {
|
8
|
+
:keywords => '',
|
9
|
+
:location => '',
|
10
|
+
:company => ''
|
11
|
+
}
|
12
|
+
|
13
|
+
RESULT_LIMIT = 25
|
14
|
+
|
15
|
+
# Search jobs based on specified keywords or location
|
16
|
+
#
|
17
|
+
# @param args [Hash]
|
18
|
+
# @option args :query [Hash] search criteria
|
19
|
+
# - *:keywords* (String) - keywords for search
|
20
|
+
# @option args [Integer] :page page number (default value 0)
|
21
|
+
# @option args [String] :query_key option provided by page() method
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
# search(:settings => HawatelSearchJobs.careerjet,:query => {:keywords => 'ruby'})
|
25
|
+
# search(:query_key => 'http://api.../search?locale_code=US_en&sort=date&keywords=ruby', :page => 0)
|
26
|
+
#
|
27
|
+
# @return [Hash<OpenStruct>]
|
28
|
+
def search(args)
|
29
|
+
args[:query] = DEFAULT.merge(args[:query]) if args[:query]
|
30
|
+
args[:page] = 0 if args[:page].nil?
|
31
|
+
|
32
|
+
if args[:query_key].to_s.empty?
|
33
|
+
url_request = build_url(args)
|
34
|
+
else
|
35
|
+
url_request = args[:query_key]
|
36
|
+
end
|
37
|
+
|
38
|
+
if url_request
|
39
|
+
attributes = Hash.new
|
40
|
+
response = send_request(url_request)
|
41
|
+
result = JSON(response.body)
|
42
|
+
if response.code == '200' && result['type'] == 'ERROR'
|
43
|
+
attributes[:code] = 501
|
44
|
+
attributes[:msg] = result['error']
|
45
|
+
return OpenStruct.new(attributes)
|
46
|
+
else
|
47
|
+
attributes[:code] = response.code
|
48
|
+
attributes[:msg] = response.message
|
49
|
+
return OpenStruct.new(attributes) if response.code != '200'
|
50
|
+
end
|
51
|
+
attributes[:totalResults] = result['hits']
|
52
|
+
attributes[:page] = args[:page]
|
53
|
+
attributes[:last] = result['pages'] - 1
|
54
|
+
attributes[:key] = url_request
|
55
|
+
attributes[:jobs] = parse_raw_data(result)
|
56
|
+
OpenStruct.new(attributes)
|
57
|
+
else
|
58
|
+
OpenStruct.new({:code => 501, :msg => 'lack of keywords or api setting'})
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Show next page of results
|
63
|
+
#
|
64
|
+
# @param args [Hash]
|
65
|
+
# @option args [Integer] :page specified page number (default 0)
|
66
|
+
# @option args [String] :query_key full url from last query
|
67
|
+
#
|
68
|
+
# @example
|
69
|
+
# page({:query_key => result.key, :page => 2}
|
70
|
+
#
|
71
|
+
# @return [Hash<OpenStrunct>]
|
72
|
+
def page(args)
|
73
|
+
args[:page] = 0 if args[:page].nil?
|
74
|
+
args[:query_key] = args[:query_key].gsub(/&page=.*/, '') << "&page=#{args[:page]+1}"
|
75
|
+
return search(args)
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
# Build query URL
|
81
|
+
#
|
82
|
+
# @param args [Hash]
|
83
|
+
# @option args query [Hash] - search criteria
|
84
|
+
# - *:keywords* (String) - keywords for search
|
85
|
+
# - *:location* (String) - specified location for search criteria (default: europe)
|
86
|
+
# @option settings [Hash]
|
87
|
+
# - *:api* (String) - api ip or domainname
|
88
|
+
#
|
89
|
+
# @example
|
90
|
+
# build_url(:query => {:keywords => 'ruby'}, :settings => {:api => 'http://api...'} }
|
91
|
+
#
|
92
|
+
# @return [String] ready to call URL
|
93
|
+
def build_url(args)
|
94
|
+
keywords = args[:query][:keywords] if !args[:query][:keywords].to_s.empty?
|
95
|
+
api_url = args[:settings][:api] if !args[:settings][:api].to_s.empty?
|
96
|
+
page_size = args[:settings][:page_size].to_s.empty? ? RESULT_LIMIT : args[:settings][:page_size].to_i
|
97
|
+
page_size = RESULT_LIMIT if page_size <= 0 || page_size > 99
|
98
|
+
|
99
|
+
if keywords && api_url
|
100
|
+
!args[:query][:location].to_s.empty? ? location = args[:query][:location] : location = 'worldwide'
|
101
|
+
"http://#{api_url}/search?locale_code=US_en&pagesize=#{page_size}&sort=date&keywords=#{keywords}&location=#{location}&page=1"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
# Build jobs array with specified attributes
|
107
|
+
#
|
108
|
+
# @param result [Hash]
|
109
|
+
# @option result [Hash] :jobs jobs hash array return from API
|
110
|
+
#
|
111
|
+
# @return [Array<OpenStruct>]
|
112
|
+
def parse_raw_data(result)
|
113
|
+
jobs = Array.new
|
114
|
+
return jobs if result['jobs'].to_s.empty?
|
115
|
+
result['jobs'].each do |offer|
|
116
|
+
job = Hash.new
|
117
|
+
job[:jobtitle] = offer['title']
|
118
|
+
job[:location] = offer['locations']
|
119
|
+
job[:company] = offer['company']
|
120
|
+
job[:date] = convert_date_to_format(offer['date'],'%d/%m/%y')
|
121
|
+
job[:url] = offer['url']
|
122
|
+
job = convert_empty_to_nil(job)
|
123
|
+
jobs << OpenStruct.new(job)
|
124
|
+
end
|
125
|
+
return jobs
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|