Module: HawatelSearchJobs::Api::Reed

Extended by:
Helpers::Base
Defined in:
lib/hawatel_search_jobs/api/reed.rb

Overview

Reed.co.uk API

Constant Summary collapse

DEFAULT =
{
    :keywords => '',
    :location => '',
}
RESULT_LIMIT =
25

Class Method Summary collapse

Class Method Details

.page(args) ⇒ Hash

Get a specific page result At the beging you have to run search method and get :key from result and pass it to the argument :query_key

Examples:

jobs = Careerbuilder.page({:settings => {
                                :api => 'api.careerbuilder.com',
                                :version => 'v2',
                                :clientid => 'secret-code'},
                           :page => 5,
                           :query_key => 'value from :key returned by search method'})

Parameters:

  • args (Hash)

Options Hash (args):

  • :settings (Hash)

    see search

  • :page (Integer)

    page number counted from 0

  • :query_key (String)

Returns:

  • (Hash)

    Job offers from specific page



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/hawatel_search_jobs/api/reed.rb', line 68

def page(args)
  page = args[:page].to_i || 0
  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 > 100

  if args[:query_key]
    #limit = result_limit(args[:query_key])
    url_request = args[:query_key].gsub(/&resultsToSkip=\d+/, '') << "&resultsToSkip=#{page * page_size}"
    args[:query_key] = url_request
    search(args)
  end
end

.search(args) ⇒ Hash

Search jobs by specific criteria

Examples:

jobs = Reed.search({:settings => {
                                :api => 'reed.co.uk/api',
                                :version => '1.0',
                                :clientid => 'secret-code'},
                             :query => {
                                :keywords => 'ruby',
                                :location => 'London'})

Parameters:

  • args (Hash)

Options Hash (args):

  • :settings (Hash)

    search criteria

  • :query (Hash)

    settings of API

    • :keywors (String)

    • :location (String)

Returns:

  • (Hash)

    First page of the result (see constant RESULT_LIMIT)



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hawatel_search_jobs/api/reed.rb', line 38

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] > 100

  if args[:query_key].nil?
    url_request = prepare_conn_string(args) + prepare_query(args)
  else
    url_request = args[:query_key]
  end

  response = api_request(url_request, args[:settings][:clientid])
  attributes = build_jobs_table(response, url_request, args[:page_size])
  OpenStruct.new(attributes)
end