Class: Ari::Client
Constant Summary collapse
- DEFAULTS =
{ :url => 'http://localhost:8088/ari' }
- HTTP_HEADERS =
{ 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'Accept-Charset' => 'utf-8', 'User-Agent' => "asterisk-ari-client/#{::Asterisk::Ari::Client::VERSION} ruby/#{RUBY_VERSION}" }
Instance Attribute Summary collapse
-
#ws ⇒ Object
readonly
Returns the value of attribute ws.
Instance Method Summary collapse
- #connect_websocket ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
Instance Attribute Details
#ws ⇒ Object (readonly)
Returns the value of attribute ws.
12 13 14 |
# File 'lib/ari/client.rb', line 12 def ws @ws end |
Instance Method Details
#connect_websocket ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ari/client.rb', line 44 def connect_websocket params = { api_key: @options[:api_key], app: @options[:app] } query_string = URI.encode_www_form params ws_url = "#{@uri}/events?#{query_string}" if @ws %w{ open message error close }.each { |e| @ws.remove_listener(e) } @ws.close end @ws = WebSocket::Client::Simple.connect ws_url @ws.on :open, &method(:handle_websocket_open) @ws.on :message, &method(:handle_websocket_message) @ws.on :error, &method(:handle_websocket_error) @ws.on :close, &method(:handle_websocket_close) end |