lib/telegram/bot/client.rb in telegram-bot-ruby-1.0.0 vs lib/telegram/bot/client.rb in telegram-bot-ruby-2.0.0

- old
+ new

@@ -20,21 +20,20 @@ yield self end def listen(&block) logger.info('Starting bot') - running = true - Signal.trap('INT') { running = false } - fetch_updates(&block) while running - exit + @running = true + fetch_updates(&block) while @running end - def fetch_updates - response = api.getUpdates(options) - return unless response['ok'] + def stop + @running = false + end - response['result'].each do |data| - yield handle_update(Types::Update.new(data)) + def fetch_updates + api.getUpdates(options).each do |update| + yield handle_update(update) end rescue Faraday::TimeoutError, Faraday::ConnectionFailed retry end