telegram-bot 0.15.6 → 0.15.7

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: 557dd6660b57db212a311ed47dc449c833dd2020fc51d13110bf95ecbc28f0b9
4
- data.tar.gz: b3dc3085d49456ce58931e4101b90b9a35d8853e09b0b0f398e772f6885b1e5a
3
+ metadata.gz: b2a7c11af116803bbd1e7538a63541064137f750f9ebde05afb172a52520aa69
4
+ data.tar.gz: ce49c1049a55d229e8ffcc502bf77f49a558c30941a3a0a474e7f756d0b06c68
5
5
  SHA512:
6
- metadata.gz: b1c07f86462d5c98528480ef526b0c14b0a94b66aa2e9b61b556bbf7ddd573a8db0b8a94149562ad481ccb802b975671f7eccc4ec6dba7b2ff98aaea21946b3a
7
- data.tar.gz: 738791f83acc89dee90a860d6dec91a8d340bf66cebdce8411c0bfe70c1de0ce2c90f0eeaac7dfaf7a930c6e1e50d158a39e75223a3bd0edacda8466c2ec0486
6
+ metadata.gz: c5820f8eda88f3a61102bb39cf394f7dbbed8f2c9f2336de8d2eee8fc26370f997e7ab67d244404ff5e64042ba72ee03c9418837318efb5b5fd0ef2630a606b3
7
+ data.tar.gz: d4aa425592ca34e7291406948fc35d07f5cb33b78a9be09fd7ebed2b03b4ec9d583aef9cc002ee4a56f4a7b5fe6eea2b4403700c76d9abdf04be5623ff5501af
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Unreleased
2
2
 
3
+ # 0.15.7
4
+
5
+ - Add support for editMessageMedia similar to sendMediaGroup.
6
+
3
7
  # 0.15.6
4
8
 
5
9
  - Rails 7.0 support.
@@ -11,8 +11,14 @@ module Telegram
11
11
 
12
12
  def format(body, action)
13
13
  body = body.dup
14
- if action.to_s == 'sendMediaGroup'
15
- body = extract_files_from_array!(body, :media)
14
+ case action.to_s
15
+ when 'sendMediaGroup'
16
+ extract_files_from_array!(body, :media)
17
+ when 'editMessageMedia'
18
+ replace_field(body, :media) do |value|
19
+ files = {}
20
+ extract_files_from_hash(value, files).tap { body.merge!(files) }
21
+ end
16
22
  end
17
23
  body.each do |key, val|
18
24
  body[key] = val.to_json if val.is_a?(Hash) || val.is_a?(Array)
@@ -21,12 +27,19 @@ module Telegram
21
27
 
22
28
  private
23
29
 
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
+ # Detects field by symbol or string name and replaces it with mapped value.
31
+ def replace_field(hash, field_name)
32
+ field_name = [field_name.to_sym, field_name.to_s].find { |x| hash.key?(x) }
33
+ hash[field_name] = yield hash[field_name] if field_name
34
+ end
35
+
36
+ def extract_files_from_array!(hash, field_name)
37
+ replace_field(hash, field_name) do |value|
38
+ break value unless value.is_a?(Array)
39
+ files = {}
40
+ value.map { |x| extract_files_from_hash(x, files) }.
41
+ tap { hash.merge!(files) }
42
+ end
30
43
  end
31
44
 
32
45
  # Replace File objects with `attach` URIs. File objects are added into `files` hash.
@@ -1,6 +1,6 @@
1
1
  module Telegram
2
2
  module Bot
3
- VERSION = '0.15.6'.freeze
3
+ VERSION = '0.15.7'.freeze
4
4
 
5
5
  def self.gem_version
6
6
  Gem::Version.new VERSION
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.6
4
+ version: 0.15.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Melentiev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-13 00:00:00.000000000 Z
11
+ date: 2023-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack