tdlib-ruby 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog.md +3 -0
- data/lib/tdlib-ruby.rb +1 -0
- data/lib/tdlib/client.rb +10 -18
- data/lib/tdlib/version.rb +1 -1
- data/spec/integration/tdlib_spec.rb +2 -2
- data/tdlib-ruby.gemspec +1 -1
- metadata +5 -9
- data/spec/support/update_manager_stub.rb +0 -19
- data/spec/unit/client_spec.rb +0 -73
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c84fd6d3b63901223ca8b58a9bea70c0fb2cae9b
|
4
|
+
data.tar.gz: 154ea127f32e385caba187f87c23a117e98950b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe38b4ed8eca764247be42b4dc66d45c7880ea15bdcba516923aa1668441b89f50c85ec46bcb6c085aa0a016618c44312c06f95b4f988bddbeb9335a751f4c34
|
7
|
+
data.tar.gz: 50c96aabe2d58139604c1f3590da3d8ac80723622cac02cfc64daa23f8af6d924da0be44a5e072dbd310f781ba1a6144332496d7984ff21959411271eced8db0
|
data/ChangeLog.md
CHANGED
data/lib/tdlib-ruby.rb
CHANGED
data/lib/tdlib/client.rb
CHANGED
@@ -58,8 +58,6 @@
|
|
58
58
|
#
|
59
59
|
# p @me
|
60
60
|
class TD::Client
|
61
|
-
include Concurrent
|
62
|
-
|
63
61
|
TIMEOUT = 10
|
64
62
|
|
65
63
|
def initialize(td_client = TD::Api.client_create,
|
@@ -68,6 +66,7 @@ class TD::Client
|
|
68
66
|
@td_client = td_client
|
69
67
|
@update_manager = update_manager
|
70
68
|
@config = TD.config.client.to_h.merge(extra_config)
|
69
|
+
@ready = Celluloid::Condition.new
|
71
70
|
authorize
|
72
71
|
@update_manager.run
|
73
72
|
end
|
@@ -93,19 +92,15 @@ class TD::Client
|
|
93
92
|
# @param [Hash] query
|
94
93
|
# @return [Hash]
|
95
94
|
def broadcast_and_receive(query, timeout: TIMEOUT)
|
96
|
-
|
95
|
+
condition = Celluloid::Condition.new
|
97
96
|
extra = TD::Utils.generate_extra(query)
|
98
|
-
handler = ->(update) {
|
97
|
+
handler = ->(update) { condition.signal(update) if update['@extra'] == extra }
|
99
98
|
@update_manager.add_handler(handler)
|
100
99
|
query['@extra'] = extra
|
101
100
|
TD::Api.client_send(@td_client, query)
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
break if result
|
106
|
-
raise TD::TimeoutError if Time.now - time_start > timeout
|
107
|
-
end
|
108
|
-
result
|
101
|
+
condition.wait(timeout)
|
102
|
+
rescue Celluloid::ConditionError
|
103
|
+
raise TD::TimeoutError
|
109
104
|
end
|
110
105
|
|
111
106
|
# Synchronously executes TDLib request
|
@@ -133,13 +128,10 @@ class TD::Client
|
|
133
128
|
end
|
134
129
|
|
135
130
|
def on_ready(timeout: TIMEOUT, &_)
|
136
|
-
|
137
|
-
loop do
|
138
|
-
sleep 0.1
|
139
|
-
break if @ready
|
140
|
-
raise TD::TimeoutError if Time.now - time_start > timeout
|
141
|
-
end
|
131
|
+
@ready.wait(timeout)
|
142
132
|
yield self
|
133
|
+
rescue Celluloid::ConditionError
|
134
|
+
raise TD::TimeoutError
|
143
135
|
end
|
144
136
|
|
145
137
|
# Stops update manager and destroys TDLib client
|
@@ -172,7 +164,7 @@ class TD::Client
|
|
172
164
|
broadcast(encryption_key_query)
|
173
165
|
else
|
174
166
|
@update_manager.remove_handler(handler)
|
175
|
-
@ready
|
167
|
+
@ready.signal(true)
|
176
168
|
end
|
177
169
|
end
|
178
170
|
@update_manager.add_handler(handler)
|
data/lib/tdlib/version.rb
CHANGED
@@ -36,7 +36,7 @@ describe TD::Client do
|
|
36
36
|
|
37
37
|
it 'runs block on update' do
|
38
38
|
subject
|
39
|
-
sleep
|
39
|
+
sleep 1
|
40
40
|
expect(@result).to include('@type', 'entities')
|
41
41
|
end
|
42
42
|
end
|
@@ -58,7 +58,7 @@ describe TD::Client do
|
|
58
58
|
|
59
59
|
it 'runs block on update' do
|
60
60
|
subject
|
61
|
-
sleep
|
61
|
+
sleep 1
|
62
62
|
expect(@result).to include('@type', 'entities')
|
63
63
|
end
|
64
64
|
end
|
data/tdlib-ruby.gemspec
CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |gem|
|
|
30
30
|
gem.require_paths = ['lib']
|
31
31
|
|
32
32
|
gem.add_runtime_dependency 'dry-configurable', '~> 0.7'
|
33
|
-
gem.add_runtime_dependency '
|
33
|
+
gem.add_runtime_dependency 'celluloid', '~> 0.17'
|
34
34
|
|
35
35
|
gem.add_development_dependency 'bundler', '~> 1.10'
|
36
36
|
gem.add_development_dependency 'rake', '12.3.1'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tdlib-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Southbridge
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|
@@ -25,19 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: celluloid
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0.17'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0.17'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -147,9 +147,7 @@ files:
|
|
147
147
|
- lib/tdlib/version.rb
|
148
148
|
- spec/integration/tdlib_spec.rb
|
149
149
|
- spec/spec_helper.rb
|
150
|
-
- spec/support/update_manager_stub.rb
|
151
150
|
- spec/tdlib_spec.rb
|
152
|
-
- spec/unit/client_spec.rb
|
153
151
|
- tdlib-ruby.gemspec
|
154
152
|
homepage: https://github.com/centosadmin/tdlib-ruby
|
155
153
|
licenses:
|
@@ -178,6 +176,4 @@ summary: Ruby bindings and client for TDlib
|
|
178
176
|
test_files:
|
179
177
|
- spec/integration/tdlib_spec.rb
|
180
178
|
- spec/spec_helper.rb
|
181
|
-
- spec/support/update_manager_stub.rb
|
182
179
|
- spec/tdlib_spec.rb
|
183
|
-
- spec/unit/client_spec.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
class UpdateManagerStub
|
2
|
-
attr_reader :handlers
|
3
|
-
|
4
|
-
def initialize(td_client, update)
|
5
|
-
@td_client, @update, @handlers = td_client, update, []
|
6
|
-
end
|
7
|
-
|
8
|
-
def run
|
9
|
-
end
|
10
|
-
|
11
|
-
def add_handler(handler)
|
12
|
-
@handlers << handler
|
13
|
-
handler.call(@update)
|
14
|
-
end
|
15
|
-
|
16
|
-
def remove_handler(handler)
|
17
|
-
@handlers.delete(handler)
|
18
|
-
end
|
19
|
-
end
|
data/spec/unit/client_spec.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'tdlib-ruby'
|
3
|
-
require 'support/update_manager_stub'
|
4
|
-
|
5
|
-
Thread.abort_on_exception = true
|
6
|
-
|
7
|
-
describe TD::Client do
|
8
|
-
let(:client) { described_class.new(td_client, update_manager) }
|
9
|
-
let(:td_client) { double }
|
10
|
-
let(:update_manager) { UpdateManagerStub.new(td_client, update) }
|
11
|
-
let(:query) { { '@type' => 'type' } }
|
12
|
-
let(:send_result) { 'send_result' }
|
13
|
-
let(:update) { { '@type' => 'update' } }
|
14
|
-
let(:extra) { 'extra' }
|
15
|
-
|
16
|
-
before do
|
17
|
-
allow(TD::Api).to receive(:client_create).and_return(td_client)
|
18
|
-
allow(TD::Api).to receive(:client_send).with(td_client, query).and_return(send_result)
|
19
|
-
allow(TD::Api).to receive(:client_execute).with(td_client, query).and_return(send_result)
|
20
|
-
allow(TD::Api).to receive(:client_receive).with(td_client).and_return(update)
|
21
|
-
|
22
|
-
allow(TD::Utils).to receive(:generate_extra).with(query).and_return(extra)
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '#broadcast' do
|
26
|
-
context 'when no block given' do
|
27
|
-
subject { client.broadcast(query) }
|
28
|
-
|
29
|
-
it { is_expected.to eq(send_result) }
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when block given' do
|
33
|
-
subject { client.broadcast(query) { |update| raise update.to_s } }
|
34
|
-
|
35
|
-
it 'adds @extra key to query' do
|
36
|
-
subject
|
37
|
-
expect(query.keys).to include('@extra')
|
38
|
-
end
|
39
|
-
|
40
|
-
it { is_expected.to eq(send_result) }
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '#broadcast_and_receive' do
|
45
|
-
let(:update) { { '@type' => 'update', '@extra' => extra } }
|
46
|
-
|
47
|
-
subject { client.broadcast_and_receive(query) }
|
48
|
-
|
49
|
-
it { is_expected.to eq(update) }
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '#execute' do
|
53
|
-
subject { client.execute(query) }
|
54
|
-
|
55
|
-
it { is_expected.to eq(send_result) }
|
56
|
-
end
|
57
|
-
|
58
|
-
describe '#on' do
|
59
|
-
subject { client.on('update') { |update| update } }
|
60
|
-
|
61
|
-
context 'when update type matches passed type' do
|
62
|
-
let(:update) { { '@type' => 'update', '@extra' => extra } }
|
63
|
-
|
64
|
-
it { is_expected.to eq(update) }
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'when update type does not match passed type' do
|
68
|
-
let(:update) { { '@type' => 'not_update', '@extra' => extra } }
|
69
|
-
|
70
|
-
it { is_expected.not_to eq(update) }
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|