telegem 2.0.2 → 2.0.4
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 +8 -37
- 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: 1fe252e1a7c876b5972ebcd9bd9d9628380fa685f1d946bb7de1b31d2fc2b36c
|
|
4
|
+
data.tar.gz: ad9193ee1aaf94d9dcc1a7e1de0b33f08b096cab84ccbd946bd452b993da5aa4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 07c915cfc64d885e8e873f3d45f8c40ccd2130519c3389b44e88992b94f2fc32a55ae88a163d75a63a3df9f72a9da1b7117bf0cf96dffc3e302197a4f16e535e
|
|
7
|
+
data.tar.gz: 3563db219318115c0f6043cb57d6fadd4bef858474a5694b2ecdba874e3361dc858f52eb4a38d2eb240112a439983973cba7ac7ee15fc989f458a258254a8538
|
data/lib/api/client.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# lib/api/client.rb - WORKING VERSION
|
|
1
|
+
# lib/api/client.rb - MINIMAL WORKING VERSION
|
|
2
2
|
require 'httpx'
|
|
3
3
|
require 'json'
|
|
4
4
|
|
|
@@ -12,28 +12,18 @@ module Telegem
|
|
|
12
12
|
def initialize(token, **options)
|
|
13
13
|
@token = token
|
|
14
14
|
@logger = options[:logger] || Logger.new($stdout)
|
|
15
|
-
timeout = options[:timeout] || 30
|
|
15
|
+
@timeout = options[:timeout] || 30
|
|
16
16
|
|
|
17
17
|
@http = HTTPX.with(
|
|
18
|
-
timeout: {
|
|
19
|
-
connect_timeout: 10,
|
|
20
|
-
write_timeout: 10,
|
|
21
|
-
read_timeout: timeout
|
|
22
|
-
},
|
|
18
|
+
timeout: { request_timeout: @timeout},
|
|
23
19
|
headers: {
|
|
24
|
-
'Content-Type' => 'application/json'
|
|
25
|
-
'User-Agent' => "Telegem/#{Telegem::VERSION}"
|
|
20
|
+
'Content-Type' => 'application/json'
|
|
26
21
|
}
|
|
27
22
|
)
|
|
28
|
-
|
|
29
|
-
ObjectSpace.define_finalizer(self, proc { close })
|
|
30
23
|
end
|
|
31
24
|
|
|
32
25
|
def call(method, params = {})
|
|
33
26
|
url = "#{BASE_URL}/bot#{@token}/#{method}"
|
|
34
|
-
|
|
35
|
-
@logger.debug("API: #{method}") if @logger
|
|
36
|
-
|
|
37
27
|
@http.post(url, json: params.compact)
|
|
38
28
|
end
|
|
39
29
|
|
|
@@ -51,7 +41,6 @@ module Telegem
|
|
|
51
41
|
|
|
52
42
|
def upload(method, params)
|
|
53
43
|
url = "#{BASE_URL}/bot#{@token}/#{method}"
|
|
54
|
-
|
|
55
44
|
form = params.map do |key, value|
|
|
56
45
|
if file_object?(value)
|
|
57
46
|
[key.to_s, HTTPX::FormData::File.new(value)]
|
|
@@ -59,7 +48,6 @@ module Telegem
|
|
|
59
48
|
[key.to_s, value.to_s]
|
|
60
49
|
end
|
|
61
50
|
end
|
|
62
|
-
|
|
63
51
|
@http.post(url, form: form)
|
|
64
52
|
end
|
|
65
53
|
|
|
@@ -67,7 +55,6 @@ module Telegem
|
|
|
67
55
|
params = { timeout: timeout, limit: limit }
|
|
68
56
|
params[:offset] = offset if offset
|
|
69
57
|
params[:allowed_updates] = allowed_updates if allowed_updates
|
|
70
|
-
|
|
71
58
|
call('getUpdates', params)
|
|
72
59
|
end
|
|
73
60
|
|
|
@@ -84,15 +71,8 @@ module Telegem
|
|
|
84
71
|
raise APIError, "HTTP #{response.status}"
|
|
85
72
|
end
|
|
86
73
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
rescue JSON::ParserError
|
|
90
|
-
raise APIError, "Invalid JSON response"
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
unless json
|
|
94
|
-
raise APIError, "Empty response"
|
|
95
|
-
end
|
|
74
|
+
json = response.json
|
|
75
|
+
return nil unless json
|
|
96
76
|
|
|
97
77
|
if json['ok']
|
|
98
78
|
json['result']
|
|
@@ -102,17 +82,8 @@ module Telegem
|
|
|
102
82
|
end
|
|
103
83
|
|
|
104
84
|
def handle_error(error)
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
@logger.error("Timeout: #{error.message}") if @logger
|
|
108
|
-
raise NetworkError, "Request timeout"
|
|
109
|
-
when HTTPX::ConnectionError
|
|
110
|
-
@logger.error("Connection error: #{error.message}") if @logger
|
|
111
|
-
raise NetworkError, "Connection failed"
|
|
112
|
-
else
|
|
113
|
-
@logger.error("Error: #{error.class}: #{error.message}") if @logger
|
|
114
|
-
raise APIError, error.message
|
|
115
|
-
end
|
|
85
|
+
@logger.error("API Error: #{error.message}") if @logger
|
|
86
|
+
raise APIError, error.message
|
|
116
87
|
end
|
|
117
88
|
|
|
118
89
|
def file_object?(obj)
|
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: 2.0.
|
|
4
|
+
version: 2.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- sick_phantom
|
|
@@ -198,7 +198,7 @@ metadata:
|
|
|
198
198
|
bug_tracker_uri: https://gitlab.com/ruby-telegem/telegem/-/issues
|
|
199
199
|
documentation_uri: https://gitlab.com/ruby-telegem/telegem/-/blob/main/README.md
|
|
200
200
|
rubygems_mfa_required: 'false'
|
|
201
|
-
post_install_message: "Thanks for installing Telegem 2.0.
|
|
201
|
+
post_install_message: "Thanks for installing Telegem 2.0.4!\n\nQuick start:\n bot
|
|
202
202
|
= Telegem.new(\"YOUR_TOKEN\")\n bot.on(:message) { |ctx| ctx.reply(\"Hello!\")
|
|
203
203
|
}\n bot.start_polling\n\nDocumentation: https://gitlab.com/ruby-telegem/telegem\nHappy
|
|
204
204
|
bot building! \U0001F916\n"
|