telegram-bot 0.16.1 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +0 -4
  3. data/.github/workflows/ci.yml +9 -9
  4. data/.rubocop.yml +31 -12
  5. data/Appraisals +2 -0
  6. data/CHANGELOG.md +5 -0
  7. data/Gemfile +5 -3
  8. data/Rakefile +2 -0
  9. data/bin/console +6 -2
  10. data/bin/fetch-telegram-methods +5 -3
  11. data/bin/install_git_hooks +2 -1
  12. data/gemfiles/rails_51.gemfile +3 -3
  13. data/gemfiles/rails_52.gemfile +3 -3
  14. data/gemfiles/rails_60.gemfile +3 -3
  15. data/gemfiles/rails_61.gemfile +3 -3
  16. data/gemfiles/rails_70.gemfile +3 -3
  17. data/gemfiles/rails_71.gemfile +3 -3
  18. data/lib/tasks/telegram-bot.rake +6 -4
  19. data/lib/telegram/bot/async.rb +4 -2
  20. data/lib/telegram/bot/client/api_helper.rb +3 -1
  21. data/lib/telegram/bot/client/api_methods.txt +8 -1
  22. data/lib/telegram/bot/client/request_body_formatter.rb +2 -0
  23. data/lib/telegram/bot/client/typed_response.rb +2 -0
  24. data/lib/telegram/bot/client.rb +5 -3
  25. data/lib/telegram/bot/client_stub.rb +4 -2
  26. data/lib/telegram/bot/config_methods.rb +3 -1
  27. data/lib/telegram/bot/debug_client.rb +3 -1
  28. data/lib/telegram/bot/middleware.rb +3 -1
  29. data/lib/telegram/bot/railtie.rb +3 -1
  30. data/lib/telegram/bot/routes_helper.rb +2 -0
  31. data/lib/telegram/bot/rspec/callback_query_helpers.rb +3 -1
  32. data/lib/telegram/bot/rspec/client_matchers.rb +12 -10
  33. data/lib/telegram/bot/rspec/integration/poller.rb +2 -0
  34. data/lib/telegram/bot/rspec/integration/rack.rb +2 -0
  35. data/lib/telegram/bot/rspec/integration/rails.rb +2 -0
  36. data/lib/telegram/bot/rspec/integration/shared.rb +3 -1
  37. data/lib/telegram/bot/rspec/message_helpers.rb +2 -0
  38. data/lib/telegram/bot/rspec.rb +2 -0
  39. data/lib/telegram/bot/tasks.rb +4 -4
  40. data/lib/telegram/bot/updates_controller/callback_query_context.rb +2 -0
  41. data/lib/telegram/bot/updates_controller/commands.rb +4 -2
  42. data/lib/telegram/bot/updates_controller/instrumentation.rb +7 -5
  43. data/lib/telegram/bot/updates_controller/log_subscriber.rb +4 -2
  44. data/lib/telegram/bot/updates_controller/message_context.rb +7 -5
  45. data/lib/telegram/bot/updates_controller/reply_helpers.rb +4 -2
  46. data/lib/telegram/bot/updates_controller/rescue.rb +3 -1
  47. data/lib/telegram/bot/updates_controller/rspec_helpers.rb +2 -0
  48. data/lib/telegram/bot/updates_controller/session.rb +7 -4
  49. data/lib/telegram/bot/updates_controller/testing.rb +5 -2
  50. data/lib/telegram/bot/updates_controller/translation.rb +2 -0
  51. data/lib/telegram/bot/updates_controller/typed_update.rb +2 -0
  52. data/lib/telegram/bot/updates_controller.rb +49 -19
  53. data/lib/telegram/bot/updates_poller.rb +9 -9
  54. data/lib/telegram/bot/version.rb +3 -1
  55. data/lib/telegram/bot.rb +3 -9
  56. data/telegram-bot.gemspec +7 -1
  57. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71f0e613a4546cd530c2abf33c26521740b2210ad1a4d1fedf1fc9b46be804ef
