Class: Townhog::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
18
# File 'lib/townhog.rb', line 10

def initialize(*args)
  options = args.extract_options!
  @conn = Faraday.new(:url => "http://townhog.com") do |builder|
    builder.adapter Faraday.default_adapter
    builder.adapter  :logger if options[:debug] == true
    builder.use Faraday::Response::ParseJson
    builder.use Faraday::Response::Mashify
  end
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



8
9
10
# File 'lib/townhog.rb', line 8

def api_key
  @api_key
end

#connObject (readonly)

Returns the value of attribute conn.



8
9
10
# File 'lib/townhog.rb', line 8

def conn
  @conn
end

Instance Method Details

#categories(*args) ⇒ Object



27
28
29
30
31
32
# File 'lib/townhog.rb', line 27

def categories(*args)
  options = args.extract_options!
  response = conn.get("/api/category-id-info/all/json") 
  ret = response.body.townhog_api.category
  ret
end

#cities(*args) ⇒ Object



33
34
35
36
37
38
# File 'lib/townhog.rb', line 33

def cities(*args)
  options = args.extract_options!
  response = conn.get("/api/city-id-info/all/json") 
  ret = response.body.townhog_api.city
  ret
end

#deals(*args) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/townhog.rb', line 20

def deals(*args)
  options = args.extract_options!
  options.merge!(:city_id => "all") if options[:city_id].nil?
  response = conn.get("/api/all-deals/#{options[:city_id]}/json/#{options[:affiliate_id]}") 
  ret = response.body.townhog_api.deal
  ret
end