cloud-waba-ruby-client 0.0.12 → 0.0.13

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: b0c8075f042ed9a22dab184ab4d24523d990c669a9ccac1b85bcc2920b62bb98
4
- data.tar.gz: cb54e89fc26f3c6d1ef655110a806a0c4572dced3fb407f43b4921cc5fcd482d
3
+ metadata.gz: 848411d117f6ed1d74d7b968320c3bcc711376956d1061d2857b2f652fa55cf8
4
+ data.tar.gz: c5b829040b35f18516f795361f3202e5f97cddee05c89f7295a73b6e3c6c4138
5
5
  SHA512:
6
- metadata.gz: b89699168601430eb4772032711c79c93cf4147def5f967c1f727e7d27a47fcfb9ad74495b28d7eea37e669085c33ff27737b922ec24bd855359ea699ff169c9
7
- data.tar.gz: 283c9530b7f59b1b39d1b6688c4014c5d79d0526b08e8b6b0b0def99a27c297e65271fa6c266c44a20ca420d6d8ea63b7010fe4d4b17daeccfded3823267e4e6
6
+ metadata.gz: a7369920015c6d7c9814a1f3325105e37dab9936b802851e92b423d20774accc03fe94584306675c208e5aa8aa77638876e1ab2da593cb580068c936ff6a34ed
7
+ data.tar.gz: 2211993d33dd43a4a78f103f94c01f0d9e417ea65d73712b9276b94297d13711c13ce9accae1c3e3c4c9608183c06a3fa55befbdb01df6ec86544a7568617cae
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cloud-waba-ruby-client"
3
- s.version = "0.0.12"
3
+ s.version = "0.0.13"
4
4
  s.summary = "Cloud Waba Client for Ruby."
5
5
  s.description = "A simple API wrapper for Cloud Whatsapp Business API"
6
6
  s.authors = ["Ahmed Bassell"]
@@ -18,7 +18,7 @@ module API
18
18
  params(limit: T.nilable(::Integer)).returns(::CloudWaba::Models::Templates::List)
19
19
  end
20
20
  def list(limit: 20)
21
- fields = "id,name,category,language,status"
21
+ fields = "id,name,category,language,status,components"
22
22
  response = with_error_handling { templates_client.get(params: { fields: fields, limit: limit }) }
23
23
 
24
24
  parsed_response = JSON.parse(response.body.to_s)
@@ -26,6 +26,35 @@ module API
26
26
  ::CloudWaba::Models::Templates::List.new(templates: templates, paging: parsed_response["paging"])
27
27
  end
28
28
 
29
+ sig do
30
+ params(
31
+ limit: T.nilable(::Integer),
32
+ block: T.proc.params(template: ::CloudWaba::Models::Templates::Response).void
33
+ ).void
34
+ end
35
+ def find_each(limit: 20, &block)
36
+ return unless block_given?
37
+
38
+ fields = "id,name,category,language,status,components"
39
+ params = { fields: fields, limit: limit }
40
+
41
+ loop do
42
+ response = with_error_handling { templates_client.get(params: params) }
43
+ parsed_response = JSON.parse(response.body.to_s)
44
+
45
+ templates = parsed_response["data"].map{|hash| ::CloudWaba::Models::Templates::Response.parse(template_hash: hash)}
46
+ templates.each { |template| yield(template) }
47
+
48
+ paging = parsed_response["paging"]
49
+ after = paging&.dig("cursors", "after")
50
+ next_link = paging&.dig("next")
51
+
52
+ break if after.nil? || after.empty? || next_link.nil?
53
+
54
+ params[:after] = after
55
+ end
56
+ end
57
+
29
58
  sig do
30
59
  params(
31
60
  name: ::String,
@@ -13,7 +13,7 @@ module CloudWaba
13
13
  {
14
14
  type: type.serialize,
15
15
  text: text,
16
- example: { body_text: [ example.values ] }
16
+ example: { body_text: [ example&.values || [] ] }
17
17
  }
18
18
  end
19
19
  end
@@ -14,6 +14,50 @@ module CloudWaba
14
14
  ::CloudWaba::Models::Templates::ButtonsComponent,
15
15
  )
16
16
  end