4
- data.tar.gz: 623c0f1bfc57ce2d021be33237df291e93cde17573cbce64cf04ab53c83b14f5
3
+ metadata.gz: 61a22f62815ac892095b9a544fa1ce2cf2273f9e3c1d6bbe371b7a548e1f8762
4
+ data.tar.gz: 5b80eb16b7bd5bef68a4dcbf5a30cda40d1aaba95774930f9d78000dec3db624
5
5
  SHA512:
6
- metadata.gz: 04aefa97d17e5d67881e9be5e291464bd04c933ff53d8b9daadd43a87d30387b38c14bf97567affe4b4ec9ef9292e7402d437aa5545bd87e6d3a833212e1d223
7
- data.tar.gz: d279d8954013c7b6a2e6f7e923bef162f389751f5ce3e0672fc2ec7d9b8622c79125870fbc69043488e9d9933ef6967b2629c17c28321d786046109b18216fe6
6
+ metadata.gz: 6cbf0d110b678071dae96a0cabb0ac6142089c5482f25906a0684ba904c348300c48422c9254884025ccab214ce7487fad852b7d22ba696384937155b4030896
7
+ data.tar.gz: 54f32643648797d54ac815f989bc2902faee6ed17357e69d83fcbbfe17640ddcc3b669b83fd16e54ab72574cecccc40b03161f716340552851f017711d3bf68f
data/.codeclimate.yml CHANGED
@@ -2,7 +2,3 @@ checks:
2
2
  method-complexity:
3
3
  config:
4
4
  threshold: 6 # should be just fine
5
-
6
- plugins:
7
- rubocop:
8
- enabled: true
@@ -3,15 +3,15 @@ name: Lint & Test
3
3
  on: [push, pull_request]
4
4
 
5
5
  jobs:
6
- # lint:
7
- # runs-on: ubuntu-latest
8
- # steps:
9
- # - uses: actions/checkout@v3
10
- # - uses: ruby/setup-ruby@v1
11
- # with:
12
- # ruby-version: '3.0'
13
- # bundler-cache: true
14
- # - run: bundle exec rubocop
6
+ lint:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v3
10
+ - uses: ruby/setup-ruby@v1
11
+ with:
12
+ ruby-version: '3.2'
13
+ bundler-cache: true
14
+ - run: bundle exec rubocop
15
15
 
16
16
  test:
17
17
  runs-on: ubuntu-latest
data/.rubocop.yml CHANGED
@@ -1,15 +1,18 @@
1
- # Rubocop does not support 2.0
2
- Gemspec/RequiredRubyVersion: {Enabled: false}
1
+ require: rubocop-rails
3
2
 
4
- Rails: {Enabled: true}
3
+ AllCops:
4
+ TargetRubyVersion: 2.4
5
+ NewCops: enable
6
+ SuggestExtensions: false
7
+ Exclude:
8
+ - gemfiles/*
9
+ - tmp/*
10
+ - vendor/**/* # for github actions
5
11
 
6
- Layout/AlignParameters:
7
- # Disable, till rubocop supports combination of styles.
8
- # Use one of this styles where appropriate, keep it clean, compact and readable.
9
- Enabled: false
10
- # EnforcedStyle:
11
- # - with_first_parameter
12
- # - with_fixed_indentation
12
+ Gemspec/DevelopmentDependencies: {Enabled: false}
13
+
14
+ Layout/ArgumentAlignment: {EnforcedStyle: with_fixed_indentation}
15
+ Layout/ParameterAlignment: {EnforcedStyle: with_fixed_indentation}
13
16
 
14
17
  # Breaks
15
18
  #
@@ -19,7 +22,11 @@ Layout/AlignParameters:
19
22
  # )
20
23
  Layout/ClosingParenthesisIndentation: {Enabled: false}
