Class: Etheruby::ClientHolder
- Inherits:
-
Object
- Object
- Etheruby::ClientHolder
- Defined in:
- lib/etheruby/client.rb
Instance Method Summary collapse
- #http_post_request(post_body) ⇒ Object
-
#initialize(uri, sym) ⇒ ClientHolder
constructor
A new instance of ClientHolder.
- #method_missing(sym, *data) ⇒ Object
Constructor Details
#initialize(uri, sym) ⇒ ClientHolder
Returns a new instance of ClientHolder.
18 19 20 21 |
# File 'lib/etheruby/client.rb', line 18 def initialize(uri,sym) @uri = uri @sym = sym end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *data) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/etheruby/client.rb', line 22 def method_missing(sym, *data) body = { 'jsonrpc' => '2.0', 'id' => '1', 'method' => "#{@sym}_#{sym}", 'params' => data } text_response = http_post_request(::MultiJson.dump(body)) ::MultiJson.load(text_response) end |
Instance Method Details
#http_post_request(post_body) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/etheruby/client.rb', line 32 def http_post_request(post_body) http = Net::HTTP.new(@uri.host, @uri.port) request = Net::HTTP::Post.new(@uri.request_uri) request.content_type = 'application/json' request.body = post_body http.request(request).body end |