Class: BotMob::Connection
- Inherits:
-
Object
- Object
- BotMob::Connection
- Defined in:
- lib/bot_mob/connection.rb
Overview
## BotMob::Connection
The Connection is the point of contact between the Bot and the specified network
Instance Attribute Summary collapse
-
#bot ⇒ Object
readonly
Returns the value of attribute bot.
Instance Method Summary collapse
- #client ⇒ Object
- #connect ⇒ Object
-
#initialize(_network, bot, token) ⇒ Connection
constructor
A new instance of Connection.
- #reconnect ⇒ Object
- #refresh ⇒ Object
Constructor Details
#initialize(_network, bot, token) ⇒ Connection
Returns a new instance of Connection.
9 10 11 12 13 |
# File 'lib/bot_mob/connection.rb', line 9 def initialize(_network, bot, token) @bot = bot @token = token token.nil? ? set_state(:inactive) : setup end |
Instance Attribute Details
#bot ⇒ Object (readonly)
Returns the value of attribute bot.
7 8 9 |
# File 'lib/bot_mob/connection.rb', line 7 def bot @bot end |
Instance Method Details
#client ⇒ Object
42 43 44 |
# File 'lib/bot_mob/connection.rb', line 42 def client @client ||= renew_client end |
#connect ⇒ Object
15 16 17 18 19 |
# File 'lib/bot_mob/connection.rb', line 15 def connect return unless active? set_state(:connecting) establish end |
#reconnect ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/bot_mob/connection.rb', line 21 def reconnect return unless active? set_state(:reconnecting) renew_client setup establish end |
#refresh ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bot_mob/connection.rb', line 29 def refresh return unless active? case true when waiting? connect when disconnected? reconnect else logger.info "State[#{bot.external_id}] - No Change" end end |