21
24
  Layout/DotPosition: {EnforcedStyle: trailing}
25
+ Layout/EmptyLineAfterGuardClause: {Enabled: false}
22
26
  Layout/FirstParameterIndentation: {EnforcedStyle: consistent}
27
+ Layout/LineContinuationLeadingSpace: {Enabled: false}
28
+ Layout/LineEndStringConcatenationIndentation: {EnforcedStyle: indented}
29
+ Layout/LineLength: {Max: 100}
23
30
  # Same as Layout/ClosingParenthesisIndentation
24
31
  Layout/MultilineMethodCallBraceLayout: {Enabled: false}
25
32
  Layout/MultilineMethodCallIndentation: {EnforcedStyle: indented}
@@ -28,8 +35,16 @@ Layout/SpaceInsideHashLiteralBraces: {EnforcedStyle: no_space}
28
35
 
29
36
  # Offences named scopes and `expect {}.to change {}`.
30
37
  Lint/AmbiguousBlockAssociation: {Enabled: false}
38
+ Lint/EmptyBlock:
39
+ Exclude:
40
+ - spec/**/*
31
41
 
42
+ Naming/FileName:
43
+ Exclude:
44
+ - lib/tasks/telegram-bot.rake
45
+ Naming/MethodParameterName: {MinNameLength: 2}
32
46
  Naming/PredicateName: {Enabled: false}
47
+ Naming/RescuedExceptionsVariableName: {PreferredName: exception}
33
48
  Naming/VariableNumber: {EnforcedStyle: snake_case}
34
49
 
35
50
  Style/Alias: {Enabled: false}
@@ -45,12 +60,16 @@ Style/ModuleFunction: {Enabled: false}
45
60
  Style/NestedParenthesizedCalls: {Enabled: false}
46
61
  Style/SignalException: {EnforcedStyle: only_raise}
47
62
  Style/TrailingCommaInArguments: {Enabled: false}
48
- Style/TrailingCommaInLiteral: {EnforcedStyleForMultiline: comma}
63
+ Style/TrailingCommaInArrayLiteral: {EnforcedStyleForMultiline: comma}
64
+ Style/TrailingCommaInHashLiteral: {EnforcedStyleForMultiline: comma}
49
65
 
50
66
  Metrics/AbcSize: {Max: 21}
51
67
  # Other metrics are just enough.
52
68
  # This one offences all specs, routes and some initializers.
53
69
  Metrics/BlockLength: {Enabled: false}
54
- Metrics/LineLength: {Max: 100}
55
70
  Metrics/MethodLength: {Max: 30}
56
71
  Metrics/CyclomaticComplexity: {Max: 8}
72
+
73
+ Rails/IndexWith: {Enabled: false}
74
+ Rails/RakeEnvironment: {Enabled: false}
75
+ Rails/ShortI18n: {Enabled: false}
data/Appraisals CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  appraise 'rails-71' do
2
4
  gem 'actionpack', '~> 7.1.0'
3
5
  gem 'railties', '~> 7.1.0'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Unreleased
2
2
 
3
+ # 0.16.2
4
+
5
+ - Update to Bot API 7.3
6
+ - Add `# frozen_string_literal: true` to all source files.
7
+
3
8
  # 0.16.1
4
9
 
5
10
  - Fix logger in poller mode in rails 7.1
data/Gemfile CHANGED
@@ -1,11 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
  gemspec
3
5
 
4
6
  group :development do
5
7
  gem 'appraisal', '~> 2.2'
6
8
 
7
- gem 'pry', '~> 0.14.1'
8
- gem 'pry-byebug', '~> 3.10.1'
9
+ gem 'debug', '~> 1.9.2'
9
10
  gem 'sdoc', '~> 2.0.3'
10
11
 
11
12
  gem 'telegram-bot-types', '~> 0.6.3'
