Class: Bitclient::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.



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

def initialize(opts = {})
  @url = opts[:url] || "http://localhost:8332"
  @auth = {:username => opts[:username], :password => opts[:password]}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bitclient.rb', line 13

def method_missing(method, *args)
  options = {
    :body => {
      :method => method.to_s.gsub(/\_/, ""),
      :params => args
    }.to_json,
    :basic_auth => @auth,
    :format => :json
  }
  res = HTTParty.post(@url, options).parsed_response
  if res["error"]
    raise Exception, res["error"]
  else
    res["result"]
  end
end