telegram-bot 0.15.4 → 0.15.6

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: ce64ac3361d5b02948e28ddef05bdc084ea6f6681889bda5ccd2d77e544f3a91
4
- data.tar.gz: 02f9adbc5cb3fc0af167c7f55c7bf716a9fef3f88706339be9948e50c410d11a
3
+ metadata.gz: 557dd6660b57db212a311ed47dc449c833dd2020fc51d13110bf95ecbc28f0b9
4
+ data.tar.gz: b3dc3085d49456ce58931e4101b90b9a35d8853e09b0b0f398e772f6885b1e5a
5
5
  SHA512:
6
- metadata.gz: 9b85de3de3da3f5adea3412a1642f6dbe831ed3b79d6a228eddf210c3ba6228396b9e9c69513848331d0a04261a6623487e7b1db8b5268aced95f18624225e49
7
- data.tar.gz: 396074577bc0bbe7f7bb189408ec5134d66a44629928a95bd0fa60ec43474be60bb110f778d4de65d3d96ce4ffedd50436c88219df1198928bc4655a4c014143
6
+ metadata.gz: b1c07f86462d5c98528480ef526b0c14b0a94b66aa2e9b61b556bbf7ddd573a8db0b8a94149562ad481ccb802b975671f7eccc4ec6dba7b2ff98aaea21946b3a
7
+ data.tar.gz: 738791f83acc89dee90a860d6dec91a8d340bf66cebdce8411c0bfe70c1de0ce2c90f0eeaac7dfaf7a930c6e1e50d158a39e75223a3bd0edacda8466c2ec0486
data/Appraisals CHANGED
@@ -1,3 +1,8 @@
1
+ appraise 'rails-70' do
2
+ gem 'actionpack', '~> 7.0.0'
3
+ gem 'railties', '~> 7.0.0'
4
+ end
5
+
1
6
  appraise 'rails-61' do
2
7
  gem 'actionpack', '~> 6.1.0'
3
8
  gem 'railties', '~> 6.1.0'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Unreleased
2
2
 
3
+ # 0.15.6
4
+
5
+ - Rails 7.0 support.
6
+ - Fix sending File objects in nested objects in sendMediaGroup.
7
+ - Update to Bot API 5.7
8
+
3
9
  # 0.15.4
4
10
 