@@ -14,7 +15,8 @@ group :development do
14
15
  gem 'rspec-its', '~> 1.3.0'
15
16
  gem 'rspec-rails', '~> 4.0.2'
16
17
 
17
- gem 'rubocop', '~> 0.52.1'
18
+ gem 'rubocop', '~> 1.59.0'
19
+ gem 'rubocop-rails', '~> 2.23.1'
18
20
 
19
21
  gem 'coveralls', '~> 0.8.23', require: false
20
22
  end
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
data/bin/console CHANGED
@@ -1,7 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'telegram/bot'
5
6
 
6
- require 'pry'
7
- Pry.start
7
+ require 'irb'
8
+ require 'irb/completion'
9
+
10
+ IRB.setup(nil)
11
+ IRB::Irb.new.run(IRB.conf)
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  # Fetch list of methods from Telegram docs.
4
6
  # Use it to update client.rb.
@@ -6,7 +8,7 @@
6
8
  require 'net/http'
7
9
  require 'nokogiri'
8
10
 
9
- DOCS_URL = 'https://core.telegram.org/bots/api'.freeze
11
+ DOCS_URL = 'https://core.telegram.org/bots/api'
10
12
 
11
13
  page_html = Net::HTTP.get(URI(DOCS_URL))
12
14
  doc = Nokogiri::HTML(page_html)
@@ -18,11 +20,11 @@ headers = doc.css('h3, h4').
18
20
  map { |g| g.map(&:text) }
19
21
 
20
22
  # Method starts with lowercase and does not have spaces.
21
- NOT_METHOD_REGEXP = /(\A[^a-z])|\s/
23
+ NOT_METHOD_REGEXP = /(\A[^a-z])|\s/.freeze
22
24
 
23
25
  # Filter method names.
24
26
  method_list = headers.
25
- map { |g| g.reject { |x| x.match?(NOT_METHOD_REGEXP) } }.
27
+ map { |g| g.grep_v(NOT_METHOD_REGEXP) }.
26
28
  reject(&:empty?)
27
29
 
28
30
  api_version = doc.text.match(/^(?:Introducing )?(Bot API ([\d\.]+))\.?$/)
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- root = File.expand_path('../../', __FILE__)
4
+ root = File.expand_path('..', __dir__)
4
5
  hooks_dir = "#{root}/bin/git-hooks"
5
6
 
6
7
  `ls -1 #{hooks_dir}`.each_line.map(&:strip).each do |file|
@@ -7,14 +7,14 @@ gem "railties", "~> 5.1.0"
7
7
 
8
8
  group :development do
9
9
  gem "appraisal", "~> 2.2"
10
- gem "pry", "~> 0.14.1"
11
- gem "pry-byebug", "~> 3.10.1"
10
+ gem "debug", "~> 1.9.2"
12
11
  gem "sdoc", "~> 2.0.3"
13
12
  gem "telegram-bot-types", "~> 0.6.3"
14
13
  gem "rspec", "~> 3.12.0"
15
14
  gem "rspec-its", "~> 1.3.0"
16
15
  gem "rspec-rails", "~> 4.0.2"
17
- gem "rubocop", "~> 0.52.1"
16
+ gem "rubocop", "~> 1.59.0"
17
+ gem "rubocop-rails", "~> 2.23.1"
18
18
  gem "coveralls", "~> 0.8.23", require: false
19
19
  end
20
20
 
@@ -7,14 +7,14 @@ gem "railties", "~> 5.2.0"
7
7
 
8
8
  group :development do
9
9
  gem "appraisal", "~> 2.2"
10
- gem "pry", "~> 0.14.1"
11
- gem "pry-byebug", "~> 3.10.1"
10
+ gem "debug", "~> 1.9.2"
12
11
  gem "sdoc", "~> 2.0.3"
13
12
  gem "telegram-bot-types", "~> 0.6.3"
14
13
  gem "rspec", "~> 3.12.0"
