Class: Dice::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/dice/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client



12
13
14
15
16
17
18
19
20
21
# File 'lib/dice/client.rb', line 12

def initialize(options = {})
  self.text = options[:text] || '' 
  self.area_coode = options[:area_coode] || ''
  self.country = options[:country] || ''
  self.state = options[:state] || ''
  self.skill = options[:skill] || ''
  self.city = options[:city] || ''
  self.text = options[:text] || ''
  self.page = options[:page] || ''
end

Instance Attribute Details

#area_coodeObject

attr_reader :uri, :options



10
11
12
# File 'lib/dice/client.rb', line 10

def area_coode
  @area_coode
end

#cityObject

attr_reader :uri, :options



10
11
12
# File 'lib/dice/client.rb', line 10

def city
  @city
end

#countryObject

attr_reader :uri, :options



10
11
12
# File 'lib/dice/client.rb', line 10

def country
  @country
end

#pageObject

attr_reader :uri, :options



10
11
12
# File 'lib/dice/client.rb', line 10

def page
  @page
end

#skillObject

attr_reader :uri, :options



10
11
12
# File 'lib/dice/client.rb', line 10

def skill
  @skill
end

#stateObject

attr_reader :uri, :options



10
11
12
# File 'lib/dice/client.rb', line 10

def state
  @state
end

#textObject

attr_reader :uri, :options



10
11
12
# File 'lib/dice/client.rb', line 10

def text
  @text
end

Instance Method Details

#encoded_uriObject



29
30
31
# File 'lib/dice/client.rb', line 29

def encoded_uri
  URI.encode("?text=#{self.text}&areacode=#{self.area_coode}&country=#{self.country}&state=#{self.state}&skill=#{self.skill}&city=#{self.city}&page=#{self.page}")
end

#searchObject



23
24
25
26
27
# File 'lib/dice/client.rb', line 23

def search
  results = []
  self.class.get(encoded_uri)['resultItemList'].map { |data| results <<  Dice::Result.new(data: data) } 
  results
end