Class: JsonRpcClient
- Inherits:
-
Object
- Object
- JsonRpcClient
- Includes:
- JsonRpcConstants, JsonRpcErrors
- Defined in:
- lib/jsonrpc2.0/Client.rb
Constant Summary
Constants included from JsonRpcErrors
JsonRpcErrors::ApplicationErrors, JsonRpcErrors::ImplementationErrors
Constants included from JsonRpcConstants
Instance Method Summary collapse
- #fire_notification(inMethod, *inParams) ⇒ Object
- #fire_request(inMethod, *inParams) ⇒ Object
- #method_missing(inMethod, *inParams) ⇒ Object
Methods included from JsonRpcErrors
add_application_errors, create_error_classes, error_from_hash
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(inMethod, *inParams) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/jsonrpc2.0/Client.rb', line 9 def method_missing(inMethod, *inParams) if (inMethod.to_s[(0..1)] == 'r_') fire_request(inMethod.to_s[(2..-1)].to_sym, *inParams) else super(inMethod, *inParams) end end |
Instance Method Details
#fire_notification(inMethod, *inParams) ⇒ Object
33 34 35 36 |
# File 'lib/jsonrpc2.0/Client.rb', line 33 def fire_notification(inMethod, *inParams) send_notification (inMethod, *inParams).to_json nil end |
#fire_request(inMethod, *inParams) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jsonrpc2.0/Client.rb', line 17 def fire_request(inMethod, *inParams) request = (inMethod, *inParams) request['id'] = (0...10).map{ ('a'..'z').to_a[rand(26)] }.join response = send_request request.to_json response = JSON.parse response begin raise JsonRpcErrors::error_from_hash(response['error'], true) if response.key?('error') rescue ApplicationError => e raise JsonRpcErrors::error_from_hash(e.data) end result = response['result'] end |