Class: OpenC3::JsonApiObject
Overview
Used to forward all method calls to the remote server object. Before using this class ensure the remote service has been started in the server class:
json = JsonDrb.new
json.start_service('127.0.0.1', 7777, self)
Now the JsonApiObject can be used to call server methods directly:
server = JsonApiObject('http://openc3-cosmos-cmd-tlm-api:2901', 1.0)
server.cmd(*args)
Direct Known Subclasses
Constant Summary collapse
- USER_AGENT =
'OpenC3 / v5 (ruby/openc3/lib/io/json_api_object)'.freeze
Instance Attribute Summary collapse
-
#request_data ⇒ Object
readonly
Returns the value of attribute request_data.
-
#response_data ⇒ Object
readonly
Returns the value of attribute response_data.
Instance Method Summary collapse
-
#disconnect ⇒ Object
Disconnects from http server.
-
#generate_auth ⇒ Object
generate the auth object.
-
#initialize(url: ENV['OPENC3_API_URL'], timeout: 1.0, authentication: nil) ⇒ JsonApiObject
constructor
A new instance of JsonApiObject.
-
#request(*method_params, **keyword_params) ⇒ Object
Forwards all method calls to the remote service.
-
#shutdown ⇒ Object
Permanently disconnects from the http server.
Constructor Details
#initialize(url: ENV['OPENC3_API_URL'], timeout: 1.0, authentication: nil) ⇒ JsonApiObject
Returns a new instance of JsonApiObject.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/openc3/io/json_api_object.rb', line 60 def initialize(url: ENV['OPENC3_API_URL'], timeout: 1.0, authentication: nil) @http = nil @mutex = Mutex.new @request_data = "" @response_data = "" @url = url @log = [nil, nil, nil] @authentication = authentication.nil? ? generate_auth() : authentication @timeout = timeout @shutdown = false end |
Instance Attribute Details
#request_data ⇒ Object (readonly)
Returns the value of attribute request_data.
52 53 54 |
# File 'lib/openc3/io/json_api_object.rb', line 52 def request_data @request_data end |
#response_data ⇒ Object (readonly)
Returns the value of attribute response_data.
53 54 55 |
# File 'lib/openc3/io/json_api_object.rb', line 53 def response_data @response_data end |
Instance Method Details
#disconnect ⇒ Object
Disconnects from http server
103 104 105 106 |
# File 'lib/openc3/io/json_api_object.rb', line 103 def disconnect @http.close if @http @http = nil end |
#generate_auth ⇒ Object
generate the auth object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/openc3/io/json_api_object.rb', line 73 def generate_auth if ENV['OPENC3_API_TOKEN'].nil? and ENV['OPENC3_API_USER'].nil? if ENV['OPENC3_API_PASSWORD'] return OpenC3Authentication.new() else return nil end else return OpenC3KeycloakAuthentication.new(ENV['OPENC3_KEYCLOAK_URL']) end end |
#request(*method_params, **keyword_params) ⇒ Object
Forwards all method calls to the remote service.
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/openc3/io/json_api_object.rb', line 90 def request(*method_params, **keyword_params) raise JsonApiError, "Shutdown" if @shutdown method = method_params[0] endpoint = method_params[1] @mutex.synchronize do kwargs = _generate_kwargs(keyword_params) @log = [nil, nil, nil] connect() if !@http return _send_request(method: method, endpoint: endpoint, kwargs: kwargs) end end |
#shutdown ⇒ Object
Permanently disconnects from the http server
109 110 111 112 |
# File 'lib/openc3/io/json_api_object.rb', line 109 def shutdown @shutdown = true disconnect() end |