tdlib-ruby 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f80634d27d92b157b5ce20130ab8a947b4bddfd348268f4126c37abd2d5f8cbe
4
- data.tar.gz: 4b08b602b04eba761bc97349f1ea8f546158fee97a32a1242728e1c768cb5924
3
+ metadata.gz: 6dd68f2d9b132ea200c2f239929ff224e4c3b2bc4510b8b49c1bd2607c03424e
4
+ data.tar.gz: e87a48b7fc213ce6402d5b12890ea332a14c4740d9d75d0afbf3825a6d2c7bca
5
5
  SHA512:
6
- metadata.gz: 9ce2500cb3d549cd7e252e0f62341709958dbbbab7f4cdd298bd48cf84c41609641c9136b220b29c1bb749d6c65397f8db4aebd31249407b5d41de36d6cce072
7
- data.tar.gz: 395f571bdbdb46621b4a3ab78f04e83e5c9dbb173ad9cf737c2b9380608d995003ff2d86af6cc8fbdfebe1f960b6ae0a109c7394e9ad9dced47b57c13d321efc
6
+ metadata.gz: 5be1229082a428085670ba952cd4832483363175ed07e43b3a63724a2243a5ca45c8d5def4ad75e25bd9ad9e57c0db3e059e8b57532c052c7c4f7cd37a47d213
7
+ data.tar.gz: 7ff810f120ab3875fee9db800ad466318135a371223b18f2a7101caadbba9c072e959d10389ce3269d7d71a12941cf3febb4e830599cdbd4f4b9a2c9d258b58e
data/ChangeLog.md CHANGED
@@ -2,3 +2,11 @@
2
2
 
3
3
  * Initial release:
4
4
 
5
+ Basic featues
6
+
7
+ ### 0.2.0 2018-02-16
8
+
9
+ * Improved lib path detection
10
+
11
+ * TD::Client#on_ready method
12
+
data/README.md CHANGED
@@ -11,6 +11,18 @@ Ruby bindings and client for TDLib (Telegram database library).
11
11
  * Ruby 2.3+
