class Simplyhired::Client
Attributes
city[R]
current_page[R]
days[R]
distance[R]
error[R]
jobs[R]
keywords[R]
location[R]
page_size[R]
query_type[R]
state[R]
zip[R]
Public Class Methods
new(ip)
click to toggle source
# File lib/simplyhired/client.rb, line 8 def initialize(ip) config_values = Simplyhired.config_values @pshid = config_values[:pshid] @jbd = config_values[:jbd] @credentials = "?pshid=#{@pshid}&ssty=2&cflg=r&jbd=#{@jbd}&clip=#{ip}" end
Public Instance Methods
next()
click to toggle source
# File lib/simplyhired/client.rb, line 42 def next if @current_page * @page_size < @accessible_count.to_i @current_page += 1 search @current_page else @jobs = nil end @jobs end
search_jobs(kw, z, c, s, options = {})
click to toggle source
# File lib/simplyhired/client.rb, line 15 def search_jobs(kw, z, c, s, options = {}) unless @pshid @error = 'define pshid in a configuration file' return nil end unless @jbd @error = 'define jbd in a configuration file' return nil end @query_type = options[:query_type] || :OR @zip = z @city = c && c.split.join('+') @state = s && s.split.join('+') @page_size = options[:ws] || 25 @distance = options[:distance] || 10 @days = options[:days] || 0 @keywords = kw @location = (@zip && !@zip.empty?) ? @zip : "#{@city},#{@state}" @current_page = options[:page] || 1 @uri = "" @jobs = nil search @current_page @jobs end
total_jobs_found()
click to toggle source
# File lib/simplyhired/client.rb, line 51 def total_jobs_found @accessible_count || 0 end
Private Instance Methods
search(p = 1)
click to toggle source
# File lib/simplyhired/client.rb, line 58 def search(p = 1) sh_prefix = 'http://api.simplyhired.com/a/jobs-api/xml-v2/q-' case @query_type when :AND kw = @keywords.join('+AND+') when :PHRASE kw = '"' + @keywords.join('+') + '"' else kw = @keywords.join('+') end qd = @days > 0 ? "/fdb-#{@days}" : "" @uri = sh_prefix + kw + "/l-#{@location}" + "/mi-#{@distance}" + qd +"/ws-#{@page_size}" + "/pn-#{p}" + @credentials @uri = URI.escape @uri # puts @uri handler = Handler.new begin io = open @uri Ox.sax_parse(handler, io) if handler.error @jobs = nil @error = handler.error else @jobs = handler.jobs @total_count = handler.total @accessible_count = handler.accessible_count.to_i end rescue Exception => e @error = "SimlyHired Error - " + e.to_s @jobs = nil @total_count = 0 @accessible_count = 0 end end