Class: BotMob::Slack::Connection
- Inherits:
-
Connection
- Object
- Connection
- BotMob::Slack::Connection
- Defined in:
- lib/bot_mob/slack/connection.rb
Instance Attribute Summary collapse
-
#bot ⇒ Object
readonly
Returns the value of attribute bot.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
- #client ⇒ Object
- #connect ⇒ Object
- #deliver(outbound_message, options = {}) ⇒ Object
-
#initialize(bot, options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #reconnect ⇒ Object
- #refresh ⇒ Object
- #welcome_message ⇒ Object
Constructor Details
#initialize(bot, options = {}) ⇒ Connection
Returns a new instance of Connection.
6 7 8 9 10 |
# File 'lib/bot_mob/slack/connection.rb', line 6 def initialize(bot, = {}) @bot = bot @token = ['token'] token.nil? ? set_state(:inactive) : setup end |
Instance Attribute Details
#bot ⇒ Object (readonly)
Returns the value of attribute bot.
4 5 6 |
# File 'lib/bot_mob/slack/connection.rb', line 4 def bot @bot end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
4 5 6 |
# File 'lib/bot_mob/slack/connection.rb', line 4 def token @token end |
Class Method Details
.setup(bot, options = {}) ⇒ Object
12 13 14 |
# File 'lib/bot_mob/slack/connection.rb', line 12 def self.setup(bot, = {}) new(bot, ) end |
Instance Method Details
#client ⇒ Object
53 54 55 |
# File 'lib/bot_mob/slack/connection.rb', line 53 def client @client ||= renew_client end |
#connect ⇒ Object
22 23 24 25 26 |
# File 'lib/bot_mob/slack/connection.rb', line 22 def connect return unless active? set_state(:connecting) establish end |
#deliver(outbound_message, options = {}) ⇒ Object
16 17 18 19 20 |
# File 'lib/bot_mob/slack/connection.rb', line 16 def deliver(, = {}) BotMob.logger.info(" Sending to Slack: \"#{.inspect}\"\n") BotMob.logger.info(" Text: \"#{.text.inspect}\"\n") client.web_client.chat_postMessage(.to_h) end |
#reconnect ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/bot_mob/slack/connection.rb', line 28 def reconnect return unless active? set_state(:reconnecting) renew_client setup establish end |
#refresh ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bot_mob/slack/connection.rb', line 36 def refresh return unless active? case true when waiting? connect when disconnected? reconnect else BotMob.logger.info "State[#{bot.class.to_s}##{bot.key}] - No Change" end end |
#welcome_message ⇒ Object
49 50 51 |
# File 'lib/bot_mob/slack/connection.rb', line 49 def "Successfully connected, '#{client.team.name}' team at https://#{client.team.domain}.slack.com." end |