Class: SardonyxRing::Services::SlackSocketClient
- Inherits:
-
Object
- Object
- SardonyxRing::Services::SlackSocketClient
- Defined in:
- lib/sardonyx_ring/services/slack_socket_client.rb
Constant Summary collapse
- SLACK_API_ORIGIN =
'https://slack.com'
Instance Method Summary collapse
- #connect! ⇒ Object
-
#initialize(options = {}) ⇒ SlackSocketClient
constructor
A new instance of SlackSocketClient.
- #on_message(&block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ SlackSocketClient
Returns a new instance of SlackSocketClient.
8 9 10 11 12 13 |
# File 'lib/sardonyx_ring/services/slack_socket_client.rb', line 8 def initialize( = {}) @app_client = SlackAppClient.new(token: [:token]) @logger = [:logger] @handler = nil @ws = nil end |
Instance Method Details
#connect! ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sardonyx_ring/services/slack_socket_client.rb', line 19 def connect! require 'faye/websocket' open_resp = @app_client.request('apps.connections.open') raise open_resp unless open_resp.ok url = "#{open_resp.url}#{debug? ? '&debug_reconnects=true' : ''}" @ws = Faye::WebSocket::Client.new(url) @ws.on(:open, &method(:on_ws_open)) @ws.on(:message, &method(:on_ws_message)) @ws.on(:close, &method(:on_ws_close)) end |
#on_message(&block) ⇒ Object
15 16 17 |
# File 'lib/sardonyx_ring/services/slack_socket_client.rb', line 15 def (&block) @handler = block end |