Class: Telegram::Bot::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram/bot/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(handler) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
# File 'lib/telegram/bot/client.rb', line 7

def initialize(handler)
  @handler = handler.new
  @handler.api = Telegram::Bot::Api.new
  @handler.botan = Telegram::Bot::Botan.new
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



5
6
7
# File 'lib/telegram/bot/client.rb', line 5

def command
  @command
end

#messageObject (readonly)

Returns the value of attribute message.



5
6
7
# File 'lib/telegram/bot/client.rb', line 5

def message
  @message
end

#updateObject (readonly)

Returns the value of attribute update.



5
6
7
# File 'lib/telegram/bot/client.rb', line 5

def update
  @update
end

Instance Method Details

#handle(params) ⇒ Object



13
14
15
16
# File 'lib/telegram/bot/client.rb', line 13

def handle(params)
  parse_request(params)
  invoke
end

#invokeObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/telegram/bot/client.rb', line 18

def invoke
  @handler.update = @update
  @handler.message = @message
  @handler.command = @command

  if !@command.nil? && @handler.respond_to?("cmd_#{@command}")
    @handler.public_send("cmd_#{@command}")
  else
    @handler.public_send(:cmd_fallback) if @handler.respond_to?(:cmd_fallback)
  end
end