Module: HawatelSearchJobs::Api::Indeed
- Extended by:
- Helpers::Base
- Defined in:
- lib/hawatel_search_jobs/api/indeed.rb
Constant Summary collapse
- DEFAULT =
{ :keywords => '', :location => '', :company => '' }
- RESULT_LIMIT =
25
Class Method Summary collapse
-
.page(args) ⇒ Hash<OpenStruct>
Show next page of results.
-
.search(args) ⇒ Hash<OpenStruct>
Search jobs based on specified keywords or location.
Class Method Details
.page(args) ⇒ Hash<OpenStruct>
Show next page of results
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/hawatel_search_jobs/api/indeed.rb', line 80 def page(args) args[:page] = 0 if args[:page].nil? page_size = args[:settings][:page_size].to_s.empty? ? RESULT_LIMIT : args[:settings][:page_size].to_i page_size = RESULT_LIMIT if page_size <= 0 || page_size > 25 if args[:query_key] url = args[:query_key].gsub(/&start=.*/, '') << "&start=#{args[:page]*page_size}" search({:settings => args[:settings], :query_key => url}) end end |
.search(args) ⇒ Hash<OpenStruct>
Search jobs based on specified keywords or location
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/hawatel_search_jobs/api/indeed.rb', line 35 def search(args) args[:query] = DEFAULT.merge(args[:query]) if args[:query] args[:page_size] = args[:settings][:page_size].to_s.empty? ? RESULT_LIMIT : args[:settings][:page_size].to_i args[:page_size] = RESULT_LIMIT if args[:page_size] <= 0 || args[:page_size] > 25 if args[:query_key].to_s.empty? url_request = build_url(args) else url_request = args[:query_key] end if url_request attributes = Hash.new response = send_request(url_request) result = JSON(response.body) if response.code == '200' && result['error'] attributes[:code] = 501 attributes[:msg] = result['error'] return OpenStruct.new(attributes) else attributes[:code] = response.code attributes[:msg] = response. return OpenStruct.new(attributes) if response.code != '200' end attributes[:totalResults] = result['totalResults'] attributes[:page] = result['pageNumber'] attributes[:last] = paging_info(args[:page_size], result['totalResults']) attributes[:key] = url_request attributes[:jobs] = parse_raw_data(result) OpenStruct.new(attributes) else OpenStruct.new({:code => 501, :msg => 'lack of api or publisher setting'}) end end |