15
14
  gem "rspec-its", "~> 1.3.0"
16
15
  gem "rspec-rails", "~> 4.0.2"
17
- gem "rubocop", "~> 0.52.1"
16
+ gem "rubocop", "~> 1.59.0"
17
+ gem "rubocop-rails", "~> 2.23.1"
18
18
  gem "coveralls", "~> 0.8.23", require: false
19
19
  end
20
20
 
@@ -7,14 +7,14 @@ gem "railties", "~> 6.0.0"
7
7
 
8
8
  group :development do
9
9
  gem "appraisal", "~> 2.2"
10
- gem "pry", "~> 0.14.1"
11
- gem "pry-byebug", "~> 3.10.1"
10
+ gem "debug", "~> 1.9.2"
12
11
  gem "sdoc", "~> 2.0.3"
13
12
  gem "telegram-bot-types", "~> 0.6.3"
14
13
  gem "rspec", "~> 3.12.0"
15
14
  gem "rspec-its", "~> 1.3.0"
16
15
  gem "rspec-rails", "~> 4.0.2"
17
- gem "rubocop", "~> 0.52.1"
16
+ gem "rubocop", "~> 1.59.0"
17
+ gem "rubocop-rails", "~> 2.23.1"
18
18
  gem "coveralls", "~> 0.8.23", require: false
19
19
  end
20
20
 
@@ -7,14 +7,14 @@ gem "railties", "~> 6.1.0"
7
7
 
8
8
  group :development do
9
9
  gem "appraisal", "~> 2.2"
10
- gem "pry", "~> 0.14.1"
11
- gem "pry-byebug", "~> 3.10.1"
10
+ gem "debug", "~> 1.9.2"
12
11
  gem "sdoc", "~> 2.0.3"
13
12
  gem "telegram-bot-types", "~> 0.6.3"
14
13
  gem "rspec", "~> 3.12.0"
15
14
  gem "rspec-its", "~> 1.3.0"
16
15
  gem "rspec-rails", "~> 4.0.2"
17
- gem "rubocop", "~> 0.52.1"
16
+ gem "rubocop", "~> 1.59.0"
17
+ gem "rubocop-rails", "~> 2.23.1"
18
18
  gem "coveralls", "~> 0.8.23", require: false
19
19
  end
20
20
 
@@ -7,14 +7,14 @@ gem "railties", "~> 7.0.0"
7
7
 
8
8
  group :development do
9
9
  gem "appraisal", "~> 2.2"
10
- gem "pry", "~> 0.14.1"
11
- gem "pry-byebug", "~> 3.10.1"
10
+ gem "debug", "~> 1.9.2"
12
11
  gem "sdoc", "~> 2.0.3"
13
12
  gem "telegram-bot-types", "~> 0.6.3"
14
13
  gem "rspec", "~> 3.12.0"
15
14
  gem "rspec-its", "~> 1.3.0"
16
15
  gem "rspec-rails", "~> 4.0.2"
17
- gem "rubocop", "~> 0.52.1"
16
+ gem "rubocop", "~> 1.59.0"
17
+ gem "rubocop-rails", "~> 2.23.1"
18
18
  gem "coveralls", "~> 0.8.23", require: false
19
19
  end
20
20
 
@@ -7,14 +7,14 @@ gem "railties", "~> 7.1.0"
7
7
 
8
8
  group :development do
9
9
  gem "appraisal", "~> 2.2"
10
- gem "pry", "~> 0.14.1"
11
- gem "pry-byebug", "~> 3.10.1"
10
+ gem "debug", "~> 1.9.2"
12
11
  gem "sdoc", "~> 2.0.3"
13
12
  gem "telegram-bot-types", "~> 0.6.3"
14
13
  gem "rspec", "~> 3.12.0"
15
14
  gem "rspec-its", "~> 1.3.0"
16
15
  gem "rspec-rails", "~> 4.0.2"
