telegram-ruby 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/telegram/bot.rb +1 -0
- data/lib/telegram/bot/api.rb +1 -1
- data/lib/telegram/bot/botan.rb +1 -1
- data/lib/telegram/bot/client.rb +1 -1
- data/lib/telegram/bot/exceptions.rb +7 -7
- data/lib/telegram/bot/login.rb +19 -0
- data/lib/telegram/bot/types/inline_keyboard_markup.rb +3 -2
- data/lib/telegram/bot/types/reply_keyboard_markup.rb +1 -1
- data/lib/telegram/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70eaf9fcc2201790d04dd5d3f869381e7bfa3fdd71251b829c3c4966ec774303
|
4
|
+
data.tar.gz: ca1b6479195e5b7875af8c121aa459d248cbebbdd1751ae65c4a7d7047993a38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2533124cc5c0788c7bfdc368d0fac47a84209ec2a4c9953650e96f3d07be9d33fcefdfd5c775be4c9c6c2ef8bc55cb2f91142fdefddbaa4b82a24922e242f0e
|
7
|
+
data.tar.gz: 577e5597e564440d9cd59e750a88f418a03a2d632def2b5cba3f2f2b7229a6b36c43e1b04f0328dc31e23b0681c798ff0a716cf9b5fc317e7c0c5ec011c4efc3
|
data/lib/telegram/bot.rb
CHANGED
data/lib/telegram/bot/api.rb
CHANGED
@@ -236,7 +236,7 @@ module Telegram
|
|
236
236
|
body = response.body
|
237
237
|
|
238
238
|
if Bot.configuration.raise_exceptions && (response.status != 200 || body['ok'] != true)
|
239
|
-
raise
|
239
|
+
raise Telegram::Bot::ResponseError.new(body['description'])
|
240
240
|
end
|
241
241
|
|
242
242
|
if type_obj.nil?
|
data/lib/telegram/bot/botan.rb
CHANGED
data/lib/telegram/bot/client.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
module Telegram
|
2
2
|
module Bot
|
3
|
-
|
4
|
-
class Error < StandardError; end
|
3
|
+
class Error < StandardError; end
|
5
4
|
|
6
|
-
|
5
|
+
class ResponseError < Error; end
|
7
6
|
|
8
|
-
|
7
|
+
class ParseError < Error; end
|
9
8
|
|
10
|
-
|
9
|
+
class KeyboardMarkupError < Error; end
|
11
10
|
|
12
|
-
|
13
|
-
|
11
|
+
class LoginError < Error; end
|
12
|
+
|
13
|
+
class BotanError < Error; end
|
14
14
|
end
|
15
15
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
|
3
|
+
module Telegram::Bot
|
4
|
+
class Login
|
5
|
+
def self.verify!(auth_data)
|
6
|
+
check_hash = auth_data[:hash]
|
7
|
+
auth_data = auth_data.slice(:auth_date, :first_name, :id, :last_name, :photo_url, :username)
|
8
|
+
check_string = auth_data.map {|k, v| "#{k}=#{v}" }.sort.join("\n")
|
9
|
+
|
10
|
+
secret_key = OpenSSL::Digest::SHA256.new.digest('523479371:AAHutDxVN_4NI5oBmIMj8mfmn47bbOWqD70')
|
11
|
+
hash = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), secret_key, check_string)
|
12
|
+
|
13
|
+
raise Telegram::Bot::LoginError.new('Data is NOT from Telegram') if (hash.casecmp(check_hash) != 0)
|
14
|
+
raise Telegram::Bot::LoginError.new('Data is outdated') if Time.now.to_i - auth_data[:auth_date] > 86400
|
15
|
+
|
16
|
+
true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -10,8 +10,9 @@ module Telegram::Bot::Types
|
|
10
10
|
elsif b.is_a?(Hash)
|
11
11
|
InlineKeyboardButton.new(b)
|
12
12
|
else
|
13
|
-
raise Telegram::Bot::
|
14
|
-
|
13
|
+
raise Telegram::Bot::KeyboardMarkupError.new(
|
14
|
+
'Attributes must be Array of Array of Telegram::Bot::Types::InlineKeyboardButton or Hash'
|
15
|
+
)
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
@@ -12,7 +12,7 @@ module Telegram::Bot::Types
|
|
12
12
|
elsif b.is_a?(Hash)
|
13
13
|
InlineKeyboardButton.new(b)
|
14
14
|
else
|
15
|
-
raise Telegram::Bot::
|
15
|
+
raise Telegram::Bot::KeyboardMarkupError
|
16
16
|
.new('Attributes must be Array of Array of Telegram::Bot::Types::KeyboardButton or Hash')
|
17
17
|
end
|
18
18
|
end
|
data/lib/telegram/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: telegram-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Belenky
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- lib/telegram/bot/client_accessors.rb
|
108
108
|
- lib/telegram/bot/configuration.rb
|
109
109
|
- lib/telegram/bot/exceptions.rb
|
110
|
+
- lib/telegram/bot/login.rb
|
110
111
|
- lib/telegram/bot/types.rb
|
111
112
|
- lib/telegram/bot/types/animation.rb
|
112
113
|
- lib/telegram/bot/types/audio.rb
|