5
11
  - Update to Bot API 5.3
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/telegram-bot.svg)](http://badge.fury.io/rb/telegram-bot)
4
4
  [![Code Climate](https://codeclimate.com/github/telegram-bot-rb/telegram-bot/badges/gpa.svg)](https://codeclimate.com/github/telegram-bot-rb/telegram-bot)
5
- [![Build Status](https://travis-ci.com/telegram-bot-rb/telegram-bot.svg)](https://travis-ci.com/telegram-bot-rb/telegram-bot)
5
+ [![Build Status](https://app.travis-ci.com/telegram-bot-rb/telegram-bot.svg)](https://app.travis-ci.com/github/telegram-bot-rb/telegram-bot)
6
6
 
7
7
  Tools for developing Telegram bots. Best used with Rails, but can be used in
8
8
  [standalone app](https://github.com/telegram-bot-rb/telegram-bot/wiki/Not-rails-application).
@@ -539,7 +539,7 @@ end
539
539
 
540
540
  There is a context for testing bot controller in the way similar to Rails controller tests.
541
541
  It's supposed to be a low-level alternative for integration tests. Among the differences is
542
- that controller tests use a single controller instance for all dispatches in specific exaple,
542
+ that controller tests use a single controller instance for all dispatches in specific example,
543
543
  session is stubbed (does not use configured store engine), and update is not serialized
544
544
  so it also supports mocks. This can be useful for unit testing, but should not be used as
545
545
  the default way to test the bot.
@@ -10,7 +10,7 @@ group :development do
10
10
  gem "pry", "~> 0.13.1"
11
11
  gem "pry-byebug", "~> 3.9.0"
12
12
  gem "sdoc", "~> 2.0.3"
13
- gem "telegram-bot-types", "~> 0.6.2"
13
+ gem "telegram-bot-types", "~> 0.6.3"
14
14
  gem "rspec", "~> 3.10.0"
15
15
  gem "rspec-its", "~> 1.3.0"
16
16
  gem "rspec-rails", "~> 4.0.2"
@@ -10,7 +10,7 @@ group :development do
10
10
  gem "pry", "~> 0.13.1"
11
11
  gem "pry-byebug", "~> 3.9.0"
12
12
  gem "sdoc", "~> 2.0.3"
13
- gem "telegram-bot-types", "~> 0.6.2"
13
+ gem "telegram-bot-types", "~> 0.6.3"
14
14
  gem "rspec", "~> 3.10.0"
15
15
  gem "rspec-its", "~> 1.3.0"
16
16
  gem "rspec-rails", "~> 4.0.2"
@@ -10,7 +10,7 @@ group :development do
10
10
  gem "pry", "~> 0.13.1"
11
11
  gem "pry-byebug", "~> 3.9.0"
12
12
  gem "sdoc", "~> 2.0.3"
13
- gem "telegram-bot-types", "~> 0.6.2"
13
+ gem "telegram-bot-types", "~> 0.6.3"
14
14
  gem "rspec", "~> 3.10.0"
15
15
  gem "rspec-its", "~> 1.3.0"
16
16
  gem "rspec-rails", "~> 4.0.2"
@@ -10,7 +10,7 @@ group :development do
10
10
  gem "pry", "~> 0.13.1"
11
11
  gem "pry-byebug", "~> 3.9.0"
12
12
  gem "sdoc", "~> 2.0.3"
13
- gem "telegram-bot-types", "~> 0.6.2"
13
+ gem "telegram-bot-types", "~> 0.6.3"
14
14
  gem "rspec", "~> 3.10.0"
15
15
  gem "rspec-its", "~> 1.3.0"
16
16
  gem "rspec-rails", "~> 4.0.2"
@@ -10,7 +10,7 @@ group :development do
10
10
  gem "pry", "~> 0.13.1"
11
11
  gem "pry-byebug", "~> 3.9.0"
12
12
  gem "sdoc", "~> 2.0.3"
13
- gem "telegram-bot-types", "~> 0.6.2"
13
+ gem "telegram-bot-types", "~> 0.6.3"
14
14
  gem "rspec", "~> 3.10.0"
15
15
  gem "rspec-its", "~> 1.3.0"
16
16
  gem "rspec-rails", "~> 4.0.2"
@@ -10,7 +10,7 @@ group :development do
10
10
  gem "pry", "~> 0.13.1"
11
11
  gem "pry-byebug", "~> 3.9.0"
12
12
  gem "sdoc", "~> 2.0.3"
13
- gem "telegram-bot-types", "~> 0.6.2"
13
+ gem "telegram-bot-types", "~> 0.6.3"
14
14
  gem "rspec", "~> 3.10.0"
15
15
  gem "rspec-its", "~> 1.3.0"
16
16
  gem "rspec-rails", "~> 4.0.2"
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "actionpack", "~> 7.0.0"
6
+ gem "railties", "~> 7.0.0"
7
+
8
+ group :development do
9
+ gem "appraisal", "~> 2.2"
10
+ gem "pry", "~> 0.13.1"
11
+ gem "pry-byebug", "~> 3.9.0"
12
+ gem "sdoc", "~> 2.0.3"
13
+ gem "telegram-bot-types", "~> 0.6.3"
14
+ gem "rspec", "~> 3.10.0"
15
+ gem "rspec-its", "~> 1.3.0"
16
+ gem "rspec-rails", "~> 4.0.2"
17
+ gem "rubocop", "~> 0.52.1"
18
+ gem "coveralls", "~> 0.8.23", require: false
19
+ end
20
+
21
+ gemspec path: "../"
@@ -1,5 +1,5 @@
1
1
  # Generated with bin/fetch-telegram-methods
2
- # Bot API 5.3
2
+ # Bot API 5.7
3
3
 
4
4
  getUpdates
5
5
  setWebhook
@@ -35,11 +35,15 @@ unbanChatMember
35
35
  restrictChatMember
36
36
  promoteChatMember
37
37
  setChatAdministratorCustomTitle
38
+ banChatSenderChat
39
+ unbanChatSenderChat
38
40
  setChatPermissions
39
41
  exportChatInviteLink
40
42
  createChatInviteLink
41
43
  editChatInviteLink
42
44
  revokeChatInviteLink
45
+ approveChatJoinRequest
46
+ declineChatJoinRequest
43
47
  setChatPhoto
44
48
  deleteChatPhoto
45
49
  setChatTitle
@@ -0,0 +1,48 @@
1
+ require 'json'
2
+
3
+ module Telegram
4
+ module Bot
5
+ class Client
6
+ # Encodes nested hashes and arrays as json and extract File objects from them
7
+ # to the top level. Top-level File objects are handled by httpclient.
8
+ # More details: https://core.telegram.org/bots/api#sending-files
9
+ module RequestBodyFormatter
10
+ extend self
11
+
12
+ def format(body, action)
13
+ body = body.dup
14
+ if action.to_s == 'sendMediaGroup'
15
+ body = extract_files_from_array!(body, :media)
16
+ end
17
+ body.each do |key, val|
18
+ body[key] = val.to_json if val.is_a?(Hash) || val.is_a?(Array)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def extract_files_from_array!(body, field_name)
25
+ field_name = [field_name.to_sym, field_name.to_s].find { |x| body.key?(x) }
26
+ return body unless field_name && body[field_name].is_a?(Array)
27
+ files = {}
28
+ body[field_name] = body[field_name].map { |x| extract_files_from_hash(x, files) }
29
+ body.merge!(files)
30
+ end
31
+
32
+ # Replace File objects with `attach` URIs. File objects are added into `files` hash.
33
+ def extract_files_from_hash(hash, files)
34
+ return hash unless hash.is_a?(Hash)
35
+ hash.transform_values do |value|
36
+ if value.is_a?(File)
37
+ arg_name = "_file#{files.size}"
38
+ files[arg_name] = value
39
+ "attach://#{arg_name}"
40
+ else
41
+ value
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,5 +1,4 @@
1
1
  require 'active_support/core_ext/hash/keys'
2
- require 'json'
3
2
  require 'httpclient'
4
3
 
5
4
  module Telegram
@@ -8,7 +7,9 @@ module Telegram
8
7
  SERVER = 'https://api.telegram.org'.freeze
9
8
  URL_TEMPLATE = '%<server>s/bot%<token>s/'.freeze
10
9
 
10
+ autoload :RequestBodyFormatter, 'telegram/bot/client/request_body_formatter'
11
11
  autoload :TypedResponse, 'telegram/bot/client/typed_response'
12
+
12
13
  prepend Async
13
14
  include DebugClient
14
15
 
@@ -35,16 +36,8 @@ module Telegram
35
36
  prepend TypedResponse
36
37
  end
37
38
 
38
- # Encodes nested hashes as json.
39
- def prepare_body(body)
40
- body = body.dup
41
- body.each do |k, val|
42
- body[k] = val.to_json if val.is_a?(Hash) || val.is_a?(Array)
43
- end
44
- end
45
-
46
39
  def prepare_async_args(action, body = {})
47
- [action.to_s, Async.prepare_hash(prepare_body(body))]
40
+ [action.to_s, Async.prepare_hash(RequestBodyFormatter.format(body, action))]
48
41
  end
49
42
 
50
43
  def error_for_response(response)
@@ -70,7 +63,7 @@ module Telegram
70
63
  end
71
64
 
72
65
  def request(action, body = {})
73
- response = http_request("#{base_uri}#{action}", self.class.prepare_body(body))
66
+ response = http_request("#{base_uri}#{action}", RequestBodyFormatter.format(body, action))
74
67
  raise self.class.error_for_response(response) if response.status >= 300
75
68
  JSON.parse(response.body)
76
69
  end
@@ -1,6 +1,6 @@
1
1
  module Telegram
2
2
  module Bot
3
- VERSION = '0.15.4'.freeze
3
+ VERSION = '0.15.6'.freeze
4
4
 
5
5
  def self.gem_version
6
6
  Gem::Version.new VERSION
data/telegram-bot.gemspec CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.required_ruby_version = '>= 2.4'
21
21
 
22
- spec.add_dependency 'actionpack', '>= 4.0', '< 6.2'
23
- spec.add_dependency 'activesupport', '>= 4.0', '< 6.2'
22
+ spec.add_dependency 'actionpack', '>= 4.0', '< 7.1'
23
+ spec.add_dependency 'activesupport', '>= 4.0', '< 7.1'
24
24
  spec.add_dependency 'httpclient', '~> 2.7'
25
25
 
26
26
  spec.add_development_dependency 'bundler', '> 1.16'
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.15.4
4
+ version: 0.15.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Melentiev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-25 00:00:00.000000000 Z
11
+ date: 2022-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '4.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6.2'
22
+ version: '7.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '4.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.2'
32
+ version: '7.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: activesupport
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: '4.0'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '6.2'
42
+ version: '7.1'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,7 +49,7 @@ dependencies:
49
49
  version: '4.0'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '6.2'
52
+ version: '7.1'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: httpclient
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -121,12 +121,14 @@ files:
121
121
  - gemfiles/rails_52.gemfile
122
122
  - gemfiles/rails_60.gemfile
123
123
  - gemfiles/rails_61.gemfile
124
+ - gemfiles/rails_70.gemfile
124
125
  - lib/tasks/telegram-bot.rake
125
126
  - lib/telegram/bot.rb
126
127
  - lib/telegram/bot/async.rb
127
128
  - lib/telegram/bot/client.rb
128
129
  - lib/telegram/bot/client/api_helper.rb
129
130
  - lib/telegram/bot/client/api_methods.txt
131
+ - lib/telegram/bot/client/request_body_formatter.rb
130
132
  - lib/telegram/bot/client/typed_response.rb
131
133
  - lib/telegram/bot/client_stub.rb
132
134
  - lib/telegram/bot/config_methods.rb
@@ -178,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
180
  - !ruby/object:Gem::Version
179
181
  version: '0'
180
182
  requirements: []
181
- rubygems_version: 3.1.4
183
+ rubygems_version: 3.2.3
182
184
  signing_key:
183
185
  specification_version: 4
184
186
  summary: Library for building Telegram Bots with Rails integration