17
- gem "rubocop", "~> 0.52.1"
16
+ gem "rubocop", "~> 1.59.0"
17
+ gem "rubocop-rails", "~> 2.23.1"
18
18
  gem "coveralls", "~> 0.8.23", require: false
19
19
  end
20
20
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  namespace :telegram do
2
4
  namespace :bot do
3
5
  desc 'Run poller. It broadcasts Rails.logger to STDOUT in dev like `rails s` do. ' \
@@ -6,14 +8,14 @@ namespace :telegram do
6
8
  ENV['BOT_POLLER_MODE'] = 'true'
7
9
  Rake::Task['environment'].invoke
8
10
  if ENV.fetch('LOG_TO_STDOUT') { Rails.env.development? }.present?
9
- console = ActiveSupport::Logger.new(STDERR)
10
- if ::Rails.logger.respond_to?(:broadcast_to)
11
- ::Rails.logger.broadcast_to(console)
11
+ console = ActiveSupport::Logger.new($stderr)
12
+ if Rails.logger.respond_to?(:broadcast_to)
13
+ Rails.logger.broadcast_to(console)
12
14
  else
13
15
  Rails.logger.extend ActiveSupport::Logger.broadcast console
14
16
  end
15
17
  end
16
- Telegram::Bot::UpdatesPoller.start(ENV['BOT'].try!(:to_sym) || :default)
18
+ Telegram::Bot::UpdatesPoller.start(ENV['BOT']&.to_sym || :default)
17
19
  end
18
20
 
19
21
  desc 'Set webhook urls for all bots'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Telegram
2
4
  module Bot
3
5
  # Telegram clients can perform requests in async way with
@@ -128,7 +130,7 @@ module Telegram
128
130
  #
129
131
  # If no block is given returns previously set value or the global one,
130
132
  # set by #async=.
131
- def async(val = true)
133
+ def async(val = true) # rubocop:disable Style/OptionalBooleanParameter
132
134
  thread_key = object_id
133
135
  thread_store = Async.thread_store
134
136
  return thread_store.fetch(thread_key) { @async } unless block_given?
@@ -137,7 +139,7 @@ module Telegram
137
139
  thread_store[thread_key] = self.class.prepare_async_val(val)
138
140
  yield
139
141
  ensure
140
- if MISSING_VALUE == old_val
142
+ if old_val == MISSING_VALUE
141
143
  thread_store.delete(thread_key)
142
144
  else
143
145
  thread_store[thread_key] = old_val
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/core_ext/string/inflections'
2
4
 
3
5
  module Telegram
4
6
  module Bot
5
7
  class Client
6
8
  module ApiHelper
7
- METHODS_LIST_FILE = File.expand_path('../api_methods.txt', __FILE__)
9
+ METHODS_LIST_FILE = File.expand_path('api_methods.txt', __dir__)
8
10
 
9
11
  class << self
10
12
  def methods_list(file = METHODS_LIST_FILE)
@@ -1,5 +1,5 @@
1
1
  # Generated with bin/fetch-telegram-methods
2
- # Bot API 6.8
2
+ # Bot API 7.3
3
3
 
4
4
  getUpdates
5
5
  setWebhook
@@ -11,7 +11,9 @@ logOut
11
11
  close
12
12
  sendMessage
13
13
  forwardMessage
14
+ forwardMessages
14
15
  copyMessage
16
+ copyMessages
15
17
  sendPhoto
16
18
  sendAudio
17
19
  sendDocument
@@ -26,6 +28,7 @@ sendContact
26
28
  sendPoll
27
29
  sendDice
28
30
  sendChatAction
31
+ setMessageReaction
29
32
  getUserProfilePhotos
30
33
  getFile
31
34
  banChatMember
@@ -70,6 +73,8 @@ hideGeneralForumTopic
70
73
  unhideGeneralForumTopic
