onyxcord-webhooks 1.1.2 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 808c218136e136121ada58d4cc381d5de4ccad0a1f20ffe702aeba26dc0dea3b
4
- data.tar.gz: f2c44b0b21bd64ac2c2ab9e03569d455a2a400d653513af53f7904f61bd40749
3
+ metadata.gz: e982f78ebf7f9a4d5d617e1cbe254864ff1917315ad1cd276b19c0b984ba3970
4
+ data.tar.gz: b1d2f272611a9b979ebb11449a3c3933ae93cf8f4ffa9ced85e0f876664e61b6
5
5
  SHA512:
6
- metadata.gz: 0c529bf0c135a5671367238e2a16070966cb3f1242018b9e8c6d1295028745ed3deb5f39099dfa0aafbb8647cd97ecb2d8334ec005378b5e8b1c02c04b5a8a36
7
- data.tar.gz: f8827403f0533f267e7427b9f5a06235f7e9f215f0f55debef75415985fe070bac3c2e221d6602af2c97e1c88b3c9c1f3edab51cdd25431ca45299a5c787bcba
6
+ metadata.gz: 144cff3d1f4f0a8905e52c4d4fbe1355a0c7a2414075e922ee7b21661b75a908ff10e711259def51512e3121b6c6080c8d053e119021f3d3ced93233c706dea8
7
+ data.tar.gz: 81dc22284b71cc4dea50f7ed99428f0adfc88eee0d3e10c989caa743e28a10d3deb4a7e3f89a65fc61a3707bffae11d5d69885f1c06a86c604bf185fcf571d33
@@ -4,6 +4,6 @@
4
4
  module OnyxCord
5
5
  module Webhooks
6
6
  # The current version of onyxcord-webhooks.
7
- VERSION = '1.1.2'
7
+ VERSION = '1.1.4'
8
8
  end
9
9
  end
@@ -279,7 +279,9 @@ class OnyxCord::Webhooks::View
279
279
  # @param url [String] An `attachment://<filename>` reference to the attached file.
280
280
  # @param id [Integer, nil] The unique 32-bit ID of the file component.
281
281
  # @param spoiler [true, false] Whether or not to apply a spoiler label to the file.
282
- def initialize(url:, id: nil, spoiler: false)
282
+ def initialize(url = nil, id: nil, spoiler: false, **kwargs)
283
+ url = kwargs.fetch(:url, url)
284
+
283
285
  @id = id
284
286
  @file = { url: }
285
287
  @spoiler = spoiler
@@ -296,10 +298,12 @@ class OnyxCord::Webhooks::View
296
298
  # Create a media gallery component.
297
299
  # @param id [Integer, nil] The unique 32-bit ID of the media gallery component.
298
300
  # @yieldparam builder [MediaGalleryBuilder] Yields the initialized media gallery component.
299
- def initialize(id: nil)
301
+ def initialize(*items, id: nil)
300
302
  @id = id
301
303
  @items = []
302
304
 
305
+ items.each { |item| self.item(item) }
306
+
303
307
  yield self if block_given?
304
308
  end
305
309
 
@@ -307,14 +311,32 @@ class OnyxCord::Webhooks::View
307
311
  # @param url [String] The URL to the gallery item's media.
308
312
  # @param description [String, nil] The description of the gallery item.
309
313
  # @param spoiler [true, false] Whether or not to apply a spoiler label to the gallery item.
310
- def item(url:, description: nil, spoiler: false)
311
- @items << { media: { url: }, description: description, spoiler: spoiler }.compact
314
+ def item(item = nil, url: nil, description: nil, spoiler: nil)
315
+ url, description, spoiler = normalize_item(item, url, description, spoiler)
316
+ raise ArgumentError, 'media gallery item requires a url' if url.nil? || url.to_s.empty?
317
+
318
+ @items << { media: { url: url }, description: description, spoiler: spoiler }.compact
312
319
  end
313
320
 
314
321
  # @!visibility private
315
322
  def to_h
316
323
  { type: COMPONENT_TYPES[:media_gallery], id: @id, items: @items }.compact
317
324
  end
325
+
326
+ private
327
+
328
+ def normalize_item(item, url, description, spoiler)
329
+ if item.is_a?(Hash)
330
+ media = item[:media] || item['media'] || {}
331
+ url ||= item[:url] || item['url'] || media[:url] || media['url']
332
+ description = item[:description] || item['description'] if description.nil?
333
+ spoiler = item[:spoiler] || item['spoiler'] if spoiler.nil?
334
+ else
335
+ url ||= item
336
+ end
337
+
338
+ [url, description, spoiler.nil? ? false : spoiler]
339
+ end
318
340
  end
319
341
 
320
342
  # A section allows you to group together an accessory with text display components.
@@ -425,8 +447,8 @@ class OnyxCord::Webhooks::View
425
447
 
426
448
  # Add a media gallery component to the container.
427
449
  # @see MediaGalleryBuilder#initialize
428
- def media_gallery(...)
429
- @components << MediaGalleryBuilder.new(...)
450
+ def media_gallery(*items, id: nil, &block)
451
+ @components << MediaGalleryBuilder.new(*items, id: id, &block)
430
452
  end
431
453
 
432
454
  # Set the color of the container.
@@ -547,8 +569,8 @@ class OnyxCord::Webhooks::View
547
569
 
548
570
  # Add a media gallery component to the view.
549
571
  # @see MediaGalleryBuilder#initialize
550
- def media_gallery(id: nil, &block)
551
- builder = MediaGalleryBuilder.new(id: id)
572
+ def media_gallery(*items, id: nil, &block)
573
+ builder = MediaGalleryBuilder.new(*items, id: id)
552
574
  @components << builder
553
575
  yield builder if block_given?
554
576
  builder
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onyxcord-webhooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gustavo Silva
@@ -16,6 +16,9 @@ dependencies:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
18
  version: 2.0.0
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '3'
19
22
  type: :runtime
20
23
  prerelease: false
21
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -23,6 +26,9 @@ dependencies:
23
26
  - - ">="
24
27
  - !ruby/object:Gem::Version
25
28
  version: 2.0.0
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '3'
26
32
  description: A webhook client for OnyxCord, a Ruby Discord library based on discordrb
27
33
  and updated with Components V2 support.
28
34
  email: