Class: Telegram::Bot::Client
- Inherits:
-
Object
- Object
- Telegram::Bot::Client
- Defined in:
- lib/telegram/bot/client.rb
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(token, timeout = 20) ⇒ Client
constructor
A new instance of Client.
- #listen ⇒ Object
- #run {|_self| ... } ⇒ Object
Constructor Details
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
4 5 6 |
# File 'lib/telegram/bot/client.rb', line 4 def api @api end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
4 5 6 |
# File 'lib/telegram/bot/client.rb', line 4 def offset @offset end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
4 5 6 |
# File 'lib/telegram/bot/client.rb', line 4 def timeout @timeout end |
Class Method Details
.run(*args, &block) ⇒ Object
6 7 8 |
# File 'lib/telegram/bot/client.rb', line 6 def self.run(*args, &block) new(*args).run(&block) end |
Instance Method Details
#listen ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/telegram/bot/client.rb', line 20 def listen loop do response = api.getUpdates(offset: offset, timeout: timeout) next unless response['ok'] response['result'].each do |data| update = Types::Update.new(data) @offset = update.update_id.next yield update. end end end |
#run {|_self| ... } ⇒ Object
16 17 18 |
# File 'lib/telegram/bot/client.rb', line 16 def run yield self end |