telegram_bot 0.0.7 → 0.0.8

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: 46b3af1c9c15bfd7fee3afb047af8491f0438be7
4
- data.tar.gz: c15932937abf729352f39858151060e15ce45cc7
3
+ metadata.gz: 49e3b9501a8d3c9bf71a3d52946c261c84876946
4
+ data.tar.gz: 0d23a35d5be8af63cdde2f76764373853f53d5c8
5
5
  SHA512:
6
- metadata.gz: c1877d5b81089d6a5e705455a05ec575972e564f495052124b944a296423ae73fad55457a1e3232dcce385de26a75d83be6fecefc789444d057526a954413bfd
7
- data.tar.gz: efc71998e43116e210bad3e50fb630c86697f470451dfed1213fbb41ea56da160c4c827ba43666811c59d4fbd33faff622e04b6735757f74da00ba0847f0bb74
6
+ metadata.gz: 7e094fd6c4bff2b12cc9aa2d8a6c9db49941d8cc333c4a60b5a66e7e84973d95cc8e01391759738a8d5af88f913b1bde4463bca4c218a78530edb3f4a7705308
7
+ data.tar.gz: 3d3f0ec72ac66d62c661234a24c65fd8d0eb19b20db3debb4d20b1157eaaab47dada05aedce3e6c3c0dbc30bedc6edd69561f83c63cbd5472d9c55ab1148127f
@@ -0,0 +1 @@
1
+ ruby 2.4.3
data/Rakefile CHANGED
@@ -1,2 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:spec) do |t|
5
+ t.libs = %w(lib spec)
6
+ t.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+
9
+ task :default => :spec
2
10
 
@@ -1,6 +1,6 @@
1
1
  module TelegramBot
2
2
  class ApiResponse
3
- attr_reader :body, :ok, :result, :description, :error_code
3
+ attr_reader :body, :ok, :result
4
4
 
5
5
  def initialize(res)
6
6
  @body = res.body
@@ -9,10 +9,9 @@ module TelegramBot
9
9
  @ok = data["ok"]
10
10
  @result = data["result"]
11
11
  else
12
- data = JSON.parse(body)
13
12
  @ok = false
14
- @description = data["description"]
15
- @error_code = data["error_code"]
13
+ error = ResponseError.new(res)
14
+ fail error, "An error has occurred: #{error.data}", caller
16
15
  end
17
16
  end
18
17
 
@@ -40,11 +40,24 @@ module TelegramBot
40
40
  end
41
41
 
42
42
  def send_message(out_message)
43
- response = request(:sendMessage, out_message.to_h)
44
43
  logger.info "sending message: #{out_message.text.inspect} to #{out_message.chat_friendly_name}"
44
+ response = request(:sendMessage, out_message.to_h)
45
45
  Message.new(response.result)
46
46
  end
47
47
 
48
+ def set_webhook(url, allowed_updates: %i(message))
49
+ logger.info "setting webhook url to #{url}, allowed_updates: #{allowed_updates}"
50
+ settings = {
51
+ url: url,
52
+ allowed_updates: allowed_updates.map(&:to_s),
53
+ }
54
+ request(:setWebhook, settings)
55
+ end
56
+
57
+ def remove_webhook
58
+ set_webhook("")
59
+ end
60
+
48
61
  private
49
62
  attr_reader :token
50
63
  attr_reader :logger
@@ -0,0 +1,17 @@
1
+ module TelegramBot
2
+ class ResponseError < StandardError
3
+ attr_reader :response
4
+
5
+ def initialize(res)
6
+ @response = res
7
+ end
8
+
9
+ def data
10
+ @data ||= begin
11
+ JSON.parse(response.body)
12
+ rescue JSON::ParserError
13
+ { error_code: response.status, error_message: response.reason_phrase }
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module TelegramBot
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -0,0 +1,2 @@
1
+ require 'telegram_bot'
2
+ require 'minitest/autorun'
@@ -0,0 +1,4 @@
1
+ require 'minitest_helper'
2
+
3
+ describe TelegramBot do
4
+ end
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency "virtus", ">= 1.0.0"
23
23
  spec.add_development_dependency "bundler", "~> 1.7"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest", "~> 5.10"
25
26
  end
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.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Tomás Albornoz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-13 00:00:00.000000000 Z
11
+ date: 2018-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.10'
69
83
  description: Still in development. Simple client for Telegram's Bot API
70
84
  email:
71
85
  - jojo@eljojo.net
@@ -74,6 +88,7 @@ extensions: []
74
88
  extra_rdoc_files: []
75
89
  files:
76
90
  - ".gitignore"
91
+ - ".tool-versions"
77
92
  - CODE_OF_CONDUCT.md
78
93
  - Gemfile
79
94
  - LICENSE.txt
@@ -94,9 +109,12 @@ files:
94
109
  - lib/telegram_bot/out_message.rb
95
110
  - lib/telegram_bot/reply_keyboard_hide.rb
96
111
  - lib/telegram_bot/reply_keyboard_markup.rb
112
+ - lib/telegram_bot/response_error.rb
97
113
  - lib/telegram_bot/update.rb
98
114
  - lib/telegram_bot/user.rb
99
115
  - lib/telegram_bot/version.rb
116
+ - spec/minitest_helper.rb
117
+ - spec/telegram_bot_spec.rb
100
118
  - telegram_bot.gemspec
101
119
  homepage: https://github.com/eljojo/telegram_bot
102
120
  licenses:
@@ -118,8 +136,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
136
  version: '0'
119
137
  requirements: []
120
138
  rubyforge_project:
121
- rubygems_version: 2.5.1
139
+ rubygems_version: 2.6.14
122
140
  signing_key:
123
141
  specification_version: 4
124
142
  summary: Simple client for Telegram's Bot API
125
- test_files: []
143
+ test_files:
144
+ - spec/minitest_helper.rb
145
+ - spec/telegram_bot_spec.rb