Class: Opensips::MI::Transport::HTTP

Inherits:
Abstract
  • Object
show all
Defined in:
lib/opensips/mi/transport/http.rb

Overview

HTTP transport to communicate with MI

Instance Method Summary collapse

Methods inherited from Abstract

#adapter_request, #adapter_response

Constructor Details

#initialize(args) ⇒ HTTP

Returns a new instance of HTTP.



11
12
13
14
15
16
17
18
19
# File 'lib/opensips/mi/transport/http.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)
  @timeout ||= 5
  connect
end

Instance Method Details

#send(cmd) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/opensips/mi/transport/http.rb', line 21

def send(cmd)
  resp = @client.post(@uri.path, cmd, { "Content-Type" => "application/json" })
  unless resp.code.eql? "200"
    raise Opensips::MI::ErrorHTTPReq,
          "invalid MI HTTP response: #{resp.message}"
  end
  resp.body
end