Module: HawatelSearchJobs::Api::CareerJet
- Extended by:
- Helpers::Base
- Defined in:
- lib/hawatel_search_jobs/api/careerjet.rb
Constant Summary collapse
- DEFAULT =
{ :keywords => '', :location => '', :company => '' }
- RESULT_LIMIT =
25
Class Method Summary collapse
-
.page(args) ⇒ Hash<OpenStrunct>
Show next page of results.
-
.search(args) ⇒ Hash<OpenStruct>
Search jobs based on specified keywords or location.
Class Method Details
.page(args) ⇒ Hash<OpenStrunct>
Show next page of results
72 73 74 75 76 |
# File 'lib/hawatel_search_jobs/api/careerjet.rb', line 72 def page(args) args[:page] = 0 if args[:page].nil? args[:query_key] = args[:query_key].gsub(/&page=.*/, '') << "&page=#{args[:page]+1}" return search(args) end |
.search(args) ⇒ Hash<OpenStruct>
Search jobs based on specified keywords or location
28 29 30 31 32 33 34 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 |
# File 'lib/hawatel_search_jobs/api/careerjet.rb', line 28 def search(args) args[:query] = DEFAULT.merge(args[:query]) if args[:query] args[:page] = 0 if args[:page].nil? 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['type'] == '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['hits'] attributes[:page] = args[:page] attributes[:last] = result['pages'] - 1 attributes[:key] = url_request attributes[:jobs] = parse_raw_data(result) OpenStruct.new(attributes) else OpenStruct.new({:code => 501, :msg => 'lack of keywords or api setting'}) end end |