whatsapp_sdk 0.7.3 → 0.9.0

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.
@@ -0,0 +1,48 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module WhatsappSdk
5
+ module Resource
6
+ class InteractiveBody
7
+ extend T::Sig
8
+
9
+ # Returns Text string if the parameter object type is text.
10
+ # For the body interactive, the character limit is 1024 characters.
11
+ #
12
+ # @returns text [String]
13
+ sig { returns(String) }
14
+ attr_accessor :text
15
+
16
+ sig do
17
+ params(text: String).void
18
+ end
19
+ def initialize(text:)
20
+ @text = text
21
+ validate
22
+ end
23
+
24
+ sig { returns(T::Hash[T.untyped, T.untyped]) }
25
+ def to_json
26
+ { text: text }
27
+ end
28
+
29
+ MAXIMUM_LENGTH = 1024
30
+
31
+ private
32
+
33
+ sig { void }
34
+ def validate
35
+ validate_text
36
+ end
37
+
38
+ sig { void }
39
+ def validate_text
40
+ text_length = text.length
41
+ return if text_length <= MAXIMUM_LENGTH
42
+
43
+ raise WhatsappSdk::Resource::Error::InvalidInteractiveBody,
44
+ "Invalid length #{text_length} for text in body. Maximum length: #{MAXIMUM_LENGTH} characters."
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,48 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module WhatsappSdk
5
+ module Resource
6
+ class InteractiveFooter
7
+ extend T::Sig
8
+
9
+ # Returns Text string if the parameter object type is text.
10
+ # For the body interactive, the character limit is 60 characters.
11
+ #
12
+ # @returns text [String]
13
+ sig { returns(String) }
14
+ attr_accessor :text
15
+
16
+ sig do
17
+ params(text: String).void
18
+ end
19
+ def initialize(text:)
20
+ @text = text
21
+ validate
22
+ end
23
+
24
+ sig { returns(T::Hash[T.untyped, T.untyped]) }
25
+ def to_json
26
+ { text: text }
27
+ end
28
+
29
+ MAXIMUM_LENGTH = 60
30
+
31
+ private
32
+
33
+ sig { void }
34
+ def validate
35
+ validate_text
36
+ end
37
+
38
+ sig { void }
39
+ def validate_text
40
+ text_length = text.length
41
+ return if text_length <= MAXIMUM_LENGTH
42
+
43
+ raise WhatsappSdk::Resource::Error::InvalidInteractiveFooter,
44
+ "Invalid length #{text_length} for text in footer. Maximum length: #{MAXIMUM_LENGTH} characters."
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,120 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module WhatsappSdk
5
+ module Resource
6
+ class InteractiveHeader
7
+ extend T::Sig
8
+
9
+ # Returns the interactive header type.
10
+ #
11
+ # @returns type [String] Valid options are text, image, document, video.
12
+ sig { returns(Type) }
13
+ attr_accessor :type
14
+
15
+ class Type < T::Enum
16
+ extend T::Sig
17
+
18
+ enums do
19
+ Text = new("text")
20
+ Image = new("image")
21
+ Document = new("document")
22
+ Video = new("video")
23
+ end
24
+ end
25
+
26
+ # Returns Text string if the interactive header type is text.
27
+ # For the header interactive, the character limit is 60 characters.
28
+ # For the body interactive, the character limit is 1024 characters.
29
+ #
30
+ # @returns text [String]
31
+ sig { returns(T.nilable(String)) }
32
+ attr_accessor :text
33
+
34
+ # Returns image if the interactive header type is image.
35
+ #
36
+ # @returns image [Media]
37
+ sig { returns(T.nilable(Media)) }
38
+ attr_accessor :image
39
+
40
+ # Returns document if the interactive header type is document.
41
+ #
42
+ # @returns document [Media]
43
+ sig { returns(T.nilable(Media)) }
44
+ attr_accessor :document
45
+
46
+ # Returns video if the interactive header type is video.
47
+ #
48
+ # @returns video [Media]
49
+ sig { returns(T.nilable(Media)) }
50
+ attr_accessor :video
51
+
52
+ sig do
53
+ params(
54
+ type: T.any(Type, String), text: T.nilable(String), image: T.nilable(Media),
55
+ document: T.nilable(Media), video: T.nilable(Media)
56
+ ).void
57
+ end
58
+ def initialize(type:, text: nil, image: nil, document: nil, video: nil)
59
+ @type = T.let(deserialize_type(type), Type)
60
+ @text = text
61
+ @image = image
62
+ @document = document
63
+ @video = video
64
+ validate
65
+ end
66
+
67
+ sig { returns(T::Hash[T.untyped, T.untyped]) }
68
+ def to_json
69
+ json = { type: type.serialize }
70
+ json[type.serialize.to_sym] = case type.serialize
71
+ when "text"
72
+ text
73
+ when "image"
74
+ T.must(image).to_json
75
+ when "document"
76
+ T.must(document).to_json
77
+ when "video"
78
+ T.must(video).to_json
79
+ else
80
+ raise "Invalid type: #{type}"
81
+ end
82
+
83
+ json
84
+ end
85
+
86
+ private
87
+
88
+ sig { params(type: T.any(String, Type)).returns(Type) }
89
+ def deserialize_type(type)
90
+ return type if type.is_a?(Type)
91
+
92
+ Type.deserialize(type)
93
+ end
94
+
95
+ sig { void }
96
+ def validate
97
+ validate_attributes
98
+ end
99
+
100
+ sig { void }
101
+ def validate_attributes
102
+ [
103
+ [Type::Text, text],
104
+ [Type::Image, image],
105
+ [Type::Document, document],
106
+ [Type::Video, video]
107
+ ].each do |type_b, value|
108
+ next unless type == type_b
109
+
110
+ next unless value.nil?
111
+
112
+ raise WhatsappSdk::Resource::Error::MissingValue.new(
113
+ type.serialize,
114
+ "#{type.serialize} is required when the type is #{type_b}"
115
+ )
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -22,23 +22,6 @@ module WhatsappSdk
22
22
  end
