telegem 3.0.4 → 3.0.6
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/lib/api/client.rb +11 -27
- data/lib/core/bot.rb +16 -13
- data/lib/telegem.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2b1fc2ee7549822e2fbf1a1808f49e274de5a1d1f40be2acd3829087f10e2ace
|
|
4
|
+
data.tar.gz: cf376724f4cd390e690cdaea90eace022eb555ea325416c017ad8a83523b2de9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c1fcf41f167133dfe32d92e7a903b1644b070f9d9544e9cf3de5475a06c6e7c4583770d9df0bea92d0729858700bfc0b955b82b7ec633afef967397e57e25362
|
|
7
|
+
data.tar.gz: ef730bff829458909631028f04cc794cbad161be022ac0218521f11083d36fafb40ea6b18e10fab3e13c4f6501e7696942ea4ba2e697d470d9508186b73812d9
|
data/lib/api/client.rb
CHANGED
|
@@ -30,43 +30,31 @@ module Telegem
|
|
|
30
30
|
def call(method, params = {})
|
|
31
31
|
url = "#{BASE_URL}/bot#{@token}/#{method}"
|
|
32
32
|
@logger.debug("Api call #{method}") if @logger
|
|
33
|
-
response = @http.post(url, json: params.compact)
|
|
34
|
-
response.json
|
|
33
|
+
response = @http.post(url, json: params.compact)
|
|
34
|
+
json = response.json
|
|
35
|
+
if json && json['ok']
|
|
36
|
+
json['result']
|
|
37
|
+
else
|
|
38
|
+
raise APIError.new(json ? json['description']: "Api Error")
|
|
39
|
+
end
|
|
35
40
|
end
|
|
36
41
|
def call!(method, params = {}, &callback)
|
|
37
42
|
url = "#{BASE_URL}/bot#{@token}/#{method}"
|
|
38
43
|
|
|
39
|
-
session = HTTPX.plugin(:callbacks).with(
|
|
40
|
-
timeout: {
|
|
41
|
-
request_timeout: 30,
|
|
42
|
-
connect_timeout: 10,
|
|
43
|
-
write_timeout: 10,
|
|
44
|
-
read_timeout: 30
|
|
45
|
-
},
|
|
46
|
-
headers: {
|
|
47
|
-
'Content-Type' => 'application/json',
|
|
48
|
-
'User-Agent' => "Telegem/#{Telegem::VERSION}"
|
|
49
|
-
}
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
# Set up the callbacks BEFORE making the request
|
|
53
44
|
if callback
|
|
54
|
-
|
|
45
|
+
@http.on_response_completed do |request, response|
|
|
55
46
|
begin
|
|
56
47
|
if response.status == 200
|
|
57
48
|
json = response.json
|
|
58
49
|
if json && json['ok']
|
|
59
|
-
# Success: callback with result
|
|
60
50
|
callback.call(json['result'], nil)
|
|
61
51
|
@logger.debug("API Response: #{json}") if @logger
|
|
62
52
|
else
|
|
63
|
-
# API error (non-200 OK)
|
|
64
53
|
error_msg = json ? json['description'] : "No JSON response"
|
|
65
54
|
error_code = json['error_code'] if json
|
|
66
55
|
callback.call(nil, APIError.new("API Error: #{error_msg}", error_code))
|
|
67
56
|
end
|
|
68
57
|
else
|
|
69
|
-
# HTTP error
|
|
70
58
|
callback.call(nil, NetworkError.new("HTTP #{response.status}"))
|
|
71
59
|
end
|
|
72
60
|
rescue JSON::ParserError
|
|
@@ -76,17 +64,13 @@ module Telegem
|
|
|
76
64
|
end
|
|
77
65
|
end
|
|
78
66
|
|
|
79
|
-
|
|
80
|
-
# Network/connection errors
|
|
67
|
+
@http.on_request_error do |request, error|
|
|
81
68
|
callback.call(nil, error)
|
|
82
69
|
end
|
|
83
70
|
end
|
|
71
|
+
|
|
72
|
+
@http.post(url, json: params.compact)
|
|
84
73
|
|
|
85
|
-
# Make the request and return immediately (async)
|
|
86
|
-
session.post(url, json: params.compact)
|
|
87
|
-
|
|
88
|
-
# Return the session if needed (optional)
|
|
89
|
-
# session
|
|
90
74
|
end
|
|
91
75
|
def upload(method, params)
|
|
92
76
|
url = "#{BASE_URL}/bot#{@token}/#{method}"
|
data/lib/core/bot.rb
CHANGED
|
@@ -189,19 +189,22 @@ end
|
|
|
189
189
|
private
|
|
190
190
|
|
|
191
191
|
def poll_loop
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
192
|
+
last_pool_time = Time.now
|
|
193
|
+
while @running
|
|
194
|
+
elapsed_time = Time.now - last_pool_time
|
|
195
|
+
sleep(0.5 - elapsed_time) if elapsed_time < 0.5
|
|
196
|
+
|
|
197
|
+
fetch_updates do |result, error|
|
|
198
|
+
if error
|
|
199
|
+
@logger.error "polling error #{error.message}"
|
|
200
|
+
sleep(2)
|
|
201
|
+
elsif result && result['ok']
|
|
202
|
+
handle_updates_response(result)
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
sleep 0.1
|
|
206
|
+
end
|
|
207
|
+
end
|
|
205
208
|
|
|
206
209
|
def fetch_updates(&completion_callback)
|
|
207
210
|
params = {
|
data/lib/telegem.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: telegem
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0.
|
|
4
|
+
version: 3.0.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- sick_phantom
|
|
@@ -216,7 +216,7 @@ metadata:
|
|
|
216
216
|
bug_tracker_uri: https://gitlab.com/ruby-telegem/telegem/-/issues
|
|
217
217
|
documentation_uri: https://gitlab.com/ruby-telegem/telegem/-/tree/main/docs-src?ref_type=heads
|
|
218
218
|
rubygems_mfa_required: 'false'
|
|
219
|
-
post_install_message: "Thanks for installing Telegem 3.0.
|
|
219
|
+
post_install_message: "Thanks for installing Telegem 3.0.6!\n\n\U0001F4DA Documentation:
|
|
220
220
|
https://gitlab.com/ruby-telegem/telegem\n\n\U0001F510 For SSL Webhooks:\nRun: telegem-ssl
|
|
221
221
|
your-domain.com\nThis sets up Let's Encrypt certificates automatically.\n\n\U0001F916
|
|
222
222
|
Happy bot building!\n"
|