Class: Tippr::Client
- Inherits:
-
Object
- Object
- Tippr::Client
- Defined in:
- lib/tippr.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
-
#initialize(*args) ⇒ Client
constructor
Initialize the client.
- #method_missing(sym, *args, &block) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Client
Initialize the client. TODO: Document.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/tippr.rb', line 12 def initialize(*args) = args. @api_key = args[0] @conn = Faraday.new(:url => "http://tippr.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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
23 24 25 26 27 |
# File 'lib/tippr.rb', line 23 def method_missing(sym, *args, &block) = args..merge(:apikey => api_key, :format => "json") response = conn.get("/api/v2/#{sym.to_s}/#{args[0]}") { |req| req.params = } response.body end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/tippr.rb', line 8 def api_key @api_key end |
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
8 9 10 |
# File 'lib/tippr.rb', line 8 def conn @conn end |