Class: BotMob::Connection

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#botObject (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

#clientObject



42
43
44
# File 'lib/bot_mob/connection.rb', line 42

def client
  @client ||= renew_client
end

#connectObject



15
16
17
18
19
# File 'lib/bot_mob/connection.rb', line 15

def connect
  return unless active?
  set_state(:connecting)
  establish
end

#reconnectObject



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

#refreshObject



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