lib/telegram/bot/client.rb in telegram-bot-ruby-0.7.0 vs lib/telegram/bot/client.rb in telegram-bot-ruby-0.7.1
- old
+ new
@@ -1,21 +1,19 @@
module Telegram
module Bot
class Client
- attr_reader :api, :offset, :timeout
+ attr_reader :api, :options
attr_accessor :logger
def self.run(*args, &block)
new(*args).run(&block)
end
def initialize(token, h = {})
- options = default_options.merge(h)
+ @options = default_options.merge(h)
@api = Api.new(token)
- @offset = options[:offset]
- @timeout = options[:timeout]
- @logger = options[:logger]
+ @logger = options.delete(:logger)
end
def run
yield self
end
@@ -27,15 +25,15 @@
fetch_updates(&block) while running
exit
end
def fetch_updates
- response = api.getUpdates(offset: offset, timeout: timeout)
+ response = api.getUpdates(options)
return unless response['ok']
response['result'].each do |data|
update = Types::Update.new(data)
- @offset = update.update_id.next
+ @options[:offset] = update.update_id.next
message = extract_message(update)
log_incoming_message(message)
yield message
end
rescue Faraday::Error::TimeoutError