Class: Alpaca::News::Api::Realtime::Client
- Defined in:
- lib/alpaca/news/api/realtime/client.rb
Overview
Realtime client class
Instance Method Summary collapse
-
#close {|Faye::WebSocket::API::Event| ... } ⇒ Object
(also: #on_close)
Websocket close callback.
-
#error {|Faye::WebSocket::API::ErrorEvent| ... } ⇒ Object
(also: #on_error)
Websocket message callback.
-
#initialize(host = nil, options = {}) ⇒ Client
constructor
Create new client object.
-
#message {|Hash| ... } ⇒ Object
(also: #on_message)
Websocket message callback.
-
#send(payload = {}) ⇒ Object
Send payload to the websocket server.
Methods inherited from Base
Constructor Details
#initialize(host = nil, options = {}) ⇒ Client
Create new client object
15 16 17 |
# File 'lib/alpaca/news/api/realtime/client.rb', line 15 def initialize(host = nil, = {}) @websocket = Faye::WebSocket::Client.new("wss://#{host}/v1beta1/news", [], ) end |
Instance Method Details
#close {|Faye::WebSocket::API::Event| ... } ⇒ Object Also known as: on_close
Websocket close callback
49 50 51 |
# File 'lib/alpaca/news/api/realtime/client.rb', line 49 def close(&block) @websocket.on(:close, &block) end |
#error {|Faye::WebSocket::API::ErrorEvent| ... } ⇒ Object Also known as: on_error
Websocket message callback
40 41 42 |
# File 'lib/alpaca/news/api/realtime/client.rb', line 40 def error(&block) @websocket.on(:error, &block) end |
#message {|Hash| ... } ⇒ Object Also known as: on_message
Websocket message callback
29 30 31 32 33 |
# File 'lib/alpaca/news/api/realtime/client.rb', line 29 def (&block) @websocket.on(:message) do |event| block.call(event.data) end end |
#send(payload = {}) ⇒ Object
Send payload to the websocket server
21 22 23 |
# File 'lib/alpaca/news/api/realtime/client.rb', line 21 def send(payload = {}) @websocket.send(payload.to_json) end |