Class: Diligence::Application

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

Instance Method Summary collapse

Constructor Details

#initialize(root_path) ⇒ Application



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/diligence/application.rb', line 3

def initialize(root_path)
  @root_path = root_path

  @loader = Zeitwerk::Loader.new
  @loader.push_dir(File.join(@root_path, 'app'))
  @loader.enable_reloading
  @loader.setup

  token = ENV['TG_TOKEN']
  raise 'TG_TOKEN environment variable is not set' unless token

  @api_client = ApiClient.new(token)
  @offset = nil
  @router = load_routes
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/diligence/application.rb', line 19

def run
  loop do
    updates = @api_client.get_updates(offset: @offset)

    updates.each do |update|
      if update.include?('message')
        message_update = Types::Updates::MessageUpdate.new(update)
        dispatch_message(message_update)
      end

      @offset = update['update_id'] + 1
    end
  end
end