Class: Simplyhired::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/simplyhired/client.rb

Defined Under Namespace

Classes: Handler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
# 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

Instance Attribute Details

#cityObject (readonly)

Returns the value of attribute city.



6
7
8
# File 'lib/simplyhired/client.rb', line 6

def city
  @city
end

#current_pageObject (readonly)

Returns the value of attribute current_page.



6
7
8
# File 'lib/simplyhired/client.rb', line 6

def current_page
  @current_page
end

#daysObject (readonly)

Returns the value of attribute days.



6
7
8
# File 'lib/simplyhired/client.rb', line 6

def days
  @days
end

#distanceObject (readonly)

Returns the value of attribute distance.



6
7
8
# File 'lib/simplyhired/client.rb', line 6

def distance
  @distance
end

#errorObject (readonly)

Returns the value of attribute error.



6
7
8
# File 'lib/simplyhired/client.rb', line 6

def error
  @error
end

#jobsObject (readonly)

Returns the value of attribute jobs.



6
7
8
# File 'lib/simplyhired/client.rb', line 6

def jobs
  @jobs
end

#keywordsObject (readonly)

Returns the value of attribute keywords.



6
7
8
# File 'lib/simplyhired/client.rb', line 6

def keywords
  @keywords
end

#locationObject (readonly)

Returns the value of attribute location.



6
7
8
# File 'lib/simplyhired/client.rb', line 6

def location
  @location
end

#page_sizeObject (readonly)

Returns the value of attribute page_size.



6
7
8
# File 'lib/simplyhired/client.rb', line 6

def page_size
  @page_size
end

#query_typeObject (readonly)

Returns the value of attribute query_type.



6
7
8
# File 'lib/simplyhired/client.rb', line 6

def query_type
  @query_type
end

#stateObject (readonly)

Returns the value of attribute state.



6
7
8
# File 'lib/simplyhired/client.rb', line 6

def state
  @state
end

#zipObject (readonly)

Returns the value of attribute zip.



6
7
8
# File 'lib/simplyhired/client.rb', line 6

def zip
  @zip
end

Instance Method Details

#nextObject



42
43
44
45
46
47
48
49
50
# 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 = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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_foundObject



51
52
53
# File 'lib/simplyhired/client.rb', line 51

def total_jobs_found
	@accessible_count || 0
end