Class: Habeel::JsonRPC::Client
- Inherits:
-
Object
- Object
- Habeel::JsonRPC::Client
- Defined in:
- lib/client.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(url, opts = {}) ⇒ Client
constructor
A new instance of Client.
- #method_missing(method, *args) ⇒ Object
Constructor Details
#initialize(url, opts = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 |
# File 'lib/client.rb', line 8 def initialize(url, opts = {}) @url = url @opts = opts || {} @opts[:content_type] = "application/json" end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/client.rb', line 14 def method_missing(method, *args) post_data = { :jsonrpc => '2.0', :method => method, :params => args, :id => self.class.make_id }.to_json resp = RestClient.post(@url, post_data, @opts) body = JSON.parse(resp.body) return body['result'] end |
Class Method Details
.make_id ⇒ Object
4 5 6 |
# File 'lib/client.rb', line 4 def self.make_id rand(10**12) end |