71
74
  unpinAllGeneralForumTopicMessages
72
75
  answerCallbackQuery
76
+ getUserChatBoosts
77
+ getBusinessConnection
73
78
  setMyCommands
74
79
  deleteMyCommands
75
80
  getMyCommands
@@ -92,6 +97,7 @@ stopMessageLiveLocation
92
97
  editMessageReplyMarkup
93
98
  stopPoll
94
99
  deleteMessage
100
+ deleteMessages
95
101
 
96
102
  sendSticker
97
103
  getStickerSet
@@ -101,6 +107,7 @@ createNewStickerSet
101
107
  addStickerToSet
102
108
  setStickerPositionInSet
103
109
  deleteStickerFromSet
110
+ replaceStickerInSet
104
111
  setStickerEmojiList
105
112
  setStickerKeywords
106
113
  setStickerMaskPosition
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
 
3
5
  module Telegram
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'telegram/bot/client/api_helper'
2
4
  require 'active_support/core_ext/string/inflections'
3
5
 
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/core_ext/hash/keys'
2
4
  require 'httpclient'
3
5
 
4
6
  module Telegram
5
7
  module Bot
6
8
  class Client
7
- SERVER = 'https://api.telegram.org'.freeze
8
- URL_TEMPLATE = '%<server>s/bot%<token>s/'.freeze
9
+ SERVER = 'https://api.telegram.org'
10
+ URL_TEMPLATE = '%<server>s/bot%<token>s/'
9
11
 
10
12
  autoload :RequestBodyFormatter, 'telegram/bot/client/request_body_formatter'
11
13
  autoload :TypedResponse, 'telegram/bot/client/typed_response'
@@ -41,7 +43,7 @@ module Telegram
41
43
  end
42
44
 
43
45
  def error_for_response(response)
44
- result = JSON.parse(response.body) rescue nil # rubocop:disable RescueModifier
46
+ result = JSON.parse(response.body) rescue nil # rubocop:disable Style/RescueModifier
45
47
  return Error.new(response.reason) unless result
46
48
  message = result['description'] || '-'
47
49
  # This errors are raised only for valid responses from Telegram
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Telegram
2
4
  module Bot
3
5
  # Stubbed client for tests. Saves all requests into #requests hash.
@@ -17,7 +19,7 @@ module Telegram
17
19
  class << self
18
20
  # Any call to Client.new will return ClientStub instance when `enabled` is true.
19
21
  # Can be used with a block.
20
- def stub_all!(enabled = true)
22
+ def stub_all!(enabled = true) # rubocop:disable Style/OptionalBooleanParameter
21
23
  Client.extend(StubbedConstructor) unless Client < StubbedConstructor
22
24
  return @_stub_all = enabled unless block_given?
23
25
  begin
@@ -34,7 +36,7 @@ module Telegram
34
36
  end
35
37
  end
36
38
 
37
- def initialize(token = nil, username = nil, **options)
39
+ def initialize(token = nil, username = nil, **options) # rubocop:disable Lint/MissingSuper
38
40
  @token = token || options[:token]
39
41
  @username = username || options[:username] || token
40
42
  reset
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/core_ext/hash/keys'
2
4
  require 'active_support/core_ext/hash/indifferent_access'
3
5
 
@@ -44,7 +46,7 @@ module Telegram
44
46
  # from `secrets.yml` merging `telegram['bot']` at `:default` key.
45
47
  #
46
48
  # Can be overwritten with .bots_config=
47
- def bots_config
49
+ def bots_config # rubocop:disable Metrics/PerceivedComplexity
48
50
  @bots_config ||=
49
51
  if defined?(Rails.application)
50
52
  app = Rails.application
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Telegram
2
4
  module Bot
3
5
  module DebugClient
4
- def debug!(dev = STDOUT)
6
+ def debug!(dev = $stdout)
5
7
  if block_given?
6
8
  begin