17
+
18
+ class << self
19
+ extend ::T::Sig
20
+
21
+ sig { params(component_hash: ::T::Hash[::T.untyped, ::T.untyped]).returns(::CloudWaba::Models::Templates::Component) }
22
+ def parse(component_hash:)
23
+ component_type = component_hash["type"]
24
+
25
+ case component_type
26
+ when "HEADER"
27
+ format = component_hash["format"]
28
+ case format
29
+ when "TEXT"
30
+ ::CloudWaba::Models::Templates::HeaderTextComponent.new(
31
+ text: component_hash["text"]
32
+ )
33
+ when "IMAGE", "VIDEO", "DOCUMENT"
34
+ format_enum = ::CloudWaba::Models::Enums::Templates::Format.try_deserialize(format)
35
+ ::CloudWaba::Models::Templates::HeaderMediaComponent.new(
36
+ format: format_enum || ::CloudWaba::Models::Enums::Templates::Format::Image
37
+ )
38
+ when "LOCATION"
39
+ ::CloudWaba::Models::Templates::HeaderLocationComponent.new
40
+ else
41
+ raise ArgumentError, "Unsupported header format: #{format}"
42
+ end
43
+ when "BODY"
44
+ ::CloudWaba::Models::Templates::BodyComponent.new(
45
+ text: component_hash["text"]
46
+ )
47
+ when "FOOTER"
48
+ ::CloudWaba::Models::Templates::FooterComponent.new(
49
+ text: component_hash["text"]
50
+ )
51
+ when "BUTTONS"
52
+ # For now, return empty buttons component - would need to parse buttons array
53
+ ::CloudWaba::Models::Templates::ButtonsComponent.new(
54
+ buttons: []
55
+ )
56
+ else
57
+ raise ArgumentError, "Unsupported component type: #{component_type}"
58
+ end
59
+ end
60
+ end
17
61
  end
18
62
  end
19
63
  end
@@ -13,7 +13,7 @@ module CloudWaba
13
13
  {
14
14
  type: type.serialize,
15
15
  format: format.serialize,
16
- example: { header_handle: [ example.values ] }
16
+ example: { header_handle: [ example&.values || [] ] }
17
17
  }
18
18
  end
19
19
  end
@@ -14,7 +14,7 @@ module CloudWaba
14
14
  type: type.serialize,
15
15
  format: "TEXT",
16
16
  text: text,
17
- example: { header_text: example.values }
17
+ example: { header_text: example&.values || [] }
18
18
  }
19
19
  end
20
20
  end
@@ -13,19 +13,39 @@ module CloudWaba
13
13
  prop :category, ::T.nilable(::CloudWaba::Models::Enums::Templates::Category)
14
14
  prop :language, ::T.nilable(::String)
15
15
  prop :name, ::T.nilable(::String)
16
+ prop :components, ::T.nilable(::T::Array[::CloudWaba::Models::Templates::Component])
16
17
 
17
18
  sig { params(template_hash: ::T::Hash[::T.untyped, ::T.untyped]).returns(::CloudWaba::Models::Templates::Response) }
18
19
  def self.parse(template_hash:)
19
20
  category = ::CloudWaba::Models::Enums::Templates::Category.try_deserialize(template_hash["category"])
21
+ components = template_hash["components"].map{|component| ::CloudWaba::Models::Templates.parse(component_hash: component)}
20
22
 
21
23
  self.new(
22
24
  id: template_hash["id"],
23
25
  status: template_hash["status"],
24
26
  category: category,
25
27
  language: template_hash["language"],
26
- name: template_hash["name"]
28
+ name: template_hash["name"],
29
+ components: components
27
30
  )
28
31
  end
32
+
33
+ sig { returns(::T::Hash[::T.untyped, ::T.untyped]) }
34
+ def serialize
35
+ result = {
36
+ id: id,
37
+ status: status,
38
+ category: category&.serialize,
39
+ language: language,
40
+ name: name
41
+ }
42
+
43
+ if components
44
+ result[:components] = components.map(&:serialize)
45
+ end
46
+
47
+ result
48
+ end
29
49
  end
30
50
  end
31
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud-waba-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmed Bassell
8
8
  autorequire: cloud-waba-ruby-client
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-09-05 00:00:00.000000000 Z
11
+ date: 2025-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv