Class: Townhog::Client
- Inherits:
-
Object
- Object
- Townhog::Client
- Defined in:
- lib/townhog.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
Instance Method Summary collapse
- #categories(*args) ⇒ Object
- #cities(*args) ⇒ Object
- #deals(*args) ⇒ Object
-
#initialize(*args) ⇒ Client
constructor
A new instance of Client.
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) = args. @conn = Faraday.new(:url => "http://townhog.com") do |builder| builder.adapter Faraday.default_adapter builder.adapter :logger if [:debug] == true builder.use Faraday::Response::ParseJson builder.use Faraday::Response::Mashify end end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/townhog.rb', line 8 def api_key @api_key end |
#conn ⇒ Object (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) = args. 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) = args. 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) = args. .merge!(:city_id => "all") if [:city_id].nil? response = conn.get("/api/all-deals/#{[:city_id]}/json/#{[:affiliate_id]}") ret = response.body.townhog_api.deal ret end |