Class: BotMob::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/bot_mob/application.rb

Overview

## BotMob::Application

This is the base class for BotMob.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bot_class) ⇒ Application

Returns a new instance of Application.



8
9
10
11
# File 'lib/bot_mob/application.rb', line 8

def initialize(bot_class)
  @bot_class = bot_class
  @bots = {}
end

Instance Attribute Details

#bot_classObject (readonly)

Returns the value of attribute bot_class.



6
7
8
# File 'lib/bot_mob/application.rb', line 6

def bot_class
  @bot_class
end

#botsObject (readonly)

Returns the value of attribute bots.



6
7
8
# File 'lib/bot_mob/application.rb', line 6

def bots
  @bots
end

Instance Method Details

#connect(auth) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/bot_mob/application.rb', line 25

def connect(auth)
  external_id, token = auth['external_id'], auth['token']
  BotMob.logger.info "Register bot: #{external_id}"
  bot = bot_class.new(external_id, token)
  @bots[external_id] ||= bot
  @bots[external_id].refresh
end

#registry_available?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/bot_mob/application.rb', line 33

def registry_available?
  @registry_available.nil? || @registry_available
end

#start!Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bot_mob/application.rb', line 13

def start!
  BotMob.logger.info("=> BotMob #{BotMob::VERSION} application starting")
  load_registry
  wire.connect { |auth| connect(auth) }

  loop do
    sleep(10)
    # Avoid polling at all for the time being
    # load_registry if registry_available? && !wire.available?
  end
end