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

Class Method Details

.page(args) ⇒ Hash<OpenStrunct>

Show next page of results

Examples:

page({:query_key => result.key, :page => 2}

Parameters:

  • args (Hash)

Options Hash (args):

  • :page (Integer)

    specified page number (default 0)

  • :query_key (String)

    full url from last query

Returns:

  • (Hash<OpenStrunct>)


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

Examples:

search(:settings => HawatelSearchJobs.careerjet,:query => {:keywords => 'ruby'})
search(:query_key => 'http://api.../search?locale_code=US_en&sort=date&keywords=ruby', :page => 0)

Parameters:

  • args (Hash)

Options Hash (args):

  • :query (Hash)

    search criteria

    • :keywords​ (String) - keywords for search

  • :page (Integer)

    page number (default value 0)

  • :query_key (String)

    option provided by page() method

Returns:

  • (Hash<OpenStruct>)


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.message
      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