Class: Opensips::MI::Transport::Abstract
- Inherits:
-
Object
- Object
- Opensips::MI::Transport::Abstract
- Defined in:
- lib/opensips/mi/transport/abstract.rb
Overview
abstruct class for transport protocols
Instance Method Summary collapse
-
#adapter_request(cmd, *args) ⇒ Object
request adapter method by default if does jsonrpc v2 as string xmlrpc overload this message.
-
#adapter_response(body) ⇒ Object
response adapter by default parses jsonrpc response to an object.
-
#send(_command) ⇒ Object
send a command to connection and return response.
Instance Method Details
#adapter_request(cmd, *args) ⇒ Object
request adapter method by default if does jsonrpc v2 as string xmlrpc overload this message
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/opensips/mi/transport/abstract.rb', line 18 def adapter_request(cmd, *args) rpc = { jsonrpc: "2.0", id: rand(1 << 16), method: cmd } unless args.empty? params = args.flatten rpc[:params] = params[0].is_a?(Hash) ? params[0] : params end JSON.generate(rpc) end |
#adapter_response(body) ⇒ Object
response adapter by default parses jsonrpc response to an object. xmlrp overloads this method
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/opensips/mi/transport/abstract.rb', line 35 def adapter_response(body) resp = JSON.parse(body) if resp["result"] { result: resp["result"] } elsif resp["error"] { error: resp["error"] } else { error: { "message" => "invalid response: #{body}" } } end rescue JSON::ParserError => e { error: { "message" => %(JSON::ParserError: #{e}) } } end |
#send(_command) ⇒ Object
send a command to connection and return response
11 12 13 |
# File 'lib/opensips/mi/transport/abstract.rb', line 11 def send(_command) raise NotImplementedError end |