telegram-bot-ruby 0.15.0 → 0.16.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
  SHA256:
3
- metadata.gz: 9b39d62dd4efff4ab96664e0cc4a0ce3eee6631ea8b96c3b90be993f8bae6d34
4
- data.tar.gz: e7afcb7986690e5e512faa9caec4abe13f85e21252e86f13af48968ae990bca0
3
+ metadata.gz: 6227a7eff23e7037a7e07e021a4f2925681c952a449b99a38cd5c23b3f331c5c
4
+ data.tar.gz: a1bc35c582ff1ba5fe4627613e6c71454be8c11877a5a1fdca7ca300a1a1fead
5
5
  SHA512:
6
- metadata.gz: 527a11835b057bc29fdbeecd22350b86b1f3bfdd9bc3c328e11b5fe275fd47847c946bc4bf7b3f804f25b9f9dee8a693c54bb3d6ebf8d64a1a009995b59d03e9
7
- data.tar.gz: 839b7b1c0c03c4109ebcdc6f777af0f90013393f35407b113c6805d7740bc9326dc2e4236b465f76387db38656832aa615178bcc96b5c13a0fdb1ebbbedbc356
6
+ metadata.gz: 39ff75cc41a8fcfa5558a28cedb8e9f3b4be72e40fca71a4f8a9a1493bcd67850c6598e84882b2db7edee2c46202b72756d1612f477909fc1097211d7a95f1da
7
+ data.tar.gz: fb29319e282a3b851689503657f1877511555b10be4135bc9c99ad192093c3ea7f96e352a32bb2cb50bedc5dd206944f2604d135b15a9375a678186c244c385b
data/.rubocop.yml CHANGED
@@ -10,6 +10,7 @@ Metrics/BlockLength:
10
10
  - describe
11
11
 
12
12
  Metrics/LineLength:
13
+ Max: 120
13
14
  Exclude:
14
15
  - telegram-bot-ruby.gemspec
