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,158 +1,167 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
require 'net/http'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
module HawatelSearchJobs
|
6
|
-
module Api
|
7
|
-
module Indeed
|
8
|
-
class << self
|
9
|
-
include HawatelSearchJobs::Helpers::Base
|
10
|
-
|
11
|
-
DEFAULT = {
|
12
|
-
:keywords => '',
|
13
|
-
:location => '',
|
14
|
-
:company => ''
|
15
|
-
}
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# @
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
# - *:
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
attributes[:
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
attributes[:
|
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
|
-
|
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
|
-
|
1
|
+
require 'ostruct'
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module HawatelSearchJobs
|
6
|
+
module Api
|
7
|
+
module Indeed
|
8
|
+
class << self
|
9
|
+
include HawatelSearchJobs::Helpers::Base
|
10
|
+
|
11
|
+
DEFAULT = {
|
12
|
+
:keywords => '',
|
13
|
+
:location => '',
|
14
|
+
:company => ''
|
15
|
+
}
|
16
|
+
|
17
|
+
RESULT_LIMIT = 25
|
18
|
+
|
19
|
+
# Search jobs based on specified keywords or location
|
20
|
+
#
|
21
|
+
# @param args [Hash]
|
22
|
+
# @option args [String] :query_key full url from last query, option deliverd by page() method
|
23
|
+
# @option args :query [Hash] search criteria
|
24
|
+
# - *:keywords* (String) keywords for search
|
25
|
+
# - *:location* (String) specified location for search criteria (default all countries)
|
26
|
+
# @option args :settings [Hash]
|
27
|
+
# - *:api* (String) hostname or ip address api server
|
28
|
+
# - *:publisher* (String) authentication string
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
# search(:settings => HawatelSearchJobs.indeed,:query => {:keywords => 'ruby'})
|
32
|
+
# search(:query_key => 'http://api.../ads/apisearch?publisher=12323&q=ruby')
|
33
|
+
#
|
34
|
+
# @return [Hash<OpenStruct>]
|
35
|
+
def search(args)
|
36
|
+
args[:query] = DEFAULT.merge(args[:query]) if args[:query]
|
37
|
+
args[:page_size] = args[:settings][:page_size].to_s.empty? ? RESULT_LIMIT : args[:settings][:page_size].to_i
|
38
|
+
args[:page_size] = RESULT_LIMIT if args[:page_size] <= 0 || args[:page_size] > 25
|
39
|
+
|
40
|
+
if args[:query_key].to_s.empty?
|
41
|
+
url_request = build_url(args)
|
42
|
+
else
|
43
|
+
url_request = args[:query_key]
|
44
|
+
end
|
45
|
+
|
46
|
+
if url_request
|
47
|
+
attributes = Hash.new
|
48
|
+
response = send_request(url_request)
|
49
|
+
result = JSON(response.body)
|
50
|
+
if response.code == '200' && result['error']
|
51
|
+
attributes[:code] = 501
|
52
|
+
attributes[:msg] = result['error']
|
53
|
+
return OpenStruct.new(attributes)
|
54
|
+
else
|
55
|
+
attributes[:code] = response.code
|
56
|
+
attributes[:msg] = response.message
|
57
|
+
return OpenStruct.new(attributes) if response.code != '200'
|
58
|
+
end
|
59
|
+
attributes[:totalResults] = result['totalResults']
|
60
|
+
attributes[:page] = result['pageNumber']
|
61
|
+
attributes[:last] = paging_info(args[:page_size], result['totalResults'])
|
62
|
+
attributes[:key] = url_request
|
63
|
+
attributes[:jobs] = parse_raw_data(result)
|
64
|
+
OpenStruct.new(attributes)
|
65
|
+
else
|
66
|
+
OpenStruct.new({:code => 501, :msg => 'lack of api or publisher setting'})
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Show next page of results
|
71
|
+
#
|
72
|
+
# @param args [Hash]
|
73
|
+
# @option args [Integer] :page page number (default 0)
|
74
|
+
# @option args [String] :query_key url from last query
|
75
|
+
#
|
76
|
+
# @example
|
77
|
+
# page({:query_key => result.key, :page => 2}
|
78
|
+
#
|
79
|
+
# @return [Hash<OpenStruct>]
|
80
|
+
def page(args)
|
81
|
+
args[:page] = 0 if args[:page].nil?
|
82
|
+
page_size = args[:settings][:page_size].to_s.empty? ? RESULT_LIMIT : args[:settings][:page_size].to_i
|
83
|
+
page_size = RESULT_LIMIT if page_size <= 0 || page_size > 25
|
84
|
+
|
85
|
+
if args[:query_key]
|
86
|
+
url = args[:query_key].gsub(/&start=.*/, '') << "&start=#{args[:page]*page_size}"
|
87
|
+
search({:settings => args[:settings], :query_key => url})
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
# Build query URL
|
93
|
+
#
|
94
|
+
# @param args [Hash]
|
95
|
+
# option args :query [Hash]
|
96
|
+
# - *:keywords* (String) keywords for search
|
97
|
+
# - *:location* (String) search jobs from specified location
|
98
|
+
# - *:salary* (String) show only position above specified salary
|
99
|
+
# - *:company* (String) find position from specified company
|
100
|
+
# @option args :settings [Hash]
|
101
|
+
# - *:api* (String) hostname or ip address api server
|
102
|
+
# - *:publisher* (String) authentication string
|
103
|
+
#
|
104
|
+
# @example
|
105
|
+
# build_url(:query => {:keywords => 'ruby'}, :settings => {:api => 'http://api...',:publisher => '23234'}}
|
106
|
+
#
|
107
|
+
# @return [String]
|
108
|
+
def build_url(args)
|
109
|
+
api_url = args[:settings][:api]
|
110
|
+
publisher = args[:settings][:publisher]
|
111
|
+
version = args[:settings][:version].to_s.empty? ? '2' : args[:settings][:version]
|
112
|
+
location = args[:query][:location]
|
113
|
+
salary = args[:query][:salary]
|
114
|
+
company = args[:query][:company]
|
115
|
+
keywords = args[:query][:keywords]
|
116
|
+
page_size = args[:page_size]
|
117
|
+
|
118
|
+
if !keywords.to_s.empty? && !company.to_s.empty?
|
119
|
+
keywords = "company:#{company}+#{keywords}"
|
120
|
+
elsif keywords.to_s.empty? && !company.to_s.empty?
|
121
|
+
keywords = "company:#{company}"
|
122
|
+
end
|
123
|
+
if api_url && publisher
|
124
|
+
"http://#{api_url}/ads/apisearch?publisher=#{publisher}&q=#{keywords}&salary=#{salary}&l=#{location}"\
|
125
|
+
"&v=#{version}&sort=date&format=json&limit=#{page_size}&start=0"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# Build jobs array with specified attributes
|
130
|
+
#
|
131
|
+
# @param result [Hash]
|
132
|
+
# @option result [Hash] :results job attributes
|
133
|
+
#
|
134
|
+
# @return [Array<OpenStruct>]
|
135
|
+
def parse_raw_data(result)
|
136
|
+
jobs = Array.new
|
137
|
+
return jobs if result['results'].to_s.empty?
|
138
|
+
result['results'].each do |offer|
|
139
|
+
job = Hash.new
|
140
|
+
job[:jobtitle] = offer['jobtitle'] if offer['jobtitle']
|
141
|
+
job[:location] = "#{offer['country']}, #{offer['city']}"
|
142
|
+
job[:company] = offer['company']
|
143
|
+
job[:date] = convert_date_to_format(offer['date'],'%d/%m/%y')
|
144
|
+
job[:url] = offer['url']
|
145
|
+
job = convert_empty_to_nil(job)
|
146
|
+
jobs << OpenStruct.new(job)
|
147
|
+
end
|
148
|
+
return jobs
|
149
|
+
end
|
150
|
+
|
151
|
+
def paging_info(limit, total_result)
|
152
|
+
return nil if total_result == 0
|
153
|
+
|
154
|
+
mod = total_result.to_i % limit.to_i
|
155
|
+
if mod == 0
|
156
|
+
last = (total_result.to_i / limit.to_i) - 1
|
157
|
+
else
|
158
|
+
last = (total_result.to_i / limit.to_i).to_i
|
159
|
+
end
|
160
|
+
|
161
|
+
last
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
158
167
|
end
|
@@ -1,186 +1,190 @@
|
|
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[:
|
42
|
-
|
43
|
-
|
44
|
-
url_request = args
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
#
|
55
|
-
#
|
56
|
-
# @
|
57
|
-
# @option args [
|
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
|
-
attributes
|
85
|
-
attributes[:
|
86
|
-
attributes[:
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
attributes[:
|
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
|
-
end
|
131
|
-
|
132
|
-
def
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
job
|
141
|
-
|
142
|
-
job =
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
end
|
155
|
-
|
156
|
-
def
|
157
|
-
|
158
|
-
|
159
|
-
end
|
160
|
-
|
161
|
-
def
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
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
|
+
args[:page_size] = args[:settings][:page_size].to_s.empty? ? RESULT_LIMIT : args[:settings][:page_size].to_i
|
41
|
+
args[:page_size] = RESULT_LIMIT if args[:page_size] <= 0 || args[:page_size] > 100
|
42
|
+
|
43
|
+
if args[:query_key].nil?
|
44
|
+
url_request = prepare_conn_string(args) + prepare_query(args)
|
45
|
+
else
|
46
|
+
url_request = args[:query_key]
|
47
|
+
end
|
48
|
+
|
49
|
+
response = api_request(url_request, args[:settings][:clientid])
|
50
|
+
attributes = build_jobs_table(response, url_request, args[:page_size])
|
51
|
+
OpenStruct.new(attributes)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Get a specific page result
|
55
|
+
# At the beging you have to run {search} method and get :key from result and pass it to the argument :query_key
|
56
|
+
# @param [Hash] args
|
57
|
+
# @option args :settings [Hash] see {search}
|
58
|
+
# @option args [Integer] :page page number counted from 0
|
59
|
+
# @option args [String] :query_key
|
60
|
+
# @example
|
61
|
+
# jobs = Careerbuilder.page({:settings => {
|
62
|
+
# :api => 'api.careerbuilder.com',
|
63
|
+
# :version => 'v2',
|
64
|
+
# :clientid => 'secret-code'},
|
65
|
+
# :page => 5,
|
66
|
+
# :query_key => 'value from :key returned by search method'})
|
67
|
+
# @return [Hash] Job offers from specific page
|
68
|
+
def page(args)
|
69
|
+
page = args[:page].to_i || 0
|
70
|
+
page_size = args[:settings][:page_size].to_s.empty? ? RESULT_LIMIT : args[:settings][:page_size].to_i
|
71
|
+
page_size = RESULT_LIMIT if page_size <= 0 || page_size > 100
|
72
|
+
|
73
|
+
if args[:query_key]
|
74
|
+
#limit = result_limit(args[:query_key])
|
75
|
+
url_request = args[:query_key].gsub(/&resultsToSkip=\d+/, '') << "&resultsToSkip=#{page * page_size}"
|
76
|
+
args[:query_key] = url_request
|
77
|
+
search(args)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def build_jobs_table(response, url_request, page_size)
|
84
|
+
attributes = Hash.new
|
85
|
+
attributes[:code] = response.code.to_i
|
86
|
+
attributes[:msg] = response.message
|
87
|
+
|
88
|
+
attributes[:totalResults] = 0
|
89
|
+
attributes[:page] = nil
|
90
|
+
attributes[:last] = nil
|
91
|
+
attributes[:key] = url_request
|
92
|
+
attributes[:jobs] = nil
|
93
|
+
|
94
|
+
|
95
|
+
if response.code.to_i == 200
|
96
|
+
json_response = JSON.parse(response.body)
|
97
|
+
begin
|
98
|
+
if !json_response['results'].to_s.empty?
|
99
|
+
attributes[:totalResults] = json_response['totalResults'] || 0
|
100
|
+
|
101
|
+
page_info = paging_info(url_request, attributes[:totalResults], page_size)
|
102
|
+
attributes[:page] = page_info.page
|
103
|
+
attributes[:last] = page_info.last
|
104
|
+
|
105
|
+
attributes[:key] = url_request
|
106
|
+
attributes[:jobs] = parse_raw_data(json_response)
|
107
|
+
end
|
108
|
+
rescue
|
109
|
+
raise "Something wrong with returned data: #{json_response}"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
attributes
|
113
|
+
end
|
114
|
+
|
115
|
+
def api_request(url, clientid = nil)
|
116
|
+
opt = Hash.new
|
117
|
+
|
118
|
+
if clientid
|
119
|
+
opt = { :basic_auth => {
|
120
|
+
:username => clientid,
|
121
|
+
:password => ''
|
122
|
+
}}
|
123
|
+
end
|
124
|
+
|
125
|
+
send_request(url, opt)
|
126
|
+
end
|
127
|
+
|
128
|
+
def prepare_query(args)
|
129
|
+
"keywords=#{args[:query][:keywords]}&locationName=#{args[:query][:location]}"
|
130
|
+
end
|
131
|
+
|
132
|
+
def prepare_conn_string(args)
|
133
|
+
conn_string = "https://#{args[:settings][:api]}/#{args[:settings][:version]}/search?resultsToTake=#{args[:page_size]}&"
|
134
|
+
conn_string
|
135
|
+
end
|
136
|
+
|
137
|
+
def parse_raw_data(data)
|
138
|
+
jobs = Array.new
|
139
|
+
data['results'].each do |offer|
|
140
|
+
job = Hash.new
|
141
|
+
job[:jobtitle] = offer['jobTitle'] if offer['jobTitle']
|
142
|
+
job[:location] = "United Kingdom, #{offer['locationName']}"
|
143
|
+
job[:company] = offer['employerName']
|
144
|
+
job[:date] = convert_date_to_format(offer['date'],'%d/%m/%y')
|
145
|
+
job[:url] = offer['jobUrl']
|
146
|
+
|
147
|
+
job = convert_empty_to_nil(job)
|
148
|
+
|
149
|
+
jobs << OpenStruct.new(job)
|
150
|
+
end
|
151
|
+
jobs
|
152
|
+
rescue
|
153
|
+
raise "Cannot parse raw data: #{data}"
|
154
|
+
end
|
155
|
+
|
156
|
+
# def result_limit(url)
|
157
|
+
# result = url.match(/\resultsToTake=(\d+)/)
|
158
|
+
# result ? result[1].to_i : RESULT_LIMIT
|
159
|
+
# end
|
160
|
+
|
161
|
+
def result_skip(url)
|
162
|
+
result = url.match(/\&resultsToSkip=(\d+)/)
|
163
|
+
result ? result[1].to_i : 0
|
164
|
+
end
|
165
|
+
|
166
|
+
def paging_info(url, total_result, page_size)
|
167
|
+
return OpenStruct.new({:page => nil, :last => nil}) if total_result == 0
|
168
|
+
|
169
|
+
result_skip = result_skip(url)
|
170
|
+
|
171
|
+
if result_skip == 0 && total_result > 0
|
172
|
+
page = 0
|
173
|
+
else
|
174
|
+
page = (result_skip / page_size).to_i
|
175
|
+
end
|
176
|
+
|
177
|
+
mod = total_result.to_i % page_size.to_i
|
178
|
+
if mod == 0
|
179
|
+
last = (total_result.to_i / page_size.to_i) - 1
|
180
|
+
else
|
181
|
+
last = (total_result.to_i / page_size.to_i).to_i
|
182
|
+
end
|
183
|
+
|
184
|
+
OpenStruct.new({:page => page, :last => last})
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
186
190
|
end
|