Class: Tippr::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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)
  options = args.extract_options!
  @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)
  options = args.extract_options!.merge(:apikey => api_key, :format => "json")
  response = conn.get("/api/v2/#{sym.to_s}/#{args[0]}") { |req| req.params = options  }
  response.body
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#connObject (readonly)

Returns the value of attribute conn.



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

def conn
  @conn
end