module HawatelSearchJobs::Api::Xing

Constants

DEFAULT
RESULT_LIMIT

Public Class Methods

page(args) click to toggle source

Show next page of results

@param args [Hash] @option page [Integer] page numer (default 0) @option query_key [String] keywords from last query

@example

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

@return [Hash<OpenStruct>]

# File lib/hawatel_search_jobs/api/xing.rb, line 57
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 > 100

  result = XingApi::Job.search(args[:query_key], {:limit => page_size, :offset => args[:page]*page_size})
  set_attributes({:result => result, :page => args[:page], :keywords => args[:query_key], :page_size => page_size})
rescue XingApi::Error => e
  {:code => e.status_code, :msg => e.text}
end

Private Class Methods

parse_raw_data(result) click to toggle source

Build jobs array with specified attributes

@return [Array<OpenStruct>]

# File lib/hawatel_search_jobs/api/xing.rb, line 101
def parse_raw_data(result)
  jobs = Array.new
  return jobs if result[:jobs].to_s.empty?
  result[:jobs][:items].each do |offer|
    job = Hash.new
    job[:jobtitle] = offer[:title]
    job[:location] = "#{offer[:location][:country]}, #{offer[:location][:city]}"
    job[:company]  = offer[:company][:name]
    job[:date]     = convert_date_to_format(offer[:published_at], '%d/%m/%y')
    job[:url]      = offer[:links][:xing]
    job = convert_empty_to_nil(job)
    jobs << OpenStruct.new(job)
  end
  return jobs
end
send_request(args) click to toggle source

Call Xing client request

@param args [Hash] @option settings [Hash] authentication attributes @option keywords [String] keywords for query

@return [Hash<OpenStruct>]

# File lib/hawatel_search_jobs/api/xing.rb, line 76
def send_request(args)
  set_settings(args[:settings])

  XingApi::Job.search(args[:keywords], {:limit => args[:page_size], :offset => 0})
rescue XingApi::Error => e
  {:code => e.status_code, :msg => e.text}
end
set_attributes(args) click to toggle source

Build final result - set required attributes and return openstruct object

# File lib/hawatel_search_jobs/api/xing.rb, line 86
def set_attributes(args)
  attributes = Hash.new
  attributes[:totalResults] = args[:result][:jobs][:total]
  attributes[:code]  = '200'
  attributes[:msg]   = "OK"
  attributes[:page]  = args[:page]
  attributes[:last]  = args[:result][:jobs][:total] / args[:page_size]
  attributes[:key]   = args[:keywords]
  attributes[:jobs]  = parse_raw_data(args[:result])
  OpenStruct.new(attributes)
end
set_settings(args) click to toggle source

Set settings for XingApi client

@param args [Hash]

# File lib/hawatel_search_jobs/api/xing.rb, line 120
def set_settings(args)
  XingApi::Client.configure do |config|
    config.consumer_key = args[:consumer_key]
    config.consumer_secret = args[:consumer_secret]
    config.oauth_token = args[:oauth_token]
    config.oauth_token_secret = args[:oauth_token_secret]
  end
end