12
12
  * Compiled [tdlib](https://github.com/tdlib/td)
13
13
 
14
+ We have precompiled versions for CentOS 6 & 7 in our repositories:
15
+
16
+ http://rpms.southbridge.ru/rhel7/stable/x86_64/
17
+
18
+ http://rpms.southbridge.ru/rhel6/stable/x86_64/
19
+
20
+ And also SRPMS:
21
+
22
+ http://rpms.southbridge.ru/rhel7/stable/SRPMS/
23
+
24
+ http://rpms.southbridge.ru/rhel6/stable/SRPMS/
25
+
14
26
  ## Install
15
27
 
16
28
  Add to your gemfile:
@@ -92,7 +104,7 @@ p @me
92
104
 
93
105
  ```ruby
94
106
  TD.configure do |config|
95
- config.lib_path = 'path/to/dir_containing_libtdjson' # libtdson will be searched in this directory (*.so, *.dylib, *.dll are valid extensions). For Rails projects, if not set, will be considered as project_root_path/vendor
107
+ config.lib_path = 'path/to/dir_containing_libtdjson' # libtdson will be searched in this directory (*.so, *.dylib, *.dll are valid extensions). For Rails projects, if not set, will be considered as project_root_path/vendor. If not set and file doesn't exist in vendor, it will try to find lib by ldconfig (only on Linux).
96
108
  config.encryption_key = 'your_encryption_key' # it's not required
97
109
 
98
110
  config.client.api_id = 12345
data/lib/tdlib/api.rb CHANGED
@@ -39,8 +39,6 @@ module TD::Api
39
39
  module_function
40
40
 
41
41
  def method_missing(method_name, *args)
42
- raise TD::MissingLibPathError unless lib_path
43
-
44
42
  dlload(find_lib)
45
43
 
46
44
  extern 'void* td_json_client_create()'
@@ -55,19 +53,26 @@ module TD::Api
55
53
  public_send(method_name, *args)
56
54
  end
57
55
 
58
- def lib_path
59
- TD.config.lib_path || (defined?(Rails) ? Rails.root.join('vendor').to_s : nil)
60
- end
61
-
62
56
  def find_lib
63
- lib_extension =
64
- case os
65
- when :windows then 'dll'
66
- when :macos then 'dylib'
67
- when :linux then 'so'
68
- else raise "#{os} OS is not supported"
57
+ file_name = "libtdjson.#{lib_extension}"
58
+ lib_path =
59
+ if TD.config.lib_path
60
+ TD.config.lib_path
61
+ elsif defined?(Rails) && File.exist?(Rails.root.join('vendor', file_name))
62
+ Rails.root.join('vendor')
69
63
  end
70
- File.join(lib_path, "libtdjson.#{lib_extension}")
64
+ return `ldconfig -p | grep libtdjson`[/=> (.*?)\n/m, 1] if os == :linux && lib_path.nil?
65
+ raise TD::MissingLibPathError unless lib_path
66
+ File.join(lib_path, file_name)
67
+ end
68
+
69
+ def lib_extension
70
+ case os
71
+ when :windows then 'dll'
72
+ when :macos then 'dylib'
73
+ when :linux then 'so'
74
+ else raise "#{os} OS is not supported"
75
+ end
71
76
  end
72
77
 
73
78
  def os
@@ -86,6 +91,4 @@ module TD::Api
86
91
  end
87
92
  end
88
93
  end
89
-
90
- private_constant :Dl
91
94
  end
data/lib/tdlib/client.rb CHANGED
@@ -58,7 +58,7 @@
58
58
  #
59
59
  # p @me
60
60
  class TD::Client
61
- TIMEOUT = 10
61
+ TIMEOUT = 20
62
62
 
63
63
  def initialize(td_client = TD::Api.client_create,
64
64
  update_manager = TD::UpdateManager.new(td_client),
@@ -130,6 +130,14 @@ class TD::Client
130
130
  @update_manager.add_handler(handler)
131
131
  end
132
132
 
133
+ def on_ready(&_)
134
+ Timeout.timeout(TIMEOUT) do
135
+ until @ready do
136
+ end
137
+ end
138
+ yield self
139
+ end
140
+
133
141
  # Stops update manager and destroys TDLib client
134
142
  def close
135
143
  @update_manager.stop
@@ -160,6 +168,7 @@ class TD::Client
160
168
  broadcast(encryption_key_query)
161
169
  else
162
170
  @update_manager.remove_handler(handler)
171
+ @ready = true
163
172
  end
164
173
  end
165
174
  @update_manager.add_handler(handler)
data/lib/tdlib/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module TD
2
2
  # tdlib-ruby version
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
data/spec/tdlib_spec.rb CHANGED
@@ -6,3 +6,134 @@ describe TD do
6
6
  expect(subject.const_get('VERSION')).to_not be_empty
7
7
  end
8
8
  end
9
+
10
+ class Base
11
+ def self.inherited(subclass)
12
+ subclass.prepend(Module.new do
13
+ define_method(:call) do |*args|
14
+ begin
15
+ super(*args)
16
+ ensure
17
+ p 'test1'
18
+ end
19
+ end
20
+ end)
21
+ end
22
+ end
23
+
24
+ class Test < Base
25
+ def call(a)
26
+ p a
27
+ end
28
+ end
29
+
30
+ p Test.new.('aaa')
31
+
32
+
33
+
34
+ TD.configure do |config|
35
+ config.lib_path = Dir.home
36
+
37
+ config.client.api_id = 39991
38
+ config.client.api_hash = '89b13f68e3840ac787eaa9ba8236d983'
39
+ end
40
+
41
+ #raise TD.config.lib_path
42
+
43
+ # TD::Api.set_log_verbosity_level(1)
44
+ #TD::Api.set_log_file_path("#{Dir.home}/tdlib.log")
45
+
46
+ client = TD::Client.new
47
+
48
+ begin
49
+ state = nil
50
+
51
+ client.on('updateAuthorizationState') do |update|
52
+ next unless update.dig('authorization_state', '@type') == 'authorizationStateWaitPhoneNumber'
53
+ state = :wait_phone
54
+ end
55
+
56
+ client.on('updateAuthorizationState') do |update|
57
+ next unless update.dig('authorization_state', '@type') == 'authorizationStateWaitCode'
58
+ state = :wait_code
59
+ end
60
+
61
+ client.on('updateAuthorizationState') do |update|
62
+ next unless update.dig('authorization_state', '@type') == 'authorizationStateReady'
63
+ state = :ready
64
+ end
65
+
66
+ loop do
67
+ case state
68
+ when :wait_phone
69
+ p 'Please, enter your phone number:'
70
+ phone = STDIN.gets.strip
71
+ params = {
72
+ '@type' => 'setAuthenticationPhoneNumber',
73
+ 'phone_number' => phone
74
+ }
75
+ client.broadcast_and_receive(params)
76
+ when :wait_code
77
+ p 'Please, enter code from SMS:'
78
+ code = STDIN.gets.strip
79
+ params = {
80
+ '@type' => 'checkAuthenticationCode',
81
+ 'code' => code
82
+ }
83
+ a = client.broadcast_and_receive(params)
84
+ when :ready
85
+ client.on_ready do |client|
86
+ @me = client.broadcast_and_receive('@type' => 'getMe')
87
+ #@contacts = client.broadcast_and_receive('@type' => 'searchChatsOnServer', 'query' => 'BotFather', 'limit' => 25)
88
+ @user = client.broadcast_and_receive('@type' => 'getUser', user_id: 132916567)
89
+ @chat = client.broadcast_and_receive('@type' => 'createNewBasicGroupChat', user_ids: [132916567], title: '111')
90
+ @link = client.broadcast_and_receive('@type' => 'generateChatInviteLink', 'chat_id' => @chat['id'])
91
+ @chat2 = client.broadcast_and_receive('@type' => 'getBasicGroupFullInfo', 'basic_group_id' => @chat.dig('type', 'basic_group_id'))['members'].map { |m| m['user_id'] }
92
+ @toggle_admins= client.broadcast_and_receive('@type' => 'toggleBasicGroupAdministrators', 'basic_group_id' => @chat.dig('type', 'basic_group_id'), everyone_is_administrator: false)
93
+ @set_st = client.broadcast_and_receive('@type' => 'setChatMemberStatus',
94
+ 'chat_id' => @chat['id'],
95
+ 'user_id' => 132916567,
96
+ 'status' => {'@type' => 'chatMemberStatusAdministrator'})
97
+ @del = client.broadcast_and_receive('@type' => 'setChatMemberStatus',
98
+ 'chat_id' => @chat['id'],
99
+ 'user_id' => @me['id'],
100
+ 'status' => {'@type' => 'chatMemberStatusLeft'})
101
+ @del1 = client.broadcast_and_receive('@type' => 'setChatMemberStatus',
102
+ 'chat_id' => @chat['id'],
103
+ 'user_id' => 132916567,
104
+ 'status' => {'@type' => 'chatMemberStatusLeft'})
105
+ # @chat = client.broadcast_and_receive('@type' => 'createNewSupergroupChat', 'title' => 'Test3')
106
+ # @link = client.broadcast_and_receive('@type' => 'generateChatInviteLink', 'chat_id' => @chat['id'])
107
+ # @chat2 = client.broadcast_and_receive('@type' => 'getChat', 'chat_id' => @chat['id'])
108
+ # admin = true
109
+ # status = { '@type' => (admin ? 'chatMemberStatusAdministrator' : 'chatMemberStatusMember'),
110
+ # 'can_edit_messages' => true,
111
+ # 'can_post_messages' => true,
112
+ # 'can_delete_messages' => true }
113
+ # @add_u = client.broadcast_and_receive('@type' => 'addChatMember',
114
+ # 'chat_id' => @chat['id'],
115
+ # 'user_id' => @user['id'])
116
+ # @set_st = client.broadcast_and_receive('@type' => 'setChatMemberStatus',
117
+ # 'chat_id' => @chat['id'],
118
+ # 'user_id' => @user['id'],
119
+ # 'status' => status)
120
+ # supergroup_id = @chat2.dig('type', 'supergroup_id')
121
+ # #client.broadcast_and_receive('@type' => 'deleteSupergroup', 'supergroup_id' => supergroup_id)
122
+ end
123
+ break
124
+ end
125
+ end
126
+
127
+ ensure
128
+ client.close
129
+ end
130
+ p @me
131
+ p @chat
132
+ p @link
133
+ p @chat2
134
+ p @toggle_admins
135
+ p @add_u
136
+ p @set_st
137
+ p @del
138
+ p @del1
139
+ # p @chat
data/tdlib-ruby.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.license = "MIT"
13
13
  gem.authors = ["Southbridge"]
14
14
  gem.email = "ask@southbridge.io"
15
- gem.homepage = "https://rubygems.org/gems/tdlib-ruby"
15
+ gem.homepage = "https://github.com/centosadmin/tdlib-ruby"
16
16
 
17
17
  gem.files = `git ls-files`.split($/)
18
18
 
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.1.0
4
+ version: 0.2.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-02-08 00:00:00.000000000 Z
11
+ date: 2018-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -136,7 +136,7 @@ files:
136
136
  - spec/tdlib_spec.rb
137
137
  - spec/unit/client_spec.rb
138
138
  - tdlib-ruby.gemspec
139
- homepage: https://rubygems.org/gems/tdlib-ruby
139
+ homepage: https://github.com/centosadmin/tdlib-ruby
140
140
  licenses:
141
141
  - MIT
142
142
  metadata: {}