cloud-waba-ruby-client 0.0.11 → 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 +4 -4
- data/README.md +2 -1
- data/cloud-waba-ruby-client.gemspec +2 -1
- data/lib/api/templates/service.rb +30 -1
- data/lib/cloud-waba-ruby-client.rb +7 -0
- data/lib/cloud_waba/models/templates/body_component.rb +1 -1
- data/lib/cloud_waba/models/templates/component.rb +44 -0
- data/lib/cloud_waba/models/templates/header_media_component.rb +1 -1
- data/lib/cloud_waba/models/templates/header_text_component.rb +1 -1
- data/lib/cloud_waba/models/templates/response.rb +21 -1
- data/lib/cloud_waba.rb +4 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 848411d117f6ed1d74d7b968320c3bcc711376956d1061d2857b2f652fa55cf8
|
4
|
+
data.tar.gz: c5b829040b35f18516f795361f3202e5f97cddee05c89f7295a73b6e3c6c4138
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7369920015c6d7c9814a1f3325105e37dab9936b802851e92b423d20774accc03fe94584306675c208e5aa8aa77638876e1ab2da593cb580068c936ff6a34ed
|
7
|
+
data.tar.gz: 2211993d33dd43a4a78f103f94c01f0d9e417ea65d73712b9276b94297d13711c13ce9accae1c3e3c4c9608183c06a3fa55befbdb01df6ec86544a7568617cae
|
data/README.md
CHANGED
@@ -29,9 +29,10 @@ gem install cloud-waba-ruby-client
|
|
29
29
|
- A phone number added to your WhatsApp business account
|
30
30
|
- Meta developer app
|
31
31
|
### Initiating clients using parameters
|
32
|
+
|
33
|
+
**Option 1: Manual require (explicit)**
|
32
34
|
```ruby
|
33
35
|
require "cloud_waba" # Auto-loads the entire gem
|
34
|
-
|
35
36
|
client_1 = CloudWaba::Client.new(
|
36
37
|
app_id: param_app_id_1,
|
37
38
|
app_secret: param_app_secret_1,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "cloud-waba-ruby-client"
|
3
|
-
s.version = "0.0.
|
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"]
|
@@ -8,6 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
# s.platform = Gem::Platform::RUBY
|
9
9
|
s.files = `git ls-files`.split("\n")
|
10
10
|
s.require_paths = ["lib"]
|
11
|
+
s.autorequire = "cloud-waba-ruby-client"
|
11
12
|
s.homepage =
|
12
13
|
"https://rubygems.org/gems/cloud_waba"
|
13
14
|
s.license = "MIT"
|
@@ -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,
|
@@ -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,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
|
data/lib/cloud_waba.rb
CHANGED
@@ -6,4 +6,7 @@ require "sorbet-runtime"
|
|
6
6
|
# Main entry point for the CloudWaba gem
|
7
7
|
# This file should be required to load the entire gem
|
8
8
|
|
9
|
-
|
9
|
+
module CloudWaba
|
10
|
+
# Auto-load the main client class when first accessed
|
11
|
+
autoload :Client, "cloud_waba/client"
|
12
|
+
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.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmed Bassell
|
8
|
-
autorequire:
|
8
|
+
autorequire: cloud-waba-ruby-client
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-09-
|
11
|
+
date: 2025-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- cloud-waba-ruby-client.gemspec
|
112
112
|
- lib/api/messages/service.rb
|
113
113
|
- lib/api/templates/service.rb
|
114
|
+
- lib/cloud-waba-ruby-client.rb
|
114
115
|
- lib/cloud_waba.rb
|
115
116
|
- lib/cloud_waba/client.rb
|
116
117
|
- lib/cloud_waba/errors/bad_request.rb
|