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.
@@ -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
- # Search jobs based on specified keywords or location
18
- #
19
- # @param args [Hash]
20
- # @option args [String] :query_key full url from last query, option deliverd by page() method
21
- # @option args :query [Hash] search criteria
22
- # - *:keywords* (String) keywords for search
23
- # - *:location* (String) specified location for search criteria (default all countries)
24
- # @option args :settings [Hash]
25
- # - *:api* (String) hostname or ip address api server
26
- # - *:publisher* (String) authentication string
27
- #
28
- # @example
29
- # search(:settings => HawatelSearchJobs.indeed,:query => {:keywords => 'ruby'})
30
- # search(:query_key => 'http://api.../ads/apisearch?publisher=12323&q=ruby')
31
- #
32
- # @return [Hash<OpenStruct>]
33
- def search(args)
34
- args[:query] = DEFAULT.merge(args[:query]) if args[:query]
35
- if args[:query_key].to_s.empty?
36
- url_request = build_url(args)
37
- else
38
- url_request = args[:query_key]
39
- end
40
-
41
- if url_request
42
- attributes = Hash.new
43
- response = send_request(url_request)
44
- result = JSON(response.body)
45
- if response.code == '200' && result['error']
46
- attributes[:code] = 501
47
- attributes[:msg] = result['error']
48
- return OpenStruct.new(attributes)
49
- else
50
- attributes[:code] = response.code
51
- attributes[:msg] = response.message
52
- return OpenStruct.new(attributes) if response.code != '200'
53
- end
54
- attributes[:totalResults] = result['totalResults']
55
- attributes[:page] = result['pageNumber']
56
- #attributes[:last] = (result['totalResults'] / 25) - 1
57
- attributes[:last] = paging_info(25, result['totalResults'])
58
- attributes[:key] = url_request
59
- attributes[:jobs] = parse_raw_data(result)
60
- OpenStruct.new(attributes)
61
- else
62
- OpenStruct.new({:code => 501, :msg => 'lack of api or publisher setting'})
63
- end
64
- end
65
-
66
- # Show next page of results
67
- #
68
- # @param args [Hash]
69
- # @option args [Integer] :page page number (default 0)
70
- # @option args [String] :query_key url from last query
71
- #
72
- # @example
73
- # page({:query_key => result.key, :page => 2}
74
- #
75
- # @return [Hash<OpenStruct>]
76
- def page(args)
77
- args[:page] = 0 if args[:page].nil?
78
- if args[:query_key]
79
- url = args[:query_key].gsub(/&start=.*/, '') << "&start=#{args[:page]*25}"
80
- search({:query_key => url})
81
- end
82
- end
83
-
84
- private
85
- # Build query URL
86
- #
87
- # @param args [Hash]
88
- # option args :query [Hash]
89
- # - *:keywords* (String) keywords for search
90
- # - *:location* (String) search jobs from specified location
91
- # - *:salary* (String) show only position above specified salary
92
- # - *:company* (String) find position from specified company
93
- # @option args :settings [Hash]
94
- # - *:api* (String) hostname or ip address api server
95
- # - *:publisher* (String) authentication string
96
- #
97
- # @example
98
- # build_url(:query => {:keywords => 'ruby'}, :settings => {:api => 'http://api...',:publisher => '23234'}}
99
- #
100
- # @return [String]
101
- def build_url(args)
102
- api_url = args[:settings][:api]
103
- publisher = args[:settings][:publisher]
104
- location = args[:query][:location]
105
- salary = args[:query][:salary]
106
- company = args[:query][:company]
107
- keywords = args[:query][:keywords]
108
-
109
- if !keywords.to_s.empty? && !company.to_s.empty?
110
- keywords = "company:#{company}+#{keywords}"
111
- elsif keywords.to_s.empty? && !company.to_s.empty?
112
- keywords = "company:#{company}"
113
- end
114
- if api_url && publisher
115
- "http://#{api_url}/ads/apisearch?publisher=#{publisher}&q=#{keywords}&salary=#{salary}&l=#{location}"\
116
- "&v=2&format=json&limit=25&start=0"
117
- end
118
- end
119
-
120
- # Build jobs array with specified attributes
121
- #
122
- # @param result [Hash]
123
- # @option result [Hash] :results job attributes
124
- #
125
- # @return [Array<OpenStruct>]
126
- def parse_raw_data(result)
127
- jobs = Array.new
128
- return jobs if result['results'].to_s.empty?
129
- result['results'].each do |offer|
130
- job = Hash.new
131
- job[:jobtitle] = offer['jobtitle'] if offer['jobtitle']
132
- job[:location] = "#{offer['country']}, #{offer['city']}"
133
- job[:company] = offer['company']
134
- job[:date] = convert_date_to_format(offer['date'],'%d/%m/%y')
135
- job[:url] = offer['url']
136
- job = convert_empty_to_nil(job)
137
- jobs << OpenStruct.new(job)
138
- end
139
- return jobs
140
- end
141
-
142
- def paging_info(limit, total_result)
143
- return nil if total_result == 0
144
-
145
- mod = total_result.to_i % limit.to_i
146
- if mod == 0
147
- last = (total_result.to_i / limit.to_i) - 1
148
- else
149
- last = (total_result.to_i / limit.to_i).to_i
150
- end
151
-
152
- last
153
- end
154
-
155
- end
156
- end
157
- end
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[: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
+ 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