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.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #fetch_updates ⇒ Object
- #handle_update(update) ⇒ Object
-
#initialize(token, hash = {}) ⇒ Client
constructor
A new instance of Client.
- #listen(&block) ⇒ Object
- #run {|_self| ... } ⇒ Object
- #stop ⇒ Object
Constructor Details
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
6 7 8 |
# File 'lib/telegram/bot/client.rb', line 6 def api @api end |
#logger ⇒ Object
Returns the value of attribute logger.
7 8 9 |
# File 'lib/telegram/bot/client.rb', line 7 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/telegram/bot/client.rb', line 6 def @options end |
Class Method Details
.run(*args, &block) ⇒ Object
9 10 11 |
# File 'lib/telegram/bot/client.rb', line 9 def self.run(*args, &block) new(*args).run(&block) end |
Instance Method Details
#fetch_updates ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/telegram/bot/client.rb', line 33 def fetch_updates api.getUpdates().each do |update| yield handle_update(update) end rescue Faraday::TimeoutError, Faraday::ConnectionFailed retry if @running end |
#handle_update(update) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/telegram/bot/client.rb', line 41 def handle_update(update) @options[:offset] = update.update_id.next = update. () end |
#listen(&block) ⇒ Object
23 24 25 26 27 |
# File 'lib/telegram/bot/client.rb', line 23 def listen(&block) logger.info('Starting bot') @running = true fetch_updates(&block) while @running end |
#run {|_self| ... } ⇒ Object
19 20 21 |
# File 'lib/telegram/bot/client.rb', line 19 def run yield self end |
#stop ⇒ Object
29 30 31 |
# File 'lib/telegram/bot/client.rb', line 29 def stop @running = false end |