Class: JRPC::BaseClient
- Inherits:
-
Object
- Object
- JRPC::BaseClient
- Extended by:
- Forwardable
- Defined in:
- lib/jrpc/base_client.rb
Direct Known Subclasses
Constant Summary collapse
- ID_CHARACTERS =
(('a'..'z').to_a + ('0'..'9').to_a + ('A'..'Z').to_a).freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(uri, options) ⇒ BaseClient
constructor
A new instance of BaseClient.
- #invoke_notification(method, *params) ⇒ Object
- #invoke_request(method, *params) ⇒ Object
- #method_missing(method, *params) ⇒ Object
Constructor Details
#initialize(uri, options) ⇒ BaseClient
Returns a new instance of BaseClient.
11 12 13 14 |
# File 'lib/jrpc/base_client.rb', line 11 def initialize(uri, ) @uri = uri @options = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *params) ⇒ Object
16 17 18 |
# File 'lib/jrpc/base_client.rb', line 16 def method_missing(method, *params) invoke_request(method, *params) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/jrpc/base_client.rb', line 7 def @options end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
7 8 9 |
# File 'lib/jrpc/base_client.rb', line 7 def uri @uri end |
Instance Method Details
#invoke_notification(method, *params) ⇒ Object
34 35 36 37 |
# File 'lib/jrpc/base_client.rb', line 34 def invoke_notification(method, *params) send_notification (method, params).to_json nil end |
#invoke_request(method, *params) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/jrpc/base_client.rb', line 20 def invoke_request(method, *params) request = (method, params) id = generate_id request['id'] = id response = send_command request.to_json response = JSON.parse response validate_response(response, id) parse_error(response['error']) if response.has_key?('error') response['result'] end |