Class: Yipit::Client
- Inherits:
-
Object
- Object
- Yipit::Client
- Defined in:
- lib/yipit.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
- #businesses(*args) ⇒ Object
- #deals(*args) ⇒ Object
- #divisions(*args) ⇒ Object
-
#initialize(*args) ⇒ Client
constructor
Initialize the client.
- #method_missing(sym, *args, &block) ⇒ Object
- #sources(*args) ⇒ Object
-
#tags(options = {}) ⇒ Array
This method returns a list of all tags.
Constructor Details
#initialize(*args) ⇒ Client
Initialize the client. TODO: Document.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/yipit.rb', line 12 def initialize(*args) = args. @api_key = args[0] @conn = Faraday.new(:url => "http://api.yipit.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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/yipit.rb', line 82 def method_missing(sym, *args, &block) = args..merge(:key => api_key, :limit => 5000) response = conn.get("/v1/#{sym.to_s}/#{args[0]}") { |req| req.params = } puts response ret = response.body['response']["#{sym.to_s}"] mashes = ret.map{|h| Hashie::Mash.new(h)} args[0].nil? ? mashes : mashes.first if mashes end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/yipit.rb', line 8 def api_key @api_key end |
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
8 9 10 |
# File 'lib/yipit.rb', line 8 def conn @conn end |
Instance Method Details
#businesses(*args) ⇒ Object
78 79 80 |
# File 'lib/yipit.rb', line 78 def businesses(*args) super end |
#deals(options = {}) ⇒ Array #deals(deal_id) ⇒ Hashie::Mash
51 52 53 |
# File 'lib/yipit.rb', line 51 def deals(*args) super end |
#divisions(*args) ⇒ Object
75 76 77 |
# File 'lib/yipit.rb', line 75 def divisions(*args) super end |
#sources(options = {}) ⇒ Object #sources(source_id) ⇒ Hashie::Mash
64 65 66 |
# File 'lib/yipit.rb', line 64 def sources(*args) super end |