From c97f04a45fb5ffee325dd3b4b80ff183bb164912 Mon Sep 17 00:00:00 2001 From: Vladislav Yashin Date: Fri, 4 May 2018 14:30:58 +0300 Subject: [PATCH 1/2] Add proxy support --- bin/console | 17 +++++++++++++++++ lib/tdlib/client.rb | 6 +++++- tdlib-ruby.gemspec | 1 - 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100755 bin/console diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..6942a29 --- /dev/null +++ b/bin/console @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +require 'bundler/setup' +require 'tdlib-ruby' + +TD.configure do |config| + config.lib_path = File.join(File.expand_path("#{TD.root_path}/../"), 'td', 'build') + + config.client.api_id = ENV['TD_API_ID'] + config.client.api_hash = ENV['TD_API_HASH'] + config.client.use_test_dc = true +end + +TD::Api.set_log_verbosity_level(1) + +require 'irb' +IRB.start(__FILE__) diff --git a/lib/tdlib/client.rb b/lib/tdlib/client.rb index 545cdc8..d85024d 100644 --- a/lib/tdlib/client.rb +++ b/lib/tdlib/client.rb @@ -62,10 +62,12 @@ class TD::Client def initialize(td_client = TD::Api.client_create, update_manager = TD::UpdateManager.new(td_client), + proxy: { '@type' => 'proxyEmpty' }, **extra_config) @td_client = td_client @update_manager = update_manager @config = TD.config.client.to_h.merge(extra_config) + @proxy = proxy @ready_condition_mutex = Mutex.new @ready_condition = ConditionVariable.new authorize @@ -98,9 +100,10 @@ def broadcast_and_receive(query, timeout: TIMEOUT) result = nil mutex = Mutex.new handler = ->(update) do - next unless update['@extra'] == extra + return unless update['@extra'] == extra mutex.synchronize do result = update + @update_manager.remove_handler(handler) condition.signal end end @@ -174,6 +177,7 @@ def authorize when 'authorizationStateWaitEncryptionKey' broadcast(encryption_key_query) else + broadcast('@type' => 'setProxy', 'proxy' => @proxy) @update_manager.remove_handler(handler) @ready_condition_mutex.synchronize do @ready = true diff --git a/tdlib-ruby.gemspec b/tdlib-ruby.gemspec index a31417e..d11c4cb 100644 --- a/tdlib-ruby.gemspec +++ b/tdlib-ruby.gemspec @@ -30,7 +30,6 @@ Gem::Specification.new do |gem| gem.require_paths = ['lib'] gem.add_runtime_dependency 'dry-configurable', '~> 0.7' - gem.add_runtime_dependency 'celluloid', '~> 0.17' gem.add_development_dependency 'bundler', '~> 1.10' gem.add_development_dependency 'rake', '12.3.1' From 24d1e467325fc6849561bcb0b08778697ce84e90 Mon Sep 17 00:00:00 2001 From: Vladislav Yashin Date: Fri, 4 May 2018 14:37:51 +0300 Subject: [PATCH 2/2] Bump version [skip ci] --- ChangeLog.md | 4 ++++ lib/tdlib/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index a6d0781..795792c 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,7 @@ +### 0.9.3 / 2018-05-04 + +* Add proxy support + ### 0.9.2 / 2018-05-04 * Fix some potential deadlocks diff --git a/lib/tdlib/version.rb b/lib/tdlib/version.rb index 1be5f88..53f1176 100644 --- a/lib/tdlib/version.rb +++ b/lib/tdlib/version.rb @@ -1,4 +1,4 @@ module TD # tdlib-ruby version - VERSION = "0.9.2" + VERSION = "0.9.3" end