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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3e2cd90813371c48e86462f40c3d14bfe89d1ea690d353afbe3e7423f5ad614
4
- data.tar.gz: c67cb2a2abf5f70cb3b709a34dd08b9812506673964620bab999aa16a5935c92
3
+ metadata.gz: 70eaf9fcc2201790d04dd5d3f869381e7bfa3fdd71251b829c3c4966ec774303
4
+ data.tar.gz: ca1b6479195e5b7875af8c121aa459d248cbebbdd1751ae65c4a7d7047993a38
5
5
  SHA512:
6
- metadata.gz: 3d4d6c06ef2f786860cc2bcfda2fa865ab316a7ac3bb5df1efcab8a0ccc0d1ee76ceeb850f52539fd639b8af8115679cf2c1aab0c0055f6ffab7672f70bc8b8d
7
- data.tar.gz: ff9a0c9c986f804c092ef471f8b3f2ef85831c6f6c962b945b76af901783a7d63bf86fc8b6af26d14c7da23f70ec3069432cfaa0cb515adbbaae10b508301f6a
6
+ metadata.gz: b2533124cc5c0788c7bfdc368d0fac47a84209ec2a4c9953650e96f3d07be9d33fcefdfd5c775be4c9c6c2ef8bc55cb2f91142fdefddbaa4b82a24922e242f0e
7
+ data.tar.gz: 577e5597e564440d9cd59e750a88f418a03a2d632def2b5cba3f2f2b7229a6b36c43e1b04f0328dc31e23b0681c798ff0a716cf9b5fc317e7c0c5ec011c4efc3
data/lib/telegram/bot.rb CHANGED
@@ -9,6 +9,7 @@ require 'telegram/bot/types'
9
9
  require 'telegram/bot/client'
10
10
  require 'telegram/bot/client_accessors'
11
11
  require 'telegram/bot/botan'
12
+ require 'telegram/bot/login'
12
13
 
13
14
  module Telegram
14
15
  module Bot
@@ -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 Exceptions::ResponseError.new(body['description'])
239
+ raise Telegram::Bot::ResponseError.new(body['description'])
240
240
  end
241
241
 
242
242
  if type_obj.nil?
@@ -16,7 +16,7 @@ module Telegram::Bot
16
16
 
17
17
  JSON.parse(response.body)
18
18
  rescue => e
19
- raise Telegram::Bot::Exceptions::BotanError.new(e.message)
19
+ raise Telegram::Bot::BotanError.new(e.message)
20
20
  end
21
21
  end
22
22
  end
@@ -45,7 +45,7 @@ module Telegram::Bot
45
45
  end
46
46
  end
47
47
 
48
- raise Exceptions::ParseError.new('Can not parse request') unless @message
48
+ raise Telegram::Bot::ParseError.new('Can not parse request') unless @message
49
49
  end
50
50
 
51
51
  def pull_command(text)
@@ -1,15 +1,15 @@
1
1
  module Telegram
2
2
  module Bot
3
- module Exceptions
4
- class Error < StandardError; end
3
+ class Error < StandardError; end
5
4
 
6
- class ResponseError < Error; end
5
+ class ResponseError < Error; end
7
6
 
8
- class ParseError < Error; end
7
+ class ParseError < Error; end
9
8
 
10
- class KeyboardMarkupError < Error; end
9
+ class KeyboardMarkupError < Error; end
11
10
 
12
- class BotanError < Error; end
13
- end
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::Exceptions::KeyboardMarkupError
14
- .new('Attributes must be Array of Array of Telegram::Bot::Types::InlineKeyboardButton or Hash')
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::Exceptions::KeyboardMarkupError
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
@@ -1,3 +1,3 @@
1
1
  module Telegram
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
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.2.1
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-05 00:00:00.000000000 Z
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