From 8936a7a96c85a57828936893095a7b6d8d5a69ab Mon Sep 17 00:00:00 2001 From: Max Melentiev Date: Fri, 22 Jun 2018 07:44:26 +0300 Subject: [PATCH] Remove botan.io support https://github.com/botanio/sdk#this-service-will-be-shut-down-on-25th-may-2018 --- CHANGELOG.md | 3 ++ lib/telegram/bot.rb | 1 - lib/telegram/bot/async.rb | 9 +--- lib/telegram/bot/botan.rb | 53 ------------------ lib/telegram/bot/botan/client_helpers.rb | 15 ------ lib/telegram/bot/botan/controller_helpers.rb | 33 ------------ lib/telegram/bot/client.rb | 1 - lib/telegram/bot/config_methods.rb | 6 --- .../telegram/bot/botan/client_helpers_spec.rb | 33 ------------ .../bot/botan/controller_helpers_spec.rb | 54 ------------------- spec/telegram/bot/botan_spec.rb | 27 ---------- spec/telegram/bot/client_spec.rb | 1 - spec/telegram/bot/config_methods_spec.rb | 15 ------ 13 files changed, 5 insertions(+), 246 deletions(-) delete mode 100644 lib/telegram/bot/botan.rb delete mode 100644 lib/telegram/bot/botan/client_helpers.rb delete mode 100644 lib/telegram/bot/botan/controller_helpers.rb delete mode 100644 spec/telegram/bot/botan/client_helpers_spec.rb delete mode 100644 spec/telegram/bot/botan/controller_helpers_spec.rb delete mode 100644 spec/telegram/bot/botan_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 84f4838..adf4b7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Unreleased +- Remove botan.io support. It's already shut down, so it should not be a braking change. + https://github.com/botanio/sdk#this-service-will-be-shut-down-on-25th-may-2018 + # 0.14.0 - Make integration & controller specs consistent. diff --git a/lib/telegram/bot.rb b/lib/telegram/bot.rb index ce860e3..c3792e0 100644 --- a/lib/telegram/bot.rb +++ b/lib/telegram/bot.rb @@ -22,7 +22,6 @@ module Telegram end autoload :Async, 'telegram/bot/async' - autoload :Botan, 'telegram/bot/botan' autoload :Client, 'telegram/bot/client' autoload :ClientStub, 'telegram/bot/client_stub' autoload :DebugClient, 'telegram/bot/debug_client' diff --git a/lib/telegram/bot/async.rb b/lib/telegram/bot/async.rb index 10bddbc..82188ed 100644 --- a/lib/telegram/bot/async.rb +++ b/lib/telegram/bot/async.rb @@ -1,20 +1,15 @@ module Telegram module Bot - # Telegram & Botan clients can perform requests in async way with + # Telegram clients can perform requests in async way with # any job adapter (ActiveJob by default). Using Rails you don't need any # additional configuration. However you may want to enable async requests - # by default with `async: true` in `secrets.yml`. Botan client doesn't inherit - # async setting from client and must be configured separately. + # by default with `async: true` in `secrets.yml`. # # telegram: # bots: # chat_async: # token: secret # async: true # enable async mode for client - # botan: botan_token # in this way botan will not be async - # botan: # in this way - it's in async mode - # token: botan_token - # async: true # # Without Rails To start using async requests # initialize client with `id` kwarg and make sure the client is diff --git a/lib/telegram/bot/botan.rb b/lib/telegram/bot/botan.rb deleted file mode 100644 index b135e6c..0000000 --- a/lib/telegram/bot/botan.rb +++ /dev/null @@ -1,53 +0,0 @@ -module Telegram - module Bot - class Botan - TRACK_URI = 'https://api.botan.io/track'.freeze - - autoload :ClientHelpers, 'telegram/bot/botan/client_helpers' - autoload :ControllerHelpers, 'telegram/bot/botan/controller_helpers' - class Error < Bot::Error; end - - extend Initializers - prepend Async - include DebugClient - - class << self - def by_id(id) - Telegram.botans[id] - end - - def prepare_async_args(method, uri, query = {}, body = nil) - [method.to_s, uri.to_s, Async.prepare_hash(query), body] - end - end - - attr_reader :client, :token - - def initialize(token = nil, **options) - @client = HTTPClient.new - @token = token || options[:token] - end - - def track(event, uid, payload = {}) - request(:post, TRACK_URI, {name: event, uid: uid}, payload.to_json) - end - - def request(method, uri, query = {}, body = nil) - res = http_request(method, uri, query.merge(token: token), body) - status = res.status - return JSON.parse(res.body) if status < 300 - result = JSON.parse(res.body) rescue nil # rubocop:disable RescueModifier - err_msg = "#{res.reason}: #{result && result['info'] || '-'}" - raise Error, err_msg - end - - def http_request(method, uri, query, body) - client.request(method, uri, query, body) - end - - def inspect - "#<#{self.class.name}##{object_id}(#{@id})>" - end - end - end -end diff --git a/lib/telegram/bot/botan/client_helpers.rb b/lib/telegram/bot/botan/client_helpers.rb deleted file mode 100644 index 1f889a9..0000000 --- a/lib/telegram/bot/botan/client_helpers.rb +++ /dev/null @@ -1,15 +0,0 @@ -module Telegram - module Bot - class Botan - # Helpers for botan.io metrics. - module ClientHelpers - attr_reader :botan - - def initialize(*, botan: nil, **options) - super - @botan = Botan.wrap(botan, id: id) if botan - end - end - end - end -end diff --git a/lib/telegram/bot/botan/controller_helpers.rb b/lib/telegram/bot/botan/controller_helpers.rb deleted file mode 100644 index 02816c5..0000000 --- a/lib/telegram/bot/botan/controller_helpers.rb +++ /dev/null @@ -1,33 +0,0 @@ -module Telegram - module Bot - class Botan - # Helpers for botan.io metrics. - module ControllerHelpers - class MissingFrom < Error; end - - protected - - def botan - @botan ||= bot.try!(:botan) - end - - # Track custom event for user taken from `from` field: - # - # botan_track :my_event, {data: :val} - # - def botan_track(event, data = {}) - raise MissingFrom, 'Can not track without user' unless from - botan.try! { |x| x.track(event, from['id'], data) } - end - - # Track current action and payload for current user. Best used with `before_action`: - # - # before_action :botan_track_action - # - def botan_track_action - botan_track(action_name, payload) - end - end - end - end -end diff --git a/lib/telegram/bot/client.rb b/lib/telegram/bot/client.rb index 953d53d..9ff861e 100644 --- a/lib/telegram/bot/client.rb +++ b/lib/telegram/bot/client.rb @@ -9,7 +9,6 @@ module Telegram autoload :TypedResponse, 'telegram/bot/client/typed_response' extend Initializers prepend Async - prepend Botan::ClientHelpers include DebugClient require 'telegram/bot/client/api_helper' diff --git a/lib/telegram/bot/config_methods.rb b/lib/telegram/bot/config_methods.rb index 3e31688..8b4c275 100644 --- a/lib/telegram/bot/config_methods.rb +++ b/lib/telegram/bot/config_methods.rb @@ -40,11 +40,6 @@ module Telegram end end - # Hash of botan clients made from #bots. - def botans - @botans ||= bots.map { |k, v| [k, v.botan] }.to_h - end - # Returns config for .bots method. By default uses `telegram['bots']` section # from `secrets.yml` merging `telegram['bot']` at `:default` key. # @@ -69,7 +64,6 @@ module Telegram @bots = nil @bot = nil @bots_config = nil - @botans = nil end end end diff --git a/spec/telegram/bot/botan/client_helpers_spec.rb b/spec/telegram/bot/botan/client_helpers_spec.rb deleted file mode 100644 index 69945f4..0000000 --- a/spec/telegram/bot/botan/client_helpers_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -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 } - its(:id) { should eq client_id } - - it 'doesnt inherit async from client' do - expect(instance.async).to be - expect(subject.async).to_not be - end - 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 } - its(:id) { should eq client_id } - its(:async) { should eq botan_config[:async] } - end - end -end diff --git a/spec/telegram/bot/botan/controller_helpers_spec.rb b/spec/telegram/bot/botan/controller_helpers_spec.rb deleted file mode 100644 index 43ac742..0000000 --- a/spec/telegram/bot/botan/controller_helpers_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -RSpec.describe Telegram::Bot::Botan::ControllerHelpers do - include_context 'telegram/bot/updates_controller' - let(:controller_class) do - described_class = self.described_class - Class.new(Telegram::Bot::UpdatesController) do - include described_class - end - end - let(:botan) { double(:botan) } - let(:result) { double(:result) } - let(:payload) { {from: {id: user_id}} } - let(:payload_type) { :message } - let(:user_id) { double(:user_id) } - before { allow(bot).to receive(:botan) { botan } } - - shared_examples 'basic tracking' do - context 'when botan is not configured' do - let(:botan) {} - it { should eq nil } - end - - context 'when `from` is empty' do - let(:payload) { {text: 'test'} } - it { expect { subject }.to raise_error described_class::MissingFrom } - end - end - - describe '#botan_track' do - subject { controller.send(:botan_track, event, data) } - let(:event) { double(:event) } - let(:data) { double(:data) } - - it 'calls botan#track' do - expect(botan).to receive(:track).with(event, user_id, data) { result } - should eq result - end - - include_examples 'basic tracking' - end - - describe '#botan_track_action' do - subject { controller.send(:botan_track_action) } - let(:action_name) { double(:action_name) } - - it 'calls botan#track with current action and payload' do - expect(controller).to receive(:action_name) { action_name } - expect(botan).to receive(:track). - with(action_name, user_id, deep_stringify(payload)) { result } - should eq result - end - - include_examples 'basic tracking' - end -end diff --git a/spec/telegram/bot/botan_spec.rb b/spec/telegram/bot/botan_spec.rb deleted file mode 100644 index 4343240..0000000 --- a/spec/telegram/bot/botan_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -RSpec.describe Telegram::Bot::Botan do - let(:instance) { described_class.new 'token' } - let(:token) { 'token' } - - include_examples 'initializers', :botans - it_behaves_like 'async', request_args: -> { [double(:method), double(:url)] } - - describe '.new' do - subject { described_class.new(*args) } - - context 'when usual args are given' do - let(:args) { ['secret'] } - its(:token) { should eq args[0] } - end - - context 'when options are given' do - let(:args) { [token: 'secret'] } - its(:token) { should eq args[0][:token] } - end - end - - describe '.prepare_async_args' do - subject { described_class.prepare_async_args(*input) } - let(:input) { [:post, :uri, {a: 1, b: :sym, 'd' => 'str'}, 'body'] } - it { should eq ['post', 'uri', {a: 1, b: 'sym', 'd' => 'str'}, 'body'] } - end -end diff --git a/spec/telegram/bot/client_spec.rb b/spec/telegram/bot/client_spec.rb index b62c871..0a82bd3 100644 --- a/spec/telegram/bot/client_spec.rb +++ b/spec/telegram/bot/client_spec.rb @@ -1,7 +1,6 @@ RSpec.describe Telegram::Bot::Client do let(:instance) { described_class.new 'token' } let(:token) { 'token' } - let(:botan_token) { double(:botan_token) } include_examples 'initializers' it_behaves_like 'async', request_args: -> { [double(:action), {body: :content}] } diff --git a/spec/telegram/bot/config_methods_spec.rb b/spec/telegram/bot/config_methods_spec.rb index bdcfa9f..3f2dbec 100644 --- a/spec/telegram/bot/config_methods_spec.rb +++ b/spec/telegram/bot/config_methods_spec.rb @@ -11,12 +11,10 @@ RSpec.describe Telegram::Bot::ConfigMethods do chat: { token: 'chat_token', username: 'Chat', - botan: 'chat_botan_token', }, other_chat: { 'token' => 'other_chat_token', 'username' => 'OtherChat', - 'botan' => 'other_chat_botan_token', }, } end @@ -43,7 +41,6 @@ RSpec.describe Telegram::Bot::ConfigMethods do its(:id) { should eq :chat } its(:token) { should eq config[:chat][:token] } its(:username) { should eq config[:chat][:username] } - its('botan.token') { should eq config[:chat][:botan] } end context 'configured by hash with stringified keys' do @@ -51,18 +48,6 @@ RSpec.describe Telegram::Bot::ConfigMethods do its(:id) { should eq :other_chat } its(:token) { should eq config[:other_chat]['token'] } its(:username) { should eq config[:other_chat]['username'] } - its('botan.token') { should eq config[:other_chat]['botan'] } - end - end - - describe '#botans' do - subject { registry.botans } - it do - should eq( - default: nil, - chat: registry.bots[:chat].botan, - other_chat: registry.bots[:other_chat].botan, - ) end end