23
23
  end
24
24
 
25
- class MissingValue < StandardError
26
- extend T::Sig
27
-
28
- sig { returns(String) }
29
- attr_reader :field
30
-
31
- sig { returns(String) }
32
- attr_reader :message
33
-
34
- sig { params(field: String, message: String).void }
35
- def initialize(field, message)
36
- @field = field
37
- @message = message
38
- super(message)
39
- end
40
- end
41
-
42
25
  # Returns the parameter type.
43
26
  #
44
27
  # @returns type [String] Valid options are text, currency, date_time, image, document, video.
@@ -169,7 +152,11 @@ module WhatsappSdk
169
152
  [Type::Video, video]
170
153
  ].each do |type_b, value|
171
154
  next unless type == type_b
172
- raise MissingValue.new(type.serialize, "#{type_b} is required when the type is #{type_b}") if value.nil?
155
+
156
+ if value.nil?
157
+ raise WhatsappSdk::Resource::Error::MissingValue.new(type.serialize,
158
+ "#{type_b} is required when the type is #{type_b}")
159
+ end
173
160
  end
174
161
  end
175
162
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
- VERSION = "0.7.3"
5
+ VERSION = "0.9.0"
6
6
  end
@@ -18,8 +18,8 @@ module Mocha::ClassMethods
18
18
  end
19
19
 
20
20
  class Mocha::Expectation
21
- sig { params(expected_parameters: T.untyped, matching_block: T.nilable(T.proc.params(actual_parameters: T.untyped).void)).returns(Mocha::Expectation) }
22
- def with(*expected_parameters, &matching_block); end
21
+ sig { params(expected_parameters_or_matchers: T.untyped, kwargs: T.untyped, matching_block: T.nilable(T.proc.params(actual_parameters: T.untyped).void)).returns(Mocha::Expectation) }
22
+ def with(*expected_parameters_or_matchers, **kwargs, &matching_block); end
23
23
 
24
24
  sig { params(values: T.untyped).returns(Mocha::Expectation) }
25
25
  def returns(*values); end
data/whatsapp_sdk.gemspec CHANGED
@@ -49,7 +49,6 @@ Gem::Specification.new do |spec|
49
49
 
50
50
  spec.add_dependency("faraday", "~> 2.3.0")
51
51
  spec.add_dependency("faraday-multipart", "~> 1.0.4")
52
- spec.add_dependency("oj", "~> 3.13.13")
53
52
  spec.add_dependency("zeitwerk", "~> 2.6.0")
54
53
  spec.metadata['rubygems_mfa_required'] = 'true'
55
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whatsapp_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ignacio-chiazzo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-24 00:00:00.000000000 Z
11
+ date: 2023-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,20 +108,6 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 1.0.4
111
- - !ruby/object:Gem::Dependency
112
- name: oj
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: 3.13.13
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: 3.13.13
125
111
  - !ruby/object:Gem::Dependency
126
112
  name: zeitwerk
127
113
  requirement: !ruby/object:Gem::Requirement
@@ -195,6 +181,15 @@ files:
195
181
  - lib/whatsapp_sdk/resource/currency.rb
196
182
  - lib/whatsapp_sdk/resource/date_time.rb
197
183
  - lib/whatsapp_sdk/resource/email.rb
184
+ - lib/whatsapp_sdk/resource/error.rb
185
+ - lib/whatsapp_sdk/resource/interactive.rb
186
+ - lib/whatsapp_sdk/resource/interactive_action.rb
187
+ - lib/whatsapp_sdk/resource/interactive_action_reply_button.rb
188
+ - lib/whatsapp_sdk/resource/interactive_action_section.rb
189
+ - lib/whatsapp_sdk/resource/interactive_action_section_row.rb
190
+ - lib/whatsapp_sdk/resource/interactive_body.rb
191
+ - lib/whatsapp_sdk/resource/interactive_footer.rb
192
+ - lib/whatsapp_sdk/resource/interactive_header.rb
198
193
  - lib/whatsapp_sdk/resource/media.rb
199
194
  - lib/whatsapp_sdk/resource/message.rb
200
195
  - lib/whatsapp_sdk/resource/name.rb