Class: Qtc::Mws::Client
- Inherits:
-
Object
- Object
- Qtc::Mws::Client
- Defined in:
- lib/qtc/mws/client.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ api_url: 'https://mws-eu-1.qtc.io/v1' }
Instance Attribute Summary collapse
-
#gateway_id ⇒ Object
Returns the value of attribute gateway_id.
-
#http_client ⇒ Object
Returns the value of attribute http_client.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(gateway_id, options = {}) ⇒ Client
constructor
Initialize.
-
#send_message(message, receivers = {sockets: ['*'], tags: nil}) ⇒ Object
Send message to websocket clients.
-
#websocket_client ⇒ Faye::WebSocket::Client
Get websocket client.
Constructor Details
#initialize(gateway_id, options = {}) ⇒ Client
Initialize
18 19 20 21 22 |
# File 'lib/qtc/mws/client.rb', line 18 def initialize(gateway_id, = {}) self.gateway_id = opts[:gateway_id] self. = DEFAULT_OPTIONS.merge() self.http_client = Qtc::Client.new(http_client_url) end |
Instance Attribute Details
#gateway_id ⇒ Object
Returns the value of attribute gateway_id.
11 12 13 |
# File 'lib/qtc/mws/client.rb', line 11 def gateway_id @gateway_id end |
#http_client ⇒ Object
Returns the value of attribute http_client.
11 12 13 |
# File 'lib/qtc/mws/client.rb', line 11 def http_client @http_client end |
#options ⇒ Object
Returns the value of attribute options.
11 12 13 |
# File 'lib/qtc/mws/client.rb', line 11 def @options end |
Instance Method Details
#send_message(message, receivers = {sockets: ['*'], tags: nil}) ⇒ Object
Send message to websocket clients
31 32 33 34 |
# File 'lib/qtc/mws/client.rb', line 31 def (, receivers = {sockets: ['*'], tags: nil}) data = {data: , receivers: receivers} self.http_client.post('/messages', data) end |
#websocket_client ⇒ Faye::WebSocket::Client
Get websocket client
40 41 42 43 |
# File 'lib/qtc/mws/client.rb', line 40 def websocket_client uri = self.http_client.get('/websocket_uri') Faye::WebSocket::Client.new(uri["uri"]) end |