7
9
  old_dev = client.debug_dev
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/concern'
2
4
  require 'active_support/core_ext/hash/indifferent_access'
3
5
  require 'active_support/json'
@@ -21,7 +23,7 @@ module Telegram
21
23
  end
22
24
 
23
25
  def inspect
24
- "#<#{self.class.name}(#{controller.try!(:name)})>"
26
+ "#<#{self.class.name}(#{controller&.name})>"
25
27
  end
26
28
  end
27
29
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'telegram/bot/routes_helper'
2
4
 
3
5
  module Telegram
@@ -10,7 +12,7 @@ module Telegram
10
12
  end
11
13
 
12
14
  config.before_initialize do
13
- ::ActionDispatch::Routing::Mapper.send(:include, RoutesHelper)
15
+ ::ActionDispatch::Routing::Mapper.include RoutesHelper
14
16
  end
15
17
 
16
18
  initializer 'telegram.bot.updates_controller.set_config' do |app|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'base64'
2
4
  require 'openssl'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'telegram/bot/rspec'
2
4
  require 'telegram/bot/rspec/message_helpers'
3
5
 
@@ -7,7 +9,7 @@ RSpec.shared_context 'telegram/bot/callback_query' do
7
9
 
8
10
  subject { -> { dispatch callback_query: payload } }
9
11
  let(:payload) { {id: callback_query_id, from: from, message: message, data: data} }
10
- let(:callback_query_id) { 11 }
12
+ let(:callback_query_id) { '11' }
11
13
  let(:message_id) { 22 }
12
14
  let(:message) { {message_id: message_id, chat: chat, text: 'message text'} }
13
15
  let(:data) { raise '`let(:data) { "callback query data here" }` is required' }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Telegram
2
4
  module Bot
3
5
  module RSpec
@@ -61,14 +63,14 @@ module Telegram
61
63
 
62
64
  attr_reader :performed_requests, :description
63
65
 
64
- def initialize(bot, action, description: nil)
66
+ def initialize(bot, action, description: nil) # rubocop:disable Lint/MissingSuper
65
67
  @bot = bot
66
68
  @action = action
67
69
  @description = description || "make #{action} telegram request"
68
70
  exactly(1)
69
71
  end
70
72
 
71
- def matches?(proc) # rubocop:disable AbcSize
73
+ def matches?(proc) # rubocop:disable Metrics/AbcSize
72
74
  raise ArgumentError, 'matcher only supports block expectations' unless proc.is_a?(Proc)
73
75
  original_requests_count = bot.requests[action].count
74
76
  proc.call
@@ -115,15 +117,15 @@ module Telegram
115
117
  :arg_list_matcher, :matching_requests_count
116
118
 
117
119
  def base_message
118
- "make #{expectation_type.to_s.tr('_', ' ')} #{expected_number} " \
119
- "#{bot.inspect}.#{action} requests,".tap do |msg|
120
- msg << " with #{arg_list_matcher}," if arg_list_matcher
121
- msg << " but made #{matching_requests_count}"
122
- if performed_requests
123
- actual_args = performed_requests.map(&:inspect).join(', ')
124
- msg << ", and #{performed_requests.count} with #{actual_args}"
125
- end
120
+ msg = "make #{expectation_type.to_s.tr('_', ' ')} #{expected_number} " \
121
+ "#{bot.inspect}.#{action} requests,"
122
+ msg += " with #{arg_list_matcher}," if arg_list_matcher
123
+ msg += " but made #{matching_requests_count}"
124
+ if performed_requests
125
+ actual_args = performed_requests.map(&:inspect).join(', ')
126
+ msg += ", and #{performed_requests.count} with #{actual_args}"
126
127
  end
128
+ msg
127
129
  end
128
130
  end
129
131
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'telegram/bot/rspec/integration/shared'
2
4
 
3
5
  RSpec.shared_context 'telegram/bot/integration/poller' do