whatsapp_sdk 0.12.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/codeql-analysis.yml +8 -6
- data/.gitignore +1 -0
- data/.rubocop.yml +0 -3
- data/CHANGELOG.md +9 -7
- data/Gemfile +0 -4
- data/Gemfile.lock +1 -20
- data/README.md +35 -55
- data/SECURITY.md +21 -0
- data/example.rb +23 -15
- data/lib/whatsapp_sdk/api/api_configuration.rb +2 -5
- data/lib/whatsapp_sdk/api/business_profile.rb +0 -12
- data/lib/whatsapp_sdk/api/client.rb +7 -43
- data/lib/whatsapp_sdk/api/medias.rb +8 -15
- data/lib/whatsapp_sdk/api/messages.rb +4 -81
- data/lib/whatsapp_sdk/api/phone_numbers.rb +0 -14
- data/lib/whatsapp_sdk/api/request.rb +0 -2
- data/lib/whatsapp_sdk/api/response.rb +1 -20
- data/lib/whatsapp_sdk/api/responses/business_profile_data_response.rb +11 -34
- data/lib/whatsapp_sdk/api/responses/data_response.rb +0 -9
- data/lib/whatsapp_sdk/api/responses/error_response.rb +1 -8
- data/lib/whatsapp_sdk/api/responses/generic_error_response.rb +8 -26
- data/lib/whatsapp_sdk/api/responses/media_data_response.rb +8 -26
- data/lib/whatsapp_sdk/api/responses/message_data_response.rb +4 -20
- data/lib/whatsapp_sdk/api/responses/message_error_response.rb +0 -1
- data/lib/whatsapp_sdk/api/responses/message_template_namespace_data_response.rb +3 -13
- data/lib/whatsapp_sdk/api/responses/phone_number_data_response.rb +19 -37
- data/lib/whatsapp_sdk/api/responses/phone_numbers_data_response.rb +2 -9
- data/lib/whatsapp_sdk/api/responses/read_message_data_response.rb +1 -6
- data/lib/whatsapp_sdk/api/responses/success_response.rb +1 -5
- data/lib/whatsapp_sdk/api/responses/template_data_response.rb +2 -7
- data/lib/whatsapp_sdk/api/responses/templates_data_response.rb +2 -9
- data/lib/whatsapp_sdk/api/templates.rb +3 -27
- data/lib/whatsapp_sdk/configuration.rb +2 -24
- data/lib/whatsapp_sdk/error.rb +0 -1
- data/lib/whatsapp_sdk/resource/address.rb +1 -30
- data/lib/whatsapp_sdk/resource/address_type.rb +3 -8
- data/lib/whatsapp_sdk/resource/business_profile.rb +0 -3
- data/lib/whatsapp_sdk/resource/button_parameter.rb +4 -20
- data/lib/whatsapp_sdk/resource/component.rb +12 -43
- data/lib/whatsapp_sdk/resource/contact.rb +1 -30
- data/lib/whatsapp_sdk/resource/contact_response.rb +1 -9
- data/lib/whatsapp_sdk/resource/currency.rb +0 -8
- data/lib/whatsapp_sdk/resource/date_time.rb +0 -6
- data/lib/whatsapp_sdk/resource/email.rb +1 -10
- data/lib/whatsapp_sdk/resource/errors.rb +1 -17
- data/lib/whatsapp_sdk/resource/interactive.rb +6 -27
- data/lib/whatsapp_sdk/resource/interactive_action.rb +10 -24
- data/lib/whatsapp_sdk/resource/interactive_action_reply_button.rb +5 -19
- data/lib/whatsapp_sdk/resource/interactive_action_section.rb +1 -11
- data/lib/whatsapp_sdk/resource/interactive_action_section_row.rb +0 -11
- data/lib/whatsapp_sdk/resource/interactive_body.rb +0 -10
- data/lib/whatsapp_sdk/resource/interactive_footer.rb +0 -10
- data/lib/whatsapp_sdk/resource/interactive_header.rb +25 -53
- data/lib/whatsapp_sdk/resource/location.rb +44 -0
- data/lib/whatsapp_sdk/resource/media.rb +10 -46
- data/lib/whatsapp_sdk/resource/media_types.rb +0 -3
- data/lib/whatsapp_sdk/resource/message.rb +0 -5
- data/lib/whatsapp_sdk/resource/name.rb +1 -28
- data/lib/whatsapp_sdk/resource/org.rb +1 -13
- data/lib/whatsapp_sdk/resource/parameter_object.rb +71 -74
- data/lib/whatsapp_sdk/resource/phone_number.rb +1 -13
- data/lib/whatsapp_sdk/resource/template.rb +23 -36
- data/lib/whatsapp_sdk/resource/url.rb +1 -10
- data/lib/whatsapp_sdk/version.rb +1 -2
- data/lib/whatsapp_sdk.rb +0 -4
- data/whatsapp_sdk.gemspec +0 -3
- metadata +5 -49
- data/sorbet/config +0 -6
- data/sorbet/rbi/annotations/faraday.rbi +0 -17
- data/sorbet/rbi/annotations/mocha.rbi +0 -34
- data/sorbet/rbi/annotations/rainbow.rbi +0 -269
- data/sorbet/rbi/gems/faraday-multipart@1.0.4.rbi +0 -270
- data/sorbet/rbi/gems/faraday-net_http@2.0.3.rbi +0 -182
- data/sorbet/rbi/gems/faraday@2.3.0.rbi +0 -2494
- data/sorbet/rbi/gems/method_source@1.0.0.rbi +0 -272
- data/sorbet/rbi/gems/minitest@5.16.1.rbi +0 -1459
- data/sorbet/rbi/gems/mocha@1.14.0.rbi +0 -60
- data/sorbet/rbi/gems/multipart-post@2.2.3.rbi +0 -239
- data/sorbet/rbi/gems/netrc@0.11.0.rbi +0 -150
- data/sorbet/rbi/gems/oj@3.13.14.rbi +0 -589
- data/sorbet/rbi/gems/zeitwerk@2.6.0.rbi +0 -867
- data/sorbet/rbi/todo.rbi +0 -8
- data/sorbet/shims/request.rbi +0 -10
- data/sorbet/tapioca/config.yml +0 -13
- data/sorbet/tapioca/require.rb +0 -4
@@ -1,26 +1,18 @@
|
|
1
|
-
# typed: strict
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module WhatsappSdk
|
5
4
|
module Resource
|
6
5
|
class InteractiveHeader
|
7
|
-
extend T::Sig
|
8
|
-
|
9
6
|
# Returns the interactive header type.
|
10
7
|
#
|
11
8
|
# @returns type [String] Valid options are text, image, document, video.
|
12
|
-
sig { returns(Type) }
|
13
9
|
attr_accessor :type
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
Image = new("image")
|
21
|
-
Document = new("document")
|
22
|
-
Video = new("video")
|
23
|
-
end
|
11
|
+
module Type
|
12
|
+
TEXT = "text"
|
13
|
+
IMAGE = "image"
|
14
|
+
DOCUMENT = "document"
|
15
|
+
VIDEO = "video"
|
24
16
|
end
|
25
17
|
|
26
18
|
# Returns Text string if the interactive header type is text.
|
@@ -28,35 +20,25 @@ module WhatsappSdk
|
|
28
20
|
# For the body interactive, the character limit is 1024 characters.
|
29
21
|
#
|
30
22
|
# @returns text [String]
|
31
|
-
sig { returns(T.nilable(String)) }
|
32
23
|
attr_accessor :text
|
33
24
|
|
34
25
|
# Returns image if the interactive header type is image.
|
35
26
|
#
|
36
27
|
# @returns image [Media]
|
37
|
-
sig { returns(T.nilable(Media)) }
|
38
28
|
attr_accessor :image
|
39
29
|
|
40
30
|
# Returns document if the interactive header type is document.
|
41
31
|
#
|
42
32
|
# @returns document [Media]
|
43
|
-
sig { returns(T.nilable(Media)) }
|
44
33
|
attr_accessor :document
|
45
34
|
|
46
35
|
# Returns video if the interactive header type is video.
|
47
36
|
#
|
48
37
|
# @returns video [Media]
|
49
|
-
sig { returns(T.nilable(Media)) }
|
50
38
|
attr_accessor :video
|
51
39
|
|
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
40
|
def initialize(type:, text: nil, image: nil, document: nil, video: nil)
|
59
|
-
@type =
|
41
|
+
@type = type
|
60
42
|
@text = text
|
61
43
|
@image = image
|
62
44
|
@document = document
|
@@ -64,54 +46,44 @@ module WhatsappSdk
|
|
64
46
|
validate
|
65
47
|
end
|
66
48
|
|
67
|
-
sig { returns(T::Hash[T.untyped, T.untyped]) }
|
68
49
|
def to_json
|
69
|
-
json = { type: type
|
70
|
-
json[type.
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
50
|
+
json = { type: type }
|
51
|
+
json[type.to_sym] = case type
|
52
|
+
when "text"
|
53
|
+
text
|
54
|
+
when "image"
|
55
|
+
image.to_json
|
56
|
+
when "document"
|
57
|
+
document.to_json
|
58
|
+
when "video"
|
59
|
+
video.to_json
|
60
|
+
else
|
61
|
+
raise "Invalid type: #{type}"
|
62
|
+
end
|
82
63
|
|
83
64
|
json
|
84
65
|
end
|
85
66
|
|
86
67
|
private
|
87
68
|
|
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
69
|
def validate
|
97
70
|
validate_attributes
|
98
71
|
end
|
99
72
|
|
100
|
-
sig { void }
|
101
73
|
def validate_attributes
|
102
74
|
[
|
103
|
-
[Type::
|
104
|
-
[Type::
|
105
|
-
[Type::
|
106
|
-
[Type::
|
75
|
+
[Type::TEXT, text],
|
76
|
+
[Type::IMAGE, image],
|
77
|
+
[Type::DOCUMENT, document],
|
78
|
+
[Type::VIDEO, video]
|
107
79
|
].each do |type_b, value|
|
108
80
|
next unless type == type_b
|
109
81
|
|
110
82
|
next unless value.nil?
|
111
83
|
|
112
84
|
raise Resource::Errors::MissingValue.new(
|
113
|
-
type
|
114
|
-
"#{type
|
85
|
+
type,
|
86
|
+
"#{type} is required when the type is #{type_b}"
|
115
87
|
)
|
116
88
|
end
|
117
89
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# typed: false
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module WhatsappSdk
|
5
|
+
module Resource
|
6
|
+
class Location
|
7
|
+
# Returns the latitude of the location.
|
8
|
+
#
|
9
|
+
# @returns latitude [Float].
|
10
|
+
attr_accessor :latitude
|
11
|
+
|
12
|
+
# Returns the longitude of the location.
|
13
|
+
#
|
14
|
+
# @returns longitude [Float].
|
15
|
+
attr_accessor :longitude
|
16
|
+
|
17
|
+
# Returns the name of the location.
|
18
|
+
#
|
19
|
+
# @returns name [String].
|
20
|
+
attr_accessor :name
|
21
|
+
|
22
|
+
# Returns the address of the location.
|
23
|
+
#
|
24
|
+
# @returns address [String].
|
25
|
+
attr_accessor :address
|
26
|
+
|
27
|
+
def initialize(latitude:, longitude:, name:, address:)
|
28
|
+
@latitude = latitude
|
29
|
+
@longitude = longitude
|
30
|
+
@name = name
|
31
|
+
@address = address
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_json
|
35
|
+
{
|
36
|
+
latitude: latitude,
|
37
|
+
longitude: longitude,
|
38
|
+
name: name,
|
39
|
+
address: address
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,21 +1,11 @@
|
|
1
|
-
# typed: strict
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module WhatsappSdk
|
5
4
|
module Resource
|
6
5
|
class Media
|
7
|
-
extend T::Sig
|
8
|
-
|
9
6
|
class InvalidMedia < StandardError
|
10
|
-
|
11
|
-
|
12
|
-
sig { returns(Symbol) }
|
13
|
-
attr_reader :field
|
14
|
-
|
15
|
-
sig { returns(String) }
|
16
|
-
attr_reader :message
|
7
|
+
attr_reader :field, :message
|
17
8
|
|
18
|
-
sig { params(field: Symbol, message: String).void }
|
19
9
|
def initialize(field, message)
|
20
10
|
@field = field
|
21
11
|
@message = message
|
@@ -26,52 +16,37 @@ module WhatsappSdk
|
|
26
16
|
# Returns media id.
|
27
17
|
#
|
28
18
|
# @returns id [String].
|
29
|
-
sig { returns(T.nilable(String)) }
|
30
19
|
attr_accessor :id
|
31
20
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
Image = new('image')
|
39
|
-
Video = new('video')
|
40
|
-
Sticker = new('sticker')
|
41
|
-
end
|
21
|
+
module Type
|
22
|
+
AUDIO = 'audio'
|
23
|
+
DOCUMENT = 'document'
|
24
|
+
IMAGE = 'image'
|
25
|
+
VIDEO = 'video'
|
26
|
+
STICKER = 'sticker'
|
42
27
|
end
|
43
28
|
|
44
29
|
# @returns type [String]. Valid options ar audio, document, image, video and sticker.
|
45
|
-
sig { returns(Type) }
|
46
30
|
attr_accessor :type
|
47
31
|
|
48
32
|
# The protocol and URL of the media to be sent. Use only with HTTP/HTTPS URLs.
|
49
33
|
# Do not use this field when the message type is set to text.
|
50
34
|
#
|
51
35
|
# @returns link [String].
|
52
|
-
sig { returns(T.nilable(String)) }
|
53
36
|
attr_accessor :link
|
54
37
|
|
55
38
|
# Describes the specified document or image media.
|
56
39
|
#
|
57
40
|
# @returns caption [String].
|
58
|
-
sig { returns(T.nilable(String)) }
|
59
41
|
attr_accessor :caption
|
60
42
|
|
61
43
|
# Describes the filename for the specific document. Use only with document media.
|
62
44
|
#
|
63
45
|
# @returns filename [String].
|
64
|
-
sig { returns(T.nilable(String)) }
|
65
46
|
attr_accessor :filename
|
66
47
|
|
67
|
-
sig do
|
68
|
-
params(
|
69
|
-
type: T.any(Type, String), id: T.nilable(String), link: T.nilable(String),
|
70
|
-
caption: T.nilable(String), filename: T.nilable(String)
|
71
|
-
).void
|
72
|
-
end
|
73
48
|
def initialize(type:, id: nil, link: nil, caption: nil, filename: nil)
|
74
|
-
@type =
|
49
|
+
@type = type
|
75
50
|
@id = id
|
76
51
|
@link = link
|
77
52
|
@caption = caption
|
@@ -79,7 +54,6 @@ module WhatsappSdk
|
|
79
54
|
validate_media
|
80
55
|
end
|
81
56
|
|
82
|
-
sig { returns(T::Hash[T.untyped, T.untyped]) }
|
83
57
|
def to_json
|
84
58
|
json = {}
|
85
59
|
json[:id] = id unless id.nil?
|
@@ -91,14 +65,6 @@ module WhatsappSdk
|
|
91
65
|
|
92
66
|
private
|
93
67
|
|
94
|
-
sig { params(type: T.any(String, Type)).returns(Type) }
|
95
|
-
def deserialize_type(type)
|
96
|
-
return type if type.is_a?(Type)
|
97
|
-
|
98
|
-
Type.deserialize(type)
|
99
|
-
end
|
100
|
-
|
101
|
-
sig { returns(T::Boolean) }
|
102
68
|
def validate_media
|
103
69
|
raise InvalidMedia.new(:filename, "filename can only be used with document") if filename && !supports_filename?
|
104
70
|
|
@@ -109,14 +75,12 @@ module WhatsappSdk
|
|
109
75
|
true
|
110
76
|
end
|
111
77
|
|
112
|
-
sig { returns(T::Boolean) }
|
113
78
|
def supports_filename?
|
114
|
-
type == Type::
|
79
|
+
type == Type::DOCUMENT
|
115
80
|
end
|
116
81
|
|
117
|
-
sig { returns(T::Boolean) }
|
118
82
|
def supports_caption?
|
119
|
-
type == Type::
|
83
|
+
type == Type::DOCUMENT || type == Type::IMAGE
|
120
84
|
end
|
121
85
|
end
|
122
86
|
end
|
@@ -1,11 +1,8 @@
|
|
1
|
-
# typed: strict
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module WhatsappSdk
|
5
4
|
module Resource
|
6
5
|
class MediaTypes
|
7
|
-
extend T::Sig
|
8
|
-
|
9
6
|
# The media types supported by Whatsapp. The list contains all the types defined in the Whatsapp API
|
10
7
|
# documentation: https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#supported-media-types
|
11
8
|
#
|
@@ -1,36 +1,10 @@
|
|
1
|
-
# typed: strict
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module WhatsappSdk
|
5
4
|
module Resource
|
6
5
|
class Name
|
7
|
-
|
6
|
+
attr_accessor :formatted_name, :first_name, :last_name, :middle_name, :suffix, :prefix
|
8
7
|
|
9
|
-
sig { returns(T.nilable(String)) }
|
10
|
-
attr_accessor :formatted_name
|
11
|
-
|
12
|
-
sig { returns(T.nilable(String)) }
|
13
|
-
attr_accessor :first_name
|
14
|
-
|
15
|
-
sig { returns(T.nilable(String)) }
|
16
|
-
attr_accessor :last_name
|
17
|
-
|
18
|
-
sig { returns(T.nilable(String)) }
|
19
|
-
attr_accessor :middle_name
|
20
|
-
|
21
|
-
sig { returns(T.nilable(String)) }
|
22
|
-
attr_accessor :suffix
|
23
|
-
|
24
|
-
sig { returns(T.nilable(String)) }
|
25
|
-
attr_accessor :prefix
|
26
|
-
|
27
|
-
sig do
|
28
|
-
params(
|
29
|
-
formatted_name: T.nilable(String), first_name: T.nilable(String),
|
30
|
-
last_name: T.nilable(String), middle_name: T.nilable(String),
|
31
|
-
suffix: T.nilable(String), prefix: T.nilable(String)
|
32
|
-
).void
|
33
|
-
end
|
34
8
|
def initialize(
|
35
9
|
formatted_name: nil, first_name: nil,
|
36
10
|
last_name: nil, middle_name: nil, suffix: nil, prefix: nil
|
@@ -43,7 +17,6 @@ module WhatsappSdk
|
|
43
17
|
@prefix = prefix
|
44
18
|
end
|
45
19
|
|
46
|
-
sig { returns(T::Hash[T.untyped, T.untyped]) }
|
47
20
|
def to_h
|
48
21
|
{
|
49
22
|
formatted_name: @formatted_name,
|
@@ -1,28 +1,16 @@
|
|
1
|
-
# typed: strict
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module WhatsappSdk
|
5
4
|
module Resource
|
6
5
|
class Org
|
7
|
-
|
6
|
+
attr_accessor :company, :department, :title
|
8
7
|
|
9
|
-
sig { returns(String) }
|
10
|
-
attr_accessor :company
|
11
|
-
|
12
|
-
sig { returns(String) }
|
13
|
-
attr_accessor :department
|
14
|
-
|
15
|
-
sig { returns(String) }
|
16
|
-
attr_accessor :title
|
17
|
-
|
18
|
-
sig { params(company: String, department: String, title: String).void }
|
19
8
|
def initialize(company:, department:, title:)
|
20
9
|
@company = company
|
21
10
|
@department = department
|
22
11
|
@title = title
|
23
12
|
end
|
24
13
|
|
25
|
-
sig { returns(T::Hash[T.untyped, T.untyped]) }
|
26
14
|
def to_h
|
27
15
|
{
|
28
16
|
company: @company,
|
@@ -1,23 +1,14 @@
|
|
1
|
-
# typed: strict
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module WhatsappSdk
|
5
4
|
module Resource
|
6
5
|
class ParameterObject
|
7
|
-
extend T::Sig
|
8
|
-
|
9
6
|
class InvalidType < StandardError
|
10
|
-
extend T::Sig
|
11
|
-
|
12
|
-
sig { returns(String) }
|
13
7
|
attr_accessor :message
|
14
8
|
|
15
|
-
sig { params(type: String).void }
|
16
9
|
def initialize(type)
|
17
|
-
@message =
|
18
|
-
|
19
|
-
String
|
20
|
-
)
|
10
|
+
@message = "invalid type #{type}. type should be text, currency, date_time, image, document or video"
|
11
|
+
|
21
12
|
super
|
22
13
|
end
|
23
14
|
end
|
@@ -25,19 +16,29 @@ module WhatsappSdk
|
|
25
16
|
# Returns the parameter type.
|
26
17
|
#
|
27
18
|
# @returns type [String] Valid options are text, currency, date_time, image, document, video.
|
28
|
-
sig { returns(Type) }
|
29
19
|
attr_accessor :type
|
30
20
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
21
|
+
module Type
|
22
|
+
TEXT = "text"
|
23
|
+
CURRENCY = "currency"
|
24
|
+
DATE_TIME = "date_time"
|
25
|
+
IMAGE = "image"
|
26
|
+
DOCUMENT = "document"
|
27
|
+
VIDEO = "video"
|
28
|
+
LOCATION = "location"
|
29
|
+
|
30
|
+
TYPES = [
|
31
|
+
TEXT,
|
32
|
+
CURRENCY,
|
33
|
+
DATE_TIME,
|
34
|
+
IMAGE,
|
35
|
+
DOCUMENT,
|
36
|
+
VIDEO,
|
37
|
+
LOCATION
|
38
|
+
].freeze
|
39
|
+
|
40
|
+
def self.valid?(type)
|
41
|
+
TYPES.include?(type)
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
@@ -46,117 +47,113 @@ module WhatsappSdk
|
|
46
47
|
# For the body component, the character limit is 1024 characters.
|
47
48
|
#
|
48
49
|
# @returns text [String]
|
49
|
-
sig { returns(T.nilable(String)) }
|
50
50
|
attr_accessor :text
|
51
51
|
|
52
52
|
# Returns Currency if the parameter object type is currency.
|
53
53
|
#
|
54
54
|
# @returns currency [Currency]
|
55
|
-
sig { returns(T.nilable(Currency)) }
|
56
55
|
attr_accessor :currency
|
57
56
|
|
58
57
|
# Returns date_time if the parameter object type is date_time.
|
59
58
|
#
|
60
59
|
# @returns date_time [DateTime]
|
61
|
-
sig { returns(T.nilable(DateTime)) }
|
62
60
|
attr_accessor :date_time
|
63
61
|
|
64
62
|
# Returns image if the parameter object type is image.
|
65
63
|
#
|
66
64
|
# @returns image [Media]
|
67
|
-
sig { returns(T.nilable(Media)) }
|
68
65
|
attr_accessor :image
|
69
66
|
|
70
67
|
# Returns document if the parameter object type is document.
|
71
68
|
#
|
72
69
|
# @returns document [Media]
|
73
|
-
sig { returns(T.nilable(Media)) }
|
74
70
|
attr_accessor :document
|
75
71
|
|
76
72
|
# Returns video if the parameter object type is video.
|
77
73
|
#
|
78
74
|
# @returns video [Media]
|
79
|
-
sig { returns(T.nilable(Media)) }
|
80
75
|
attr_accessor :video
|
81
76
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
77
|
+
# Returns location if the parameter object type is location
|
78
|
+
#
|
79
|
+
# @returns location [Location]
|
80
|
+
attr_accessor :location
|
81
|
+
|
82
|
+
def initialize(
|
83
|
+
type:,
|
84
|
+
text: nil,
|
85
|
+
currency: nil,
|
86
|
+
date_time: nil,
|
87
|
+
image: nil,
|
88
|
+
document: nil,
|
89
|
+
video: nil,
|
90
|
+
location: nil
|
91
|
+
)
|
92
|
+
@type = type
|
90
93
|
@text = text
|
91
94
|
@currency = currency
|
92
95
|
@date_time = date_time
|
93
96
|
@image = image
|
94
97
|
@document = document
|
95
98
|
@video = video
|
99
|
+
@location = location
|
96
100
|
validate
|
97
101
|
end
|
98
102
|
|
99
|
-
sig { returns(T::Hash[T.untyped, T.untyped]) }
|
100
103
|
def to_json
|
101
|
-
json = { type: type
|
102
|
-
json[type.
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
104
|
+
json = { type: type }
|
105
|
+
json[type.to_sym] = case type
|
106
|
+
when "text"
|
107
|
+
text
|
108
|
+
when "currency"
|
109
|
+
currency.to_json
|
110
|
+
when "date_time"
|
111
|
+
date_time.to_json
|
112
|
+
when "image"
|
113
|
+
image.to_json
|
114
|
+
when "document"
|
115
|
+
document.to_json
|
116
|
+
when "video"
|
117
|
+
video.to_json
|
118
|
+
when "location"
|
119
|
+
location.to_json
|
120
|
+
else
|
121
|
+
raise "Invalid type: #{type}"
|
122
|
+
end
|
118
123
|
|
119
124
|
json
|
120
125
|
end
|
121
126
|
|
122
127
|
private
|
123
128
|
|
124
|
-
sig { params(type: T.any(String, Type)).returns(Type) }
|
125
|
-
def deserialize_type(type)
|
126
|
-
return type if type.is_a?(Type)
|
127
|
-
|
128
|
-
Type.deserialize(type)
|
129
|
-
end
|
130
|
-
|
131
|
-
sig { void }
|
132
129
|
def validate
|
133
130
|
validate_attributes
|
134
131
|
validate_type
|
135
132
|
end
|
136
133
|
|
137
|
-
sig { void }
|
138
134
|
def validate_type
|
139
135
|
return if Type.valid?(type)
|
140
136
|
|
141
137
|
raise InvalidType, type
|
142
138
|
end
|
143
139
|
|
144
|
-
sig { void }
|
145
140
|
def validate_attributes
|
146
141
|
[
|
147
|
-
[Type::
|
148
|
-
[Type::
|
149
|
-
[Type::
|
150
|
-
[Type::
|
151
|
-
[Type::
|
152
|
-
[Type::
|
142
|
+
[Type::TEXT, text],
|
143
|
+
[Type::CURRENCY, currency],
|
144
|
+
[Type::DATE_TIME, date_time],
|
145
|
+
[Type::IMAGE, image],
|
146
|
+
[Type::DOCUMENT, document],
|
147
|
+
[Type::VIDEO, video],
|
148
|
+
[Type::LOCATION, location]
|
153
149
|
].each do |type_b, value|
|
154
150
|
next unless type == type_b
|
151
|
+
next unless value.nil?
|
155
152
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
153
|
+
raise Errors::MissingValue.new(
|
154
|
+
type,
|
155
|
+
"#{type_b} is required when the type is #{type_b}"
|
156
|
+
)
|
160
157
|
end
|
161
158
|
end
|
162
159
|
end
|
@@ -1,28 +1,16 @@
|
|
1
|
-
# typed: strict
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module WhatsappSdk
|
5
4
|
module Resource
|
6
5
|
class PhoneNumber
|
7
|
-
|
6
|
+
attr_accessor :phone, :wa_id, :type
|
8
7
|
|
9
|
-
sig { returns(String) }
|
10
|
-
attr_accessor :phone
|
11
|
-
|
12
|
-
sig { returns(String) }
|
13
|
-
attr_accessor :wa_id
|
14
|
-
|
15
|
-
sig { returns(AddressType) }
|
16
|
-
attr_accessor :type
|
17
|
-
|
18
|
-
sig { params(phone: String, type: AddressType, wa_id: String).void }
|
19
8
|
def initialize(phone:, type:, wa_id:)
|
20
9
|
@phone = phone
|
21
10
|
@type = type
|
22
11
|
@wa_id = wa_id
|
23
12
|
end
|
24
13
|
|
25
|
-
sig { returns(T::Hash[T.untyped, T.untyped]) }
|
26
14
|
def to_h
|
27
15
|
{
|
28
16
|
phone: @phone,
|