telegram-bot 0.10.2 → 0.11.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
  SHA1:
3
- metadata.gz: be687b63c630f76cc65ca33e41da8314503ca12f
4
- data.tar.gz: 97a72626bb37dbdd7c60a733391e80d234980280
3
+ metadata.gz: 6965124480bcaf8247399876641d9f7a27380592
4
+ data.tar.gz: 4ac406cca75f4c864a07b0b98eca019aa4c39f9b
5
5
  SHA512:
6
- metadata.gz: 47dc2b51b69704ac5ab9f9638ea0419c714597387f2dece46409c6d57e35dd0ff12df09f2c5c72a76ffb23c7a30e251406b0f41d83d9a0c545599174c41b1e19
7
- data.tar.gz: e6c1fbd85e95a560c28175129329bd3565aa0957df803cbe2efbafabdd70fcd381c4f20ce23c9eadf988620d841d8bae23991bbb93f0d89edc593f0f895ee20c
6
+ metadata.gz: 5c9cf79f27c144401dacd15cd59047ccf9a695070eca66b08537246f9aa061bb81bfb05954e8d720b84f9cd40b3bf30f40dfd43e75da8a49e76ae6bd4b4851f6
7
+ data.tar.gz: 0262b407a6c583eeeff2fb3d3ef011d709bb1eba8f788b3cf80cb95a769e8d25deec7fcd9ce83d5404e4131188b76a39e014204ba257fdb790e3d4646e1f3a82
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.11.0
2
+
3
+ - Remove Bot::StaleChat in favor of Bot::Forbidden, as Telegram adds more
4
+ and more new descriptions.
5
+ Please open an issue if you face a problem.
6
+
1
7
  # 0.10.2
2
8
 
3
9
  - Support `(edited_)channel_post` updates.
data/README.md CHANGED
@@ -100,7 +100,7 @@ bot.get_me.class # => Telegram::Bot::Types::User
100
100
  ```
101
101
 
102
102
  Any API request error will raise `Telegram::Bot::Error` with description in its message.
103
- Special `Telegram::Bot::StaleChat` is raised when bot can't post messages to the chat anymore.
103
+ Special `Telegram::Bot::Forbidden` is raised when bot can't post messages to the chat anymore.
104
104
 
105
105
  ### Controller
106
106
 
data/lib/telegram/bot.rb CHANGED
@@ -6,26 +6,7 @@ module Telegram
6
6
  module Bot
7
7
  class Error < StandardError; end
8
8
  class NotFound < Error; end
9
-
10
- # Error class for events when chat is not available anymore for bot.
11
- # While Telegram has same error codes for different messages and there is no
12
- # official docs for this error codes it uses `description` to
13
- # check response.
14
- class StaleChat < Error
15
- DESCRIPTIONS = [
16
- 'Bot was blocked',
17
- 'bot was kicked',
18
- "can't write to",
19
- 'group chat is deactivated',
20
- ].freeze
21
-
22
- class << self
23
- def match_response?(response)
24
- description = response['description'].to_s
25
- DESCRIPTIONS.any? { |x| description[x] }
26
- end
27
- end
28
- end
9
+ class Forbidden < Error; end
29
10
 
30
11
  autoload :Async, 'telegram/bot/async'
31
12
  autoload :Botan, 'telegram/bot/botan'
@@ -46,18 +46,20 @@ module Telegram
46
46
  @base_uri = format URL_TEMPLATE, self.token
47
47
  end
48
48
 
49
- def request(action, body = {}) # rubocop:disable PerceivedComplexity
49
+ def request(action, body = {})
50
50
  res = http_request("#{base_uri}#{action}", self.class.prepare_body(body))
51
51
  status = res.status
52
52
  return JSON.parse(res.body) if 300 > status
53
53
  result = JSON.parse(res.body) rescue nil # rubocop:disable RescueModifier
54
- err_msg = "#{res.reason}: #{result && result['description'] || '-'}"
54
+ err_msg = result && result['description'] || '-'
55
55
  if result
56
- # NotFound is raised only for valid responses from Telegram
57
- raise NotFound, err_msg if 404 == status
58
- raise StaleChat, err_msg if StaleChat.match_response?(result)
56
+ # This errors are raised only for valid responses from Telegram
57
+ case status
58
+ when 403 then raise Forbidden, err_msg
59
+ when 404 then raise NotFound, err_msg
60
+ end
59
61
  end
60
- raise Error, err_msg
62
+ raise Error, "#{res.reason}: #{err_msg}"
61
63
  end
62
64
 
63
65
  # Splited to the sections similar to API docs.
@@ -1,6 +1,6 @@
1
1
  module Telegram
2
2
  module Bot
3
- VERSION = '0.10.2'.freeze
3
+ VERSION = '0.11.0'.freeze
4
4
 
5
5
  def self.gem_version
6
6
  Gem::Version.new VERSION
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telegram-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.2
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Melentiev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-09 00:00:00.000000000 Z
11
+ date: 2017-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
163
  version: '0'
164
164
  requirements: []
165
165
  rubyforge_project:
166
- rubygems_version: 2.5.1
166
+ rubygems_version: 2.6.8
167
167
  signing_key:
168
168
  specification_version: 4
169
169
  summary: Library for building Telegram Bots with Rails integration