Class: Opensips::MI::Transport::Xmlrpc
- Defined in:
- lib/opensips/mi/transport/xmlrpc.rb
Overview
XML-RPC protocol for MI
Instance Method Summary collapse
-
#adapter_request(*args) ⇒ Object
overload request adapter for xmlrpc.
-
#adapter_response(resp) ⇒ Object
overload resonse adapter for xmlrpc.
-
#initialize(args) ⇒ Xmlrpc
constructor
A new instance of Xmlrpc.
- #send(*cmd) ⇒ Object
Constructor Details
#initialize(args) ⇒ Xmlrpc
Returns a new instance of Xmlrpc.
11 12 13 14 15 16 17 18 |
# File 'lib/opensips/mi/transport/xmlrpc.rb', line 11 def initialize(args) super() raise_invalid_params unless args.is_a?(Hash) url, @timeout = args.values_at(:url, :timeout) raise_invalid_params if url.nil? seturi(url) @client = XMLRPC::Client.new2(@uri.to_s, nil, @timeout) end |
Instance Method Details
#adapter_request(*args) ⇒ Object
overload request adapter for xmlrpc
38 39 40 41 42 43 44 45 46 |
# File 'lib/opensips/mi/transport/xmlrpc.rb', line 38 def adapter_request(*args) args.flatten => [cmd, *rest] return [cmd] if rest.empty? rest = rest.flatten return [cmd, rest.first.map { |_, v| v }].flatten if rest.first.is_a?(Hash) [cmd, rest].flatten end |
#adapter_response(resp) ⇒ Object
overload resonse adapter for xmlrpc
29 30 31 32 33 34 35 |
# File 'lib/opensips/mi/transport/xmlrpc.rb', line 29 def adapter_response(resp) if resp[:error] resp else { result: resp } end end |
#send(*cmd) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/opensips/mi/transport/xmlrpc.rb', line 20 def send(*cmd) @client.call(*cmd) rescue XMLRPC::FaultException => e { error: { "message" => e. } } rescue StandardError => e raise Opensips::MI::ErrorHTTPReq, e end |