15
16
  - examples/*.rb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.16.0
4
+
5
+ - Replace `inflecto` with `dry-inflector`
6
+ - Update `virtus` up to 2.0
7
+
3
8
  ## 0.15.0
4
9
 
5
10
  - Implement [Bot API 5.1](https://core.telegram.org/bots/api#march-9-2021)
data/lib/telegram/bot.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'virtus'
2
- require 'inflecto'
3
2
  require 'logger'
4
3
  require 'json'
5
4
  require 'faraday'
@@ -1,6 +1,6 @@
1
1
  module Telegram
2
2
  module Bot
3
- class Api # rubocop:disable ClassLength
3
+ class Api
4
4
  ENDPOINTS = %w[
5
5
  getUpdates setWebhook deleteWebhook getWebhookInfo getMe sendMessage
6
6
  forwardMessage sendPhoto sendAudio sendDocument sendVideo sendVoice
@@ -22,34 +22,6 @@ module Telegram
22
22
  setStickerSetThumb logOut close copyMessage createChatInviteLink
23
23
  editChatInviteLink revokeChatInviteLink
24
24
  ].freeze
25
- REPLY_MARKUP_TYPES = [
26
- Telegram::Bot::Types::ReplyKeyboardMarkup,
27
- Telegram::Bot::Types::ReplyKeyboardRemove,
28
- Telegram::Bot::Types::ForceReply,
29
- Telegram::Bot::Types::InlineKeyboardMarkup
30
- ].freeze
31
- INLINE_QUERY_RESULT_TYPES = [
32
- Telegram::Bot::Types::InlineQueryResultArticle,
33
- Telegram::Bot::Types::InlineQueryResultPhoto,
34
- Telegram::Bot::Types::InlineQueryResultGif,
35
- Telegram::Bot::Types::InlineQueryResultMpeg4Gif,
36
- Telegram::Bot::Types::InlineQueryResultVideo,
37
- Telegram::Bot::Types::InlineQueryResultAudio,
38
- Telegram::Bot::Types::InlineQueryResultVoice,
39
- Telegram::Bot::Types::InlineQueryResultDocument,
40
- Telegram::Bot::Types::InlineQueryResultLocation,
41
- Telegram::Bot::Types::InlineQueryResultVenue,
42
- Telegram::Bot::Types::InlineQueryResultContact,
43
- Telegram::Bot::Types::InlineQueryResultGame,
44
- Telegram::Bot::Types::InlineQueryResultCachedPhoto,
45
- Telegram::Bot::Types::InlineQueryResultCachedGif,
46
- Telegram::Bot::Types::InlineQueryResultCachedMpeg4Gif,
47
- Telegram::Bot::Types::InlineQueryResultCachedSticker,
48
- Telegram::Bot::Types::InlineQueryResultCachedDocument,
49
- Telegram::Bot::Types::InlineQueryResultCachedVideo,
50
- Telegram::Bot::Types::InlineQueryResultCachedVoice,
51
- Telegram::Bot::Types::InlineQueryResultCachedAudio
52
- ].freeze
53
25
 
54
26
  attr_reader :token, :url
55
27
 
@@ -92,19 +64,15 @@ module Telegram
92
64
  end
93
65
 
94
66
  def sanitize_value(value)
95
- jsonify_inline_query_results(jsonify_reply_markup(value))
67
+ jsonify_value(value)
96
68
  end
97
69
 
98
- def jsonify_reply_markup(value)
99
- return value unless REPLY_MARKUP_TYPES.any? { |type| value.is_a?(type) }
100
- value.to_compact_hash.to_json
70
+ def jsonify_value(value)
71
+ jsonify_value?(value) ? value.to_json : value
101
72
  end
102
73
 
103
- def jsonify_inline_query_results(value)
104
- return value unless
105
- value.is_a?(Array) &&
106
- value.all? { |i| INLINE_QUERY_RESULT_TYPES.any? { |t| i.is_a?(t) } }
107
- value.map { |i| i.to_compact_hash.select { |_, v| v } }.to_json
74
+ def jsonify_value?(value)
75
+ value.respond_to?(:to_compact_hash) || value.is_a?(Array)
108
76
  end
109
77
 
110
78
  def camelize(method_name)
@@ -1,4 +1,5 @@
1
1
  require 'telegram/bot/types/compactable'
2
+ require 'telegram/bot/types/pattern_matching'
2
3
  require 'telegram/bot/types/base'
3
4
  require 'telegram/bot/types/user'
4
5
  require 'telegram/bot/types/photo_size'
@@ -4,6 +4,7 @@ module Telegram
4
4
  class Base
5
5
  include Virtus.model
6
6
  include Compactable
7
+ include PatternMatching
7
8
  end
8
9
  end
9
10
  end
@@ -4,6 +4,7 @@ module Telegram
4
4
  class Chat
5
5
  include Virtus.model(finalize: false)
6
6
  include Compactable
7
+ include PatternMatching
7
8
 
8
9
  attribute :id, Integer
9
10
  attribute :type, String
@@ -5,7 +5,7 @@ module Telegram
5
5
  def to_compact_hash
6
6
  Hash[attributes.dup.delete_if { |_, v| v.nil? }.map do |key, value|
7
7
  value =
8
- if value.class.ancestors.include?(Telegram::Bot::Types::Base)
8
+ if value.respond_to?(:to_compact_hash)
9
9
  value.to_compact_hash
10
10
  else
11
11
  value
@@ -14,6 +14,10 @@ module Telegram
14
14
  [key, value]
15
15
  end]
16
16
  end
17
+
18
+ def to_json(*args)
19
+ to_compact_hash.select { |_, v| v }.to_json(*args)
20
+ end
17
21
  end
18
22
  end
19
23
  end
@@ -0,0 +1,11 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ module PatternMatching
5
+ def deconstruct_keys(_keys)
6
+ attributes
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module Telegram
2
2
  module Bot
3
- VERSION = '0.15.0'.freeze
3
+ VERSION = '0.16.0'.freeze
4
4
  end
5
5
  end
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ['lib']
19
19
 
20
20
  spec.add_dependency 'faraday'
21
- spec.add_dependency 'virtus'
22
- spec.add_dependency 'inflecto'
21
+ spec.add_dependency 'virtus', '~> 2.0'
22
+ spec.add_dependency 'dry-inflector'
23
23
 
24
24
  spec.add_development_dependency 'rake', '~> 13.0'
25
25
  spec.add_development_dependency 'pry'
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.15.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Tipugin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-11 00:00:00.000000000 Z
11
+ date: 2021-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -28,18 +28,18 @@ dependencies:
28
28
  name: virtus
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '2.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: inflecto
42
+ name: dry-inflector
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -228,6 +228,7 @@ files:
228
228
  - lib/telegram/bot/types/passport_element_error_translation_files.rb
229
229
  - lib/telegram/bot/types/passport_element_error_unspecified.rb
230
230
  - lib/telegram/bot/types/passport_file.rb
231
+ - lib/telegram/bot/types/pattern_matching.rb
231
232
  - lib/telegram/bot/types/photo_size.rb
232
233
  - lib/telegram/bot/types/poll.rb
233
234
  - lib/telegram/bot/types/poll_answer.rb
@@ -273,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
273
274
  - !ruby/object:Gem::Version
274
275
  version: '0'
275
276
  requirements: []
276
- rubygems_version: 3.2.3
277
+ rubygems_version: 3.2.15
277
278
  signing_key:
278
279
  specification_version: 4
279
280
  summary: Ruby wrapper for Telegram's Bot API