telegram-bot-ruby 0.2.1 → 0.2.2

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: 1d52d14ef44cbb3583be07ce94d6a497c5fcdbe9
4
- data.tar.gz: a9e8eb1afb4a9ed07ff4a645f68f54f4978505d2
3
+ metadata.gz: 293f3e90dc90b39181a1cee27db8e817f180e83b
4
+ data.tar.gz: d0e165c9dfbcce35f2ed47c8f754bbb2fe7d9dc6
5
5
  SHA512:
6
- metadata.gz: 9f79b2bf808f6b88e2003a8eb628a88dc45d093aae9e67b05a8659de96f71d48b9f37418c09bb0eb9b0b6d20507cf0f183bedd8329a476af1e030dcd965d1b62
7
- data.tar.gz: 50db3e10ebadbd7daa4cb0f877e9453a191a1b1a5bebf8b530f16971917dea7bffa32819eb22dd67bf26899cc5a237e7e364e1b84cca34f42a7e5808c4bfa4cd
6
+ metadata.gz: f2fdd4d4105f5403781427ca4154fcfc59d13040c0041db308acfa70b45e6a3bcb41c383e8df4a7ceec44f8d1a582d3035b8cf2fcecee8c8ca3ceedca6af6e5d
7
+ data.tar.gz: 16994c1bd51b1083ae6f32bf62d9cc5eed56ec0491b35b70611cd6ea37a942b7688505a432f2129d703106767cea2f6e9c142f1cb6fe20d545685b6de92de090
data/lib/telegram/bot.rb CHANGED
@@ -3,6 +3,7 @@ require 'persistent_httparty'
3
3
  require 'virtus'
4
4
 
5
5
  require 'telegram/bot/types'
6
+ require 'telegram/bot/exceptions'
6
7
  require 'telegram/bot/api'
7
8
  require 'telegram/bot/client'
8
9
  require 'telegram/bot/version'
@@ -30,7 +30,12 @@ module Telegram
30
30
  def call(endpoint, raw_params = {})
31
31
  params = build_params(raw_params)
32
32
  response = self.class.get("/bot#{token}/#{endpoint}", query: params)
33
- response.code == 200 ? response.to_h : {}
33
+ if response.code == 200
34
+ response.to_h
35
+ else
36
+ fail Exceptions::ResponseError.new(response),
37
+ 'Telegram API has returned the error.'
38
+ end
34
39
  end
35
40
 
36
41
  private
@@ -0,0 +1,2 @@
1
+ require 'telegram/bot/exceptions/base'
2
+ require 'telegram/bot/exceptions/response_error'
@@ -0,0 +1,7 @@
1
+ module Telegram
2
+ module Bot
3
+ module Exceptions
4
+ class Base < StandardError; end
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ module Telegram
2
+ module Bot
3
+ module Exceptions
4
+ class ResponseError < Base
5
+ attr_reader :response
6
+
7
+ def initialize(response)
8
+ @response = response
9
+ end
10
+
11
+ def to_s
12
+ super +
13
+ format(' (%s)', data.map { |k, v| %(#{k}: "#{v}") }.join(', '))
14
+ end
15
+
16
+ private
17
+
18
+ def data
19
+ @data ||= begin
20
+ JSON.parse(response.body)
21
+ rescue JSON::ParserError
22
+ { error_code: response.code, uri: response.request.last_uri.to_s }
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,5 +1,5 @@
1
1
  module Telegram
2
2
  module Bot
3
- VERSION = '0.2.1'
3
+ VERSION = '0.2.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telegram-bot-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Tipugin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-29 00:00:00.000000000 Z
11
+ date: 2015-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -126,6 +126,9 @@ files:
126
126
  - lib/telegram/bot.rb
127
127
  - lib/telegram/bot/api.rb
128
128
  - lib/telegram/bot/client.rb
129
+ - lib/telegram/bot/exceptions.rb
130
+ - lib/telegram/bot/exceptions/base.rb
131
+ - lib/telegram/bot/exceptions/response_error.rb
129
132
  - lib/telegram/bot/types.rb
130
133
  - lib/telegram/bot/types/audio.rb
131
134
  - lib/telegram/bot/types/base.rb