gruubY 0.2.1 → 0.2.3
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/LICENSE +21 -21
- data/README.md +11 -6
- data/Rakefile +51 -51
- data/config/config.rb +1 -1
- data/example/bot.rb +122 -2
- data/example/generate_user_session.rb +81 -81
- data/example/tdlib.rb +77 -77
- data/example/userbot.rb +133 -133
- data/lib/gruubY/api.rb +540 -363
- data/lib/gruubY/async.rb +13 -13
- data/lib/gruubY/bot.rb +104 -90
- data/lib/gruubY/bound.rb +14 -14
- data/lib/gruubY/client.rb +310 -296
- data/lib/gruubY/context.rb +296 -242
- data/lib/gruubY/dispatcher.rb +60 -60
- data/lib/gruubY/enums.rb +57 -62
- data/lib/gruubY/exception.rb +5 -5
- data/lib/gruubY/file_stream.rb +17 -17
- data/lib/gruubY/filters.rb +292 -292
- data/lib/gruubY/group_manager.rb +213 -213
- data/lib/gruubY/handlers.rb +225 -170
- data/lib/gruubY/keyboard.rb +49 -49
- data/lib/gruubY/media.rb +38 -38
- data/lib/gruubY/middleware.rb +18 -18
- data/lib/gruubY/plugin.rb +27 -14
- data/lib/gruubY/raw.rb +25 -25
- data/lib/gruubY/retry.rb +14 -14
- data/lib/gruubY/server.rb +18 -18
- data/lib/gruubY/session.rb +30 -30
- data/lib/gruubY/tdlib/client.rb +565 -565
- data/lib/gruubY/tdlib/client_manager.rb +37 -37
- data/lib/gruubY/tdlib/decorators.rb +17 -17
- data/lib/gruubY/tdlib/errors.rb +6 -6
- data/lib/gruubY/tdlib/group_manager.rb +58 -58
- data/lib/gruubY/tdlib/native.rb +72 -72
- data/lib/gruubY/tdlib/schema_builder.rb +237 -237
- data/lib/gruubY/tdlib/tdjson.rb +49 -49
- data/lib/gruubY/tdlib/user_session.rb +69 -69
- data/lib/gruubY/types/base_object.rb +72 -72
- data/lib/gruubY/types/bound_entities.rb +289 -245
- data/lib/gruubY/types/chat.rb +93 -93
- data/lib/gruubY/types/chat_info.rb +32 -31
- data/lib/gruubY/types/extra.rb +289 -251
- data/lib/gruubY/types/message.rb +301 -295
- data/lib/gruubY/types/message_entity.rb +14 -14
- data/lib/gruubY/types/registry.rb +86 -67
- data/lib/gruubY/types/user.rb +47 -31
- data/lib/gruubY/webapp.rb +22 -22
- data/lib/gruubY.rb +39 -41
- data/plugins/logger.rb +7 -7
- metadata +3 -9
- data/example/ntgcalls.rb +0 -80
- data/lib/gruubY/ntgcalls/native.rb +0 -100
- data/lib/gruubY/ntgcalls.rb +0 -478
- data/lib/gruubY/raw_types.rb +0 -57
- data/plugins/media_tools.rb +0 -13
|
@@ -1,237 +1,237 @@
|
|
|
1
|
-
require "json"
|
|
2
|
-
require "net/http"
|
|
3
|
-
require "uri"
|
|
4
|
-
require "cgi"
|
|
5
|
-
require "stringio"
|
|
6
|
-
|
|
7
|
-
module GrubY
|
|
8
|
-
module TDLib
|
|
9
|
-
class SchemaBuilder
|
|
10
|
-
TL_DEF_REGEX = /^(?<name>\w+)(?:#[0-9a-f]+)?\s+(?<params>.*)=\s+(?<type>\w+);$/
|
|
11
|
-
PARAM_DETAIL_REGEX = /(?<name>\w+):(?<type>[^\s]+)/
|
|
12
|
-
ROW_REGEX = /<tr>\s*<td>(.*?)<\/td>\s*<td>(.*?)<\/td>\s*<td>(.*?)<\/td>\s*<td>(.*?)<\/td>\s*<\/tr>/m
|
|
13
|
-
TAG_REGEX = /<[^>]*>/
|
|
14
|
-
|
|
15
|
-
def initialize(src:, version: "", commit: "", out: "tdlib.json")
|
|
16
|
-
@src = src
|
|
17
|
-
@version = version
|
|
18
|
-
@commit = commit
|
|
19
|
-
@out = out
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def call
|
|
23
|
-
data = if @src.start_with?("http://", "https://")
|
|
24
|
-
fetch_and_parse_tl(@src)
|
|
25
|
-
else
|
|
26
|
-
parse_tl_from_file(@src)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
data["version"] = @version
|
|
30
|
-
data["commit"] = @commit
|
|
31
|
-
|
|
32
|
-
begin
|
|
33
|
-
data["options"] = fetch_options
|
|
34
|
-
rescue StandardError => e
|
|
35
|
-
warn "Warning: failed to fetch options: #{e.message}"
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
save_json(data, @out)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
private
|
|
42
|
-
|
|
43
|
-
def parse_tl_from_file(path)
|
|
44
|
-
File.open(path, "r:utf-8") do |file|
|
|
45
|
-
parse_tl_from_reader(file)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def fetch_and_parse_tl(url)
|
|
50
|
-
uri = URI.parse(url)
|
|
51
|
-
request = Net::HTTP::Get.new(uri)
|
|
52
|
-
request["User-Agent"] = "gruby-tdlib-schema-builder/1.0"
|
|
53
|
-
|
|
54
|
-
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https", read_timeout: 30, open_timeout: 30) do |http|
|
|
55
|
-
http.request(request)
|
|
56
|
-
end
|
|
57
|
-
raise "failed to fetch #{url}: status #{response.code}" unless response.is_a?(Net::HTTPSuccess)
|
|
58
|
-
|
|
59
|
-
parse_tl_from_reader(StringIO.new(response.body))
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def parse_tl_from_reader(reader)
|
|
63
|
-
data = {
|
|
64
|
-
"name" => "Auto-generated JSON TDLib API",
|
|
65
|
-
"version" => "",
|
|
66
|
-
"commit" => "",
|
|
67
|
-
"classes" => {},
|
|
68
|
-
"types" => {},
|
|
69
|
-
"updates" => {},
|
|
70
|
-
"functions" => {},
|
|
71
|
-
"options" => {}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
current_description = ""
|
|
75
|
-
current_params = {}
|
|
76
|
-
is_functions_section = false
|
|
77
|
-
start = false
|
|
78
|
-
|
|
79
|
-
reader.each_line do |raw_line|
|
|
80
|
-
line = raw_line.strip
|
|
81
|
-
|
|
82
|
-
if line.include?("---functions---")
|
|
83
|
-
is_functions_section = true
|
|
84
|
-
next
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
if line.start_with?("//")
|
|
88
|
-
start = true
|
|
89
|
-
if line.start_with?("//@")
|
|
90
|
-
parse_doc_tags(data, line.sub("//@", ""), current_params) do |description|
|
|
91
|
-
current_description = [current_description, description].reject(&:empty?).join(" ").strip
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
next
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
next if line.empty? || !start
|
|
98
|
-
|
|
99
|
-
match = TL_DEF_REGEX.match(line)
|
|
100
|
-
next unless match
|
|
101
|
-
|
|
102
|
-
name = match[:name]
|
|
103
|
-
params_str = match[:params]
|
|
104
|
-
result_type = match[:type]
|
|
105
|
-
|
|
106
|
-
type_def = {
|
|
107
|
-
"description" => current_description,
|
|
108
|
-
"args" => {},
|
|
109
|
-
"type" => result_type
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
params_str.scan(PARAM_DETAIL_REGEX) do |p_name, p_type|
|
|
113
|
-
p_desc = current_params[p_name] || ""
|
|
114
|
-
type_def["args"][p_name] = {
|
|
115
|
-
"description" => p_desc,
|
|
116
|
-
"is_optional" => optional_arg?(p_desc, p_type),
|
|
117
|
-
"type" => p_type
|
|
118
|
-
}
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
if is_functions_section
|
|
122
|
-
data["functions"][name] = type_def
|
|
123
|
-
(data["classes"][result_type] ||= default_class)["functions"] << name
|
|
124
|
-
elsif name.start_with?("update")
|
|
125
|
-
data["updates"][name] = type_def
|
|
126
|
-
(data["classes"][result_type] ||= default_class)["types"] << name
|
|
127
|
-
else
|
|
128
|
-
data["types"][name] = type_def
|
|
129
|
-
(data["classes"][result_type] ||= default_class)["types"] << name
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
current_description = ""
|
|
133
|
-
current_params = {}
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
data
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
def parse_doc_tags(data, tag_line, current_params)
|
|
140
|
-
parts = (" " + tag_line).split(" @")
|
|
141
|
-
current_class = nil
|
|
142
|
-
|
|
143
|
-
parts.each do |part|
|
|
144
|
-
part = part.strip
|
|
145
|
-
next if part.empty?
|
|
146
|
-
|
|
147
|
-
tag_name, tag_text = part.split(" ", 2)
|
|
148
|
-
tag_text = (tag_text || "").strip
|
|
149
|
-
|
|
150
|
-
case tag_name
|
|
151
|
-
when "class"
|
|
152
|
-
current_class = tag_text
|
|
153
|
-
when "description"
|
|
154
|
-
if current_class
|
|
155
|
-
data["classes"][current_class] = {
|
|
156
|
-
"description" => tag_text,
|
|
157
|
-
"types" => [],
|
|
158
|
-
"functions" => []
|
|
159
|
-
}
|
|
160
|
-
current_class = nil
|
|
161
|
-
else
|
|
162
|
-
yield(tag_text)
|
|
163
|
-
end
|
|
164
|
-
else
|
|
165
|
-
clean_name = tag_name.sub(/^param_/, "")
|
|
166
|
-
current_params[clean_name] = [current_params[clean_name], tag_text].compact.join(" ").strip
|
|
167
|
-
end
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
def default_class
|
|
172
|
-
{ "description" => "", "types" => [], "functions" => [] }
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
def optional_arg?(description, type)
|
|
176
|
-
text = description.to_s.downcase
|
|
177
|
-
text.include?("may be null") ||
|
|
178
|
-
text.include?("pass null") ||
|
|
179
|
-
text.include?("may be empty") ||
|
|
180
|
-
description.to_s.include?("If non-empty,") ||
|
|
181
|
-
type.to_s.include?("?")
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
def fetch_options
|
|
185
|
-
url = URI.parse("https://core.telegram.org/tdlib/options")
|
|
186
|
-
request = Net::HTTP::Get.new(url)
|
|
187
|
-
request["User-Agent"] = "gruby-tdlib-schema-builder/1.0"
|
|
188
|
-
|
|
189
|
-
response = Net::HTTP.start(url.host, url.port, use_ssl: true, read_timeout: 30, open_timeout: 30) do |http|
|
|
190
|
-
http.request(request)
|
|
191
|
-
end
|
|
192
|
-
raise "failed to fetch options: status #{response.code}" unless response.is_a?(Net::HTTPSuccess)
|
|
193
|
-
|
|
194
|
-
content = response.body
|
|
195
|
-
marker_index = content.index("list-of-options-supported-by-tdlib")
|
|
196
|
-
raise "could not find options list in HTML" unless marker_index
|
|
197
|
-
|
|
198
|
-
options = {}
|
|
199
|
-
content[marker_index..].scan(ROW_REGEX) do |name, type_name, writable, description|
|
|
200
|
-
clean_name = clean_html(name)
|
|
201
|
-
next if clean_name.empty? || clean_name.casecmp("name").zero?
|
|
202
|
-
|
|
203
|
-
options[clean_name] = {
|
|
204
|
-
"type" => map_type(clean_html(type_name)),
|
|
205
|
-
"writable" => clean_html(writable).casecmp("yes").zero?,
|
|
206
|
-
"description" => clean_html(description)
|
|
207
|
-
}
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
raise "no options were parsed from HTML" if options.empty?
|
|
211
|
-
|
|
212
|
-
options
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
def clean_html(text)
|
|
216
|
-
CGI.unescapeHTML(text.gsub(TAG_REGEX, "").strip)
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
def map_type(type_name)
|
|
220
|
-
case type_name
|
|
221
|
-
when "Integer"
|
|
222
|
-
"int64"
|
|
223
|
-
when "Boolean"
|
|
224
|
-
"Bool"
|
|
225
|
-
when "String"
|
|
226
|
-
"string"
|
|
227
|
-
else
|
|
228
|
-
type_name
|
|
229
|
-
end
|
|
230
|
-
end
|
|
231
|
-
|
|
232
|
-
def save_json(data, path)
|
|
233
|
-
File.write(path, JSON.pretty_generate(data) + "\n")
|
|
234
|
-
end
|
|
235
|
-
end
|
|
236
|
-
end
|
|
237
|
-
end
|
|
1
|
+
require "json"
|
|
2
|
+
require "net/http"
|
|
3
|
+
require "uri"
|
|
4
|
+
require "cgi"
|
|
5
|
+
require "stringio"
|
|
6
|
+
|
|
7
|
+
module GrubY
|
|
8
|
+
module TDLib
|
|
9
|
+
class SchemaBuilder
|
|
10
|
+
TL_DEF_REGEX = /^(?<name>\w+)(?:#[0-9a-f]+)?\s+(?<params>.*)=\s+(?<type>\w+);$/
|
|
11
|
+
PARAM_DETAIL_REGEX = /(?<name>\w+):(?<type>[^\s]+)/
|
|
12
|
+
ROW_REGEX = /<tr>\s*<td>(.*?)<\/td>\s*<td>(.*?)<\/td>\s*<td>(.*?)<\/td>\s*<td>(.*?)<\/td>\s*<\/tr>/m
|
|
13
|
+
TAG_REGEX = /<[^>]*>/
|
|
14
|
+
|
|
15
|
+
def initialize(src:, version: "", commit: "", out: "tdlib.json")
|
|
16
|
+
@src = src
|
|
17
|
+
@version = version
|
|
18
|
+
@commit = commit
|
|
19
|
+
@out = out
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def call
|
|
23
|
+
data = if @src.start_with?("http://", "https://")
|
|
24
|
+
fetch_and_parse_tl(@src)
|
|
25
|
+
else
|
|
26
|
+
parse_tl_from_file(@src)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
data["version"] = @version
|
|
30
|
+
data["commit"] = @commit
|
|
31
|
+
|
|
32
|
+
begin
|
|
33
|
+
data["options"] = fetch_options
|
|
34
|
+
rescue StandardError => e
|
|
35
|
+
warn "Warning: failed to fetch options: #{e.message}"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
save_json(data, @out)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def parse_tl_from_file(path)
|
|
44
|
+
File.open(path, "r:utf-8") do |file|
|
|
45
|
+
parse_tl_from_reader(file)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def fetch_and_parse_tl(url)
|
|
50
|
+
uri = URI.parse(url)
|
|
51
|
+
request = Net::HTTP::Get.new(uri)
|
|
52
|
+
request["User-Agent"] = "gruby-tdlib-schema-builder/1.0"
|
|
53
|
+
|
|
54
|
+
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https", read_timeout: 30, open_timeout: 30) do |http|
|
|
55
|
+
http.request(request)
|
|
56
|
+
end
|
|
57
|
+
raise "failed to fetch #{url}: status #{response.code}" unless response.is_a?(Net::HTTPSuccess)
|
|
58
|
+
|
|
59
|
+
parse_tl_from_reader(StringIO.new(response.body))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def parse_tl_from_reader(reader)
|
|
63
|
+
data = {
|
|
64
|
+
"name" => "Auto-generated JSON TDLib API",
|
|
65
|
+
"version" => "",
|
|
66
|
+
"commit" => "",
|
|
67
|
+
"classes" => {},
|
|
68
|
+
"types" => {},
|
|
69
|
+
"updates" => {},
|
|
70
|
+
"functions" => {},
|
|
71
|
+
"options" => {}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
current_description = ""
|
|
75
|
+
current_params = {}
|
|
76
|
+
is_functions_section = false
|
|
77
|
+
start = false
|
|
78
|
+
|
|
79
|
+
reader.each_line do |raw_line|
|
|
80
|
+
line = raw_line.strip
|
|
81
|
+
|
|
82
|
+
if line.include?("---functions---")
|
|
83
|
+
is_functions_section = true
|
|
84
|
+
next
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
if line.start_with?("//")
|
|
88
|
+
start = true
|
|
89
|
+
if line.start_with?("//@")
|
|
90
|
+
parse_doc_tags(data, line.sub("//@", ""), current_params) do |description|
|
|
91
|
+
current_description = [current_description, description].reject(&:empty?).join(" ").strip
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
next
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
next if line.empty? || !start
|
|
98
|
+
|
|
99
|
+
match = TL_DEF_REGEX.match(line)
|
|
100
|
+
next unless match
|
|
101
|
+
|
|
102
|
+
name = match[:name]
|
|
103
|
+
params_str = match[:params]
|
|
104
|
+
result_type = match[:type]
|
|
105
|
+
|
|
106
|
+
type_def = {
|
|
107
|
+
"description" => current_description,
|
|
108
|
+
"args" => {},
|
|
109
|
+
"type" => result_type
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
params_str.scan(PARAM_DETAIL_REGEX) do |p_name, p_type|
|
|
113
|
+
p_desc = current_params[p_name] || ""
|
|
114
|
+
type_def["args"][p_name] = {
|
|
115
|
+
"description" => p_desc,
|
|
116
|
+
"is_optional" => optional_arg?(p_desc, p_type),
|
|
117
|
+
"type" => p_type
|
|
118
|
+
}
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
if is_functions_section
|
|
122
|
+
data["functions"][name] = type_def
|
|
123
|
+
(data["classes"][result_type] ||= default_class)["functions"] << name
|
|
124
|
+
elsif name.start_with?("update")
|
|
125
|
+
data["updates"][name] = type_def
|
|
126
|
+
(data["classes"][result_type] ||= default_class)["types"] << name
|
|
127
|
+
else
|
|
128
|
+
data["types"][name] = type_def
|
|
129
|
+
(data["classes"][result_type] ||= default_class)["types"] << name
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
current_description = ""
|
|
133
|
+
current_params = {}
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
data
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def parse_doc_tags(data, tag_line, current_params)
|
|
140
|
+
parts = (" " + tag_line).split(" @")
|
|
141
|
+
current_class = nil
|
|
142
|
+
|
|
143
|
+
parts.each do |part|
|
|
144
|
+
part = part.strip
|
|
145
|
+
next if part.empty?
|
|
146
|
+
|
|
147
|
+
tag_name, tag_text = part.split(" ", 2)
|
|
148
|
+
tag_text = (tag_text || "").strip
|
|
149
|
+
|
|
150
|
+
case tag_name
|
|
151
|
+
when "class"
|
|
152
|
+
current_class = tag_text
|
|
153
|
+
when "description"
|
|
154
|
+
if current_class
|
|
155
|
+
data["classes"][current_class] = {
|
|
156
|
+
"description" => tag_text,
|
|
157
|
+
"types" => [],
|
|
158
|
+
"functions" => []
|
|
159
|
+
}
|
|
160
|
+
current_class = nil
|
|
161
|
+
else
|
|
162
|
+
yield(tag_text)
|
|
163
|
+
end
|
|
164
|
+
else
|
|
165
|
+
clean_name = tag_name.sub(/^param_/, "")
|
|
166
|
+
current_params[clean_name] = [current_params[clean_name], tag_text].compact.join(" ").strip
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def default_class
|
|
172
|
+
{ "description" => "", "types" => [], "functions" => [] }
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def optional_arg?(description, type)
|
|
176
|
+
text = description.to_s.downcase
|
|
177
|
+
text.include?("may be null") ||
|
|
178
|
+
text.include?("pass null") ||
|
|
179
|
+
text.include?("may be empty") ||
|
|
180
|
+
description.to_s.include?("If non-empty,") ||
|
|
181
|
+
type.to_s.include?("?")
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def fetch_options
|
|
185
|
+
url = URI.parse("https://core.telegram.org/tdlib/options")
|
|
186
|
+
request = Net::HTTP::Get.new(url)
|
|
187
|
+
request["User-Agent"] = "gruby-tdlib-schema-builder/1.0"
|
|
188
|
+
|
|
189
|
+
response = Net::HTTP.start(url.host, url.port, use_ssl: true, read_timeout: 30, open_timeout: 30) do |http|
|
|
190
|
+
http.request(request)
|
|
191
|
+
end
|
|
192
|
+
raise "failed to fetch options: status #{response.code}" unless response.is_a?(Net::HTTPSuccess)
|
|
193
|
+
|
|
194
|
+
content = response.body
|
|
195
|
+
marker_index = content.index("list-of-options-supported-by-tdlib")
|
|
196
|
+
raise "could not find options list in HTML" unless marker_index
|
|
197
|
+
|
|
198
|
+
options = {}
|
|
199
|
+
content[marker_index..].scan(ROW_REGEX) do |name, type_name, writable, description|
|
|
200
|
+
clean_name = clean_html(name)
|
|
201
|
+
next if clean_name.empty? || clean_name.casecmp("name").zero?
|
|
202
|
+
|
|
203
|
+
options[clean_name] = {
|
|
204
|
+
"type" => map_type(clean_html(type_name)),
|
|
205
|
+
"writable" => clean_html(writable).casecmp("yes").zero?,
|
|
206
|
+
"description" => clean_html(description)
|
|
207
|
+
}
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
raise "no options were parsed from HTML" if options.empty?
|
|
211
|
+
|
|
212
|
+
options
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def clean_html(text)
|
|
216
|
+
CGI.unescapeHTML(text.gsub(TAG_REGEX, "").strip)
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
def map_type(type_name)
|
|
220
|
+
case type_name
|
|
221
|
+
when "Integer"
|
|
222
|
+
"int64"
|
|
223
|
+
when "Boolean"
|
|
224
|
+
"Bool"
|
|
225
|
+
when "String"
|
|
226
|
+
"string"
|
|
227
|
+
else
|
|
228
|
+
type_name
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def save_json(data, path)
|
|
233
|
+
File.write(path, JSON.pretty_generate(data) + "\n")
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
end
|
data/lib/gruubY/tdlib/tdjson.rb
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
require "json"
|
|
2
|
-
require_relative "native"
|
|
3
|
-
|
|
4
|
-
module GrubY
|
|
5
|
-
module TDLib
|
|
6
|
-
class TdJson
|
|
7
|
-
attr_reader :version
|
|
8
|
-
|
|
9
|
-
def initialize(lib_path: nil, verbosity: 1)
|
|
10
|
-
Native.load!(lib_path)
|
|
11
|
-
Native.td_set_log_verbosity_level(verbosity.to_i)
|
|
12
|
-
@version = fetch_version
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def create_client_id
|
|
16
|
-
Native.td_json_client_create
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def send(client_id, request)
|
|
20
|
-
Native.td_json_client_send(client_id, JSON.generate(request))
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def receive(client_id, timeout:)
|
|
24
|
-
raw = Native.td_json_client_receive(client_id, timeout.to_f)
|
|
25
|
-
raw ? JSON.parse(raw) : nil
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def execute(client_id, request)
|
|
29
|
-
raw = Native.td_json_client_execute(client_id, JSON.generate(request))
|
|
30
|
-
raw ? JSON.parse(raw) : nil
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def destroy(client_id)
|
|
34
|
-
Native.td_json_client_destroy(client_id)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
private
|
|
38
|
-
|
|
39
|
-
def fetch_version
|
|
40
|
-
temp = create_client_id
|
|
41
|
-
response = execute(temp, { "@type" => "getOption", "name" => "version" })
|
|
42
|
-
destroy(temp)
|
|
43
|
-
response&.dig("value", "value")
|
|
44
|
-
rescue StandardError
|
|
45
|
-
nil
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
1
|
+
require "json"
|
|
2
|
+
require_relative "native"
|
|
3
|
+
|
|
4
|
+
module GrubY
|
|
5
|
+
module TDLib
|
|
6
|
+
class TdJson
|
|
7
|
+
attr_reader :version
|
|
8
|
+
|
|
9
|
+
def initialize(lib_path: nil, verbosity: 1)
|
|
10
|
+
Native.load!(lib_path)
|
|
11
|
+
Native.td_set_log_verbosity_level(verbosity.to_i)
|
|
12
|
+
@version = fetch_version
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def create_client_id
|
|
16
|
+
Native.td_json_client_create
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def send(client_id, request)
|
|
20
|
+
Native.td_json_client_send(client_id, JSON.generate(request))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def receive(client_id, timeout:)
|
|
24
|
+
raw = Native.td_json_client_receive(client_id, timeout.to_f)
|
|
25
|
+
raw ? JSON.parse(raw) : nil
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def execute(client_id, request)
|
|
29
|
+
raw = Native.td_json_client_execute(client_id, JSON.generate(request))
|
|
30
|
+
raw ? JSON.parse(raw) : nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def destroy(client_id)
|
|
34
|
+
Native.td_json_client_destroy(client_id)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def fetch_version
|
|
40
|
+
temp = create_client_id
|
|
41
|
+
response = execute(temp, { "@type" => "getOption", "name" => "version" })
|
|
42
|
+
destroy(temp)
|
|
43
|
+
response&.dig("value", "value")
|
|
44
|
+
rescue StandardError
|
|
45
|
+
nil
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|