зеркало из
https://github.com/glebtv/telegram-bot.git
synced 2026-09-05 10:45:49 +03:00
Extract Botan-related code from Client to Botan::ClientHelpers
Этот коммит содержится в:
@@ -3,6 +3,7 @@ module Telegram
|
|||||||
class Botan
|
class Botan
|
||||||
TRACK_URI = 'https://api.botan.io/track'.freeze
|
TRACK_URI = 'https://api.botan.io/track'.freeze
|
||||||
|
|
||||||
|
autoload :ClientHelpers, 'telegram/bot/botan/client_helpers'
|
||||||
autoload :ControllerHelpers, 'telegram/bot/botan/controller_helpers'
|
autoload :ControllerHelpers, 'telegram/bot/botan/controller_helpers'
|
||||||
class Error < Bot::Error; end
|
class Error < Bot::Error; end
|
||||||
|
|
||||||
|
|||||||
15
lib/telegram/bot/botan/client_helpers.rb
Обычный файл
15
lib/telegram/bot/botan/client_helpers.rb
Обычный файл
@@ -0,0 +1,15 @@
|
|||||||
|
module Telegram
|
||||||
|
module Bot
|
||||||
|
class Botan
|
||||||
|
# Helpers for botan.io metrics.
|
||||||
|
module ClientHelpers
|
||||||
|
attr_reader :botan
|
||||||
|
|
||||||
|
def initialize(*, botan: nil, **)
|
||||||
|
super
|
||||||
|
@botan = Botan.wrap(botan) if botan
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -10,6 +10,7 @@ module Telegram
|
|||||||
|
|
||||||
autoload :TypedResponse, 'telegram/bot/client/typed_response'
|
autoload :TypedResponse, 'telegram/bot/client/typed_response'
|
||||||
extend Initializers
|
extend Initializers
|
||||||
|
prepend Botan::ClientHelpers
|
||||||
include DebugClient
|
include DebugClient
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
@@ -31,9 +32,9 @@ module Telegram
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :client, :token, :username, :base_uri, :botan
|
attr_reader :client, :token, :username, :base_uri
|
||||||
|
|
||||||
def initialize(token = nil, username = nil, botan: nil, **options)
|
def initialize(token = nil, username = nil, **options)
|
||||||
@client = HTTPClient.new
|
@client = HTTPClient.new
|
||||||
@token = token || options[:token]
|
@token = token || options[:token]
|
||||||
@username = username || options[:username]
|
@username = username || options[:username]
|
||||||
|
|||||||
25
spec/telegram/bot/botan/client_helpers_spec.rb
Обычный файл
25
spec/telegram/bot/botan/client_helpers_spec.rb
Обычный файл
@@ -0,0 +1,25 @@
|
|||||||
|
RSpec.describe Telegram::Bot::Client do
|
||||||
|
let(:instance) { described_class.new(*client_args) }
|
||||||
|
let(:token) { 'token' }
|
||||||
|
let(:botan_token) { double(:botan_token) }
|
||||||
|
let(:client_id) { 'client_id' }
|
||||||
|
let(:client_args) { [token] }
|
||||||
|
|
||||||
|
describe '#botan' do
|
||||||
|
subject { instance.botan }
|
||||||
|
it { should eq nil }
|
||||||
|
|
||||||
|
context 'when botan token is set' do
|
||||||
|
let(:client_args) { [token, id: client_id, async: Class.new, botan: botan_token] }
|
||||||
|
it { should be_instance_of Telegram::Bot::Botan }
|
||||||
|
its(:token) { should eq botan_token }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when botan is configured with hash' do
|
||||||
|
let(:client_args) { [token, id: client_id, async: Class.new, botan: botan_config] }
|
||||||
|
let(:botan_config) { {token: botan_token, async: Class.new} }
|
||||||
|
it { should be_instance_of Telegram::Bot::Botan }
|
||||||
|
its(:token) { should eq botan_token }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -41,15 +41,4 @@ RSpec.describe Telegram::Bot::Client do
|
|||||||
its(:base_uri) { should include args[0][:token] }
|
its(:base_uri) { should include args[0][:token] }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#botan' do
|
|
||||||
subject { instance.botan }
|
|
||||||
it { should eq nil }
|
|
||||||
|
|
||||||
context 'when botan token is set' do
|
|
||||||
let(:instance) { described_class.new token, botan: botan_token }
|
|
||||||
it { should be_instance_of Telegram::Bot::Botan }
|
|
||||||
its(:token) { should eq botan_token }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user