whatsapp_sdk 0.3.0 → 0.4.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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +21 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +14 -0
  4. data/.github/workflows/codeql-analysis.yml +72 -0
  5. data/.gitignore +1 -0
  6. data/.rubocop.yml +14 -0
  7. data/CHANGELOG.md +8 -1
  8. data/Gemfile +6 -0
  9. data/Gemfile.lock +48 -1
  10. data/README.md +107 -33
  11. data/Rakefile +1 -0
  12. data/bin/tapioca +30 -0
  13. data/example.rb +23 -20
  14. data/lib/version.rb +2 -1
  15. data/lib/whatsapp_sdk/api/client.rb +14 -3
  16. data/lib/whatsapp_sdk/api/medias.rb +12 -3
  17. data/lib/whatsapp_sdk/api/messages.rb +72 -14
  18. data/lib/whatsapp_sdk/api/phone_numbers.rb +3 -0
  19. data/lib/whatsapp_sdk/api/request.rb +2 -2
  20. data/lib/whatsapp_sdk/api/response.rb +17 -1
  21. data/lib/whatsapp_sdk/api/responses/data_response.rb +10 -3
  22. data/lib/whatsapp_sdk/api/responses/error_response.rb +8 -1
  23. data/lib/whatsapp_sdk/api/responses/media_data_response.rb +26 -7
  24. data/lib/whatsapp_sdk/api/responses/message_data_response.rb +20 -3
  25. data/lib/whatsapp_sdk/api/responses/message_error_response.rb +26 -7
  26. data/lib/whatsapp_sdk/api/responses/phone_number_data_response.rb +18 -5
  27. data/lib/whatsapp_sdk/api/responses/phone_numbers_data_response.rb +9 -1
  28. data/lib/whatsapp_sdk/api/responses/read_message_data_response.rb +10 -3
  29. data/lib/whatsapp_sdk/api/responses/success_response.rb +5 -1
  30. data/lib/whatsapp_sdk/configuration.rb +7 -14
  31. data/lib/whatsapp_sdk/error.rb +1 -0
  32. data/lib/whatsapp_sdk/resource/address.rb +30 -6
  33. data/lib/whatsapp_sdk/resource/address_type.rb +15 -0
  34. data/lib/whatsapp_sdk/resource/button_parameter.rb +19 -23
  35. data/lib/whatsapp_sdk/resource/component.rb +45 -13
  36. data/lib/whatsapp_sdk/resource/contact.rb +30 -1
  37. data/lib/whatsapp_sdk/resource/contact_response.rb +9 -1
  38. data/lib/whatsapp_sdk/resource/currency.rb +9 -1
  39. data/lib/whatsapp_sdk/resource/date_time.rb +7 -1
  40. data/lib/whatsapp_sdk/resource/email.rb +9 -5
  41. data/lib/whatsapp_sdk/resource/media.rb +44 -15
  42. data/lib/whatsapp_sdk/resource/message.rb +5 -0
  43. data/lib/whatsapp_sdk/resource/name.rb +28 -1
  44. data/lib/whatsapp_sdk/resource/org.rb +13 -1
  45. data/lib/whatsapp_sdk/resource/parameter_object.rb +82 -39
  46. data/lib/whatsapp_sdk/resource/phone_number.rb +12 -5
  47. data/lib/whatsapp_sdk/resource/url.rb +9 -5
  48. data/lib/whatsapp_sdk.rb +19 -33
  49. data/sorbet/config +6 -0
  50. data/sorbet/rbi/annotations/faraday.rbi +17 -0
  51. data/sorbet/rbi/annotations/mocha.rbi +34 -0
  52. data/sorbet/rbi/annotations/rainbow.rbi +269 -0
  53. data/sorbet/rbi/gems/faraday-multipart@1.0.4.rbi +270 -0
  54. data/sorbet/rbi/gems/faraday-net_http@2.0.3.rbi +182 -0
  55. data/sorbet/rbi/gems/faraday@2.3.0.rbi +2494 -0
  56. data/sorbet/rbi/gems/method_source@1.0.0.rbi +272 -0
  57. data/sorbet/rbi/gems/minitest@5.16.1.rbi +1459 -0
  58. data/sorbet/rbi/gems/mocha@1.14.0.rbi +60 -0
  59. data/sorbet/rbi/gems/multipart-post@2.2.3.rbi +239 -0
  60. data/sorbet/rbi/gems/netrc@0.11.0.rbi +150 -0
  61. data/sorbet/rbi/gems/oj@3.13.14.rbi +589 -0
  62. data/sorbet/rbi/gems/zeitwerk@2.6.0.rbi +867 -0
  63. data/sorbet/rbi/todo.rbi +8 -0
  64. data/sorbet/shims/request.rbi +10 -0
  65. data/sorbet/tapioca/config.yml +13 -0
  66. data/sorbet/tapioca/require.rb +5 -0
  67. data/whatsapp_sdk.gemspec +5 -1
  68. metadata +67 -2
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  require_relative "error_response"
4
5
 
@@ -6,18 +7,36 @@ module WhatsappSdk
6
7
  module Api
7
8
  module Responses
8
9
  class MessageErrorResponse < ErrorResponse
9
- attr_reader :code, :subcode, :message, :type, :data, :fbtrace_id
10
+ sig { returns(Integer) }
11
+ attr_reader :code
10
12
 
13
+ sig { returns(T.nilable(Integer)) }
14
+ attr_reader :subcode
15
+
16
+ sig { returns(T.nilable(String)) }
17
+ attr_reader :message
18
+
19
+ sig { returns(T.nilable(String)) }
20
+ attr_reader :type
21
+
22
+ sig { returns(T.nilable(String)) }
23
+ attr_reader :data
24
+
25
+ sig { returns(T.nilable(String)) }
26
+ attr_reader :fbtrace_id
27
+
28
+ sig { params(response: T::Hash[T.untyped, T.untyped]).void }
11
29
  def initialize(response:)
12
- @code = response["code"]
13
- @subcode = response["error_subcode"]
14
- @message = response["message"]
15
- @type = response["type"]
16
- @data = response["data"]
17
- @fbtrace_id = response["fbtrace_id"]
30
+ @code = T.let(response["code"], Integer)
31
+ @subcode = T.let(response["error_subcode"], T.nilable(Integer))
32
+ @message = T.let(response["message"], T.nilable(String))
33
+ @type = T.let(response["type"], T.nilable(String))
34
+ @data = T.let(response["data"], T.nilable(String))
35
+ @fbtrace_id = T.let(response["fbtrace_id"], T.nilable(String))
18
36
  super(response: response)
19
37
  end
20
38
 
39
+ sig { override.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(MessageErrorResponse)) }
21
40
  def self.build_from_response(response:)
22
41
  error_response = response["error"]
23
42
  return unless error_response
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  require_relative "data_response"
4
5
 
@@ -6,16 +7,28 @@ module WhatsappSdk
6
7
  module Api
7
8
  module Responses
8
9
  class PhoneNumberDataResponse < DataResponse
9
- attr_accessor :id, :verified_name, :display_phone_number, :quality_rating
10
+ sig { returns(String) }
11
+ attr_accessor :id
10
12
 
13
+ sig { returns(String) }
14
+ attr_accessor :verified_name
15
+
16
+ sig { returns(String) }
17
+ attr_accessor :display_phone_number
18
+
19
+ sig { returns(String) }
20
+ attr_accessor :quality_rating
21
+
22
+ sig { params(response: T::Hash[T.untyped, T.untyped]).void }
11
23
  def initialize(response)
12
- @id = response["id"]
13
- @verified_name = response["verified_name"]
14
- @display_phone_number = response["display_phone_number"]
15
- @quality_rating = response["quality_rating"]
24
+ @id = T.let(response["id"], String)
25
+ @verified_name = T.let(response["verified_name"], String)
26
+ @display_phone_number = T.let(response["display_phone_number"], String)
27
+ @quality_rating = T.let(response["quality_rating"], String)
16
28
  super(response)
17
29
  end
18
30
 
31
+ sig { override.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(PhoneNumberDataResponse)) }
19
32
  def self.build_from_response(response:)
20
33
  return unless response["id"]
21
34
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  require_relative "data_response"
4
5
  require_relative "phone_number_data_response"
@@ -7,13 +8,19 @@ module WhatsappSdk
7
8
  module Api
8
9
  module Responses
9
10
  class PhoneNumbersDataResponse < DataResponse
11
+ sig { returns(T::Array[PhoneNumberDataResponse]) }
10
12
  attr_reader :phone_numbers
11
13
 
14
+ sig { params(response: T::Hash[T.untyped, T.untyped]).void }
12
15
  def initialize(response)
13
- @phone_numbers = response['data']&.map { |phone_number| parse_phone_number(phone_number) }
16
+ @phone_numbers = T.let(
17
+ response['data']&.map { |phone_number| parse_phone_number(phone_number) },
18
+ T::Array[PhoneNumberDataResponse]
19
+ )
14
20
  super(response)
15
21
  end
16
22
 
23
+ sig { override.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(PhoneNumbersDataResponse)) }
17
24
  def self.build_from_response(response:)
18
25
  return unless response["data"]
19
26
 
@@ -22,6 +29,7 @@ module WhatsappSdk
22
29
 
23
30
  private
24
31
 
32
+ sig { params(phone_number: T::Hash[T.untyped, T.untyped]).returns(PhoneNumberDataResponse) }
25
33
  def parse_phone_number(phone_number)
26
34
  PhoneNumberDataResponse.new(phone_number)
27
35
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  require_relative "../request"
4
5
  require_relative "data_response"
@@ -9,18 +10,24 @@ module WhatsappSdk
9
10
  module Api
10
11
  module Responses
11
12
  class ReadMessageDataResponse < DataResponse
12
- attr_reader :success
13
-
13
+ extend T::Sig
14
+ sig { params(response: T::Hash[T.untyped, T.untyped]).void }
14
15
  def initialize(response:)
15
- @success = response["success"]
16
+ @success = T.let(response["success"], T::Boolean)
16
17
  super(response)
17
18
  end
18
19
 
20
+ sig { override.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(ReadMessageDataResponse)) }
19
21
  def self.build_from_response(response:)
20
22
  return if response["error"]
21
23
 
22
24
  new(response: response)
23
25
  end
26
+
27
+ sig { returns(T::Boolean) }
28
+ def success?
29
+ @success
30
+ end
24
31
  end
25
32
  end
26
33
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  require_relative "data_response"
4
5
 
@@ -6,17 +7,20 @@ module WhatsappSdk
6
7
  module Api
7
8
  module Responses
8
9
  class SuccessResponse < DataResponse
10
+ sig { params(response: T::Hash[T.untyped, T.untyped]).void }
9
11
  def initialize(response:)
10
- @success = response["success"]
12
+ @success = T.let(response["success"], T::Boolean)
11
13
  super(response)
12
14
  end
13
15
 
16
+ sig { override.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(SuccessResponse)) }
14
17
  def self.build_from_response(response:)
15
18
  return unless response["success"]
16
19
 
17
20
  new(response: response)
18
21
  end
19
22
 
23
+ sig { returns(T::Boolean) }
20
24
  def success?
21
25
  @success
22
26
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  module WhatsappSdk
4
5
  # This module allows client instantiating the client as a singleton like the following example:
@@ -7,27 +8,19 @@ module WhatsappSdk
7
8
  # end
8
9
  #
9
10
  # The gem have access to the client through WhatsappSdk.configuration.client
10
-
11
- class << self
12
- def configuration
13
- @configuration ||= Configuration.new
14
- end
15
-
16
- def configure
17
- yield(configuration)
18
- end
19
- end
20
-
21
11
  class Configuration
12
+ extend T::Sig
13
+
14
+ sig { returns(String) }
22
15
  attr_accessor :access_token
23
16
 
24
- def initialize(access_token = nil)
17
+ sig { params(access_token: String).void }
18
+ def initialize(access_token = "")
25
19
  @access_token = access_token
26
20
  end
27
21
 
22
+ sig { returns(WhatsappSdk::Api::Client) }
28
23
  def client
29
- return unless access_token
30
-
31
24
  WhatsappSdk::Api::Client.new(access_token)
32
25
  end
33
26
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  module WhatsappSdk
4
5
  class Error < StandardError; end
@@ -1,16 +1,39 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  module WhatsappSdk
4
5
  module Resource
5
6
  class Address
6
- attr_accessor :street, :city, :state, :zip, :country, :country_code, :typ
7
+ extend T::Sig
7
8
 
8
- ADDRESS_TYPE = {
9
- home: "HOME",
10
- work: "WORK"
11
- }.freeze
9
+ sig { returns(String) }
10
+ attr_accessor :street
12
11
 
13
- def initialize(street:, city:, state:, zip:, country:, country_code:, type: ADDRESS_TYPE::HOME)
12
+ sig { returns(String) }
13
+ attr_accessor :city
14
+
15
+ sig { returns(String) }
16
+ attr_accessor :state
17
+
18
+ sig { returns(String) }
19
+ attr_accessor :zip
20
+
21
+ sig { returns(String) }
22
+ attr_accessor :country
23
+
24
+ sig { returns(String) }
25
+ attr_accessor :country_code
26
+
27
+ sig { returns(AddressType) }
28
+ attr_accessor :type
29
+
30
+ sig do
31
+ params(
32
+ street: String, city: String, state: String, zip: String,
33
+ country: String, country_code: String, type: AddressType
34
+ ).void
35
+ end
36
+ def initialize(street:, city:, state:, zip:, country:, country_code:, type: AddressType::Home)
14
37
  @street = street
15
38
  @city = city
16
39
  @state = state
@@ -20,6 +43,7 @@ module WhatsappSdk
20
43
  @type = type
21
44
  end
22
45
 
46
+ sig { returns(T::Hash[T.untyped, T.untyped]) }
23
47
  def to_h
24
48
  {
25
49
  street: @street,
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ # typed: strict
3
+
4
+ module WhatsappSdk
5
+ module Resource
6
+ class AddressType < T::Enum
7
+ extend T::Sig
8
+
9
+ enums do
10
+ Home = new("Home")
11
+ Work = new("Work")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,27 +1,24 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  module WhatsappSdk
4
5
  module Resource
5
6
  class ButtonParameter
6
- class InvalidType < StandardError
7
- attr_accessor :message
8
-
9
- def initialize(type)
10
- @message = "invalid type #{type}. type should be text or payload"
11
- super
12
- end
13
- end
7
+ extend T::Sig
14
8
 
15
9
  # Returns the button parameter type.
16
10
  #
17
11
  # @returns type [String] Valid options are payload and text.
12
+ sig { returns(Type) }
18
13
  attr_accessor :type
19
14
 
20
- module Type
21
- TEXT = "text"
22
- PAYLOAD = "payload"
15
+ class Type < T::Enum
16
+ extend T::Sig
23
17
 
24
- VALID_TYPES = [PAYLOAD, TEXT].freeze
18
+ enums do
19
+ Text = new("text")
20
+ Payload = new("payload")
21
+ end
25
22
  end
26
23
 
27
24
  # Required for quick_reply buttons.
@@ -29,37 +26,36 @@ module WhatsappSdk
29
26
  # in addition to the display text on the button.
30
27
  #
31
28
  # @returns payload [String]
29
+ sig { returns(T.nilable(String)) }
32
30
  attr_accessor :payload
33
31
 
34
32
  # Required for URL buttons.
35
33
  # Developer-provided suffix that is appended to the predefined prefix URL in the template.
36
34
  #
37
35
  # @returns text [String]
36
+ sig { returns(T.nilable(String)) }
38
37
  attr_accessor :text
39
38
 
39
+ sig do
40
+ params(
41
+ type: Type, payload: T.nilable(String), text: T.nilable(String)
42
+ ).void
43
+ end
40
44
  def initialize(type:, payload: nil, text: nil)
41
45
  @type = type
42
46
  @payload = payload
43
47
  @text = text
44
- validate
45
48
  end
46
49
 
47
- def to_json(*_args)
50
+ sig { returns(T::Hash[T.untyped, T.untyped]) }
51
+ def to_json
48
52
  json = {
49
- type: type
53
+ type: type.serialize
50
54
  }
51
55
  json[:payload] = payload if payload
52
56
  json[:text] = text if text
53
57
  json
54
58
  end
55
-
56
- private
57
-
58
- def validate
59
- return if Type::VALID_TYPES.include?(type)
60
-
61
- raise InvalidType, type
62
- end
63
59
  end
64
60
  end
65
61
  end
@@ -1,11 +1,21 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  module WhatsappSdk
4
5
  module Resource
5
6
  class Component
7
+ extend T::Sig
8
+
6
9
  class InvalidField < StandardError
7
- attr_reader :field, :message
10
+ extend T::Sig
11
+
12
+ sig { returns(Symbol) }
13
+ attr_reader :field
14
+
15
+ sig { returns(String) }
16
+ attr_reader :message
8
17
 
18
+ sig { params(field: Symbol, message: String).void }
9
19
  def initialize(field, message)
10
20
  @field = field
11
21
  @message = message
@@ -13,25 +23,35 @@ module WhatsappSdk
13
23
  end
14
24
  end
15
25
 
16
- module Type
17
- HEADER = 'header'
18
- BODY = 'body'
19
- BUTTON = 'button'
26
+ class Type < T::Enum
27
+ extend T::Sig
28
+
29
+ enums do
30
+ Header = new("header")
31
+ Body = new("body")
32
+ Button = new("button")
33
+ end
20
34
  end
21
35
 
22
- module Subtype
23
- QUICK_REPLY = "quick_reply"
24
- URL = "url"
36
+ class Subtype < T::Enum
37
+ extend T::Sig
38
+
39
+ enums do
40
+ QuickReply = new("quick_reply")
41
+ Url = new("url")
42
+ end
25
43
  end
26
44
 
27
45
  # Returns the Component type.
28
46
  #
29
47
  # @returns type [String]. Supported Options are header, body and button.
48
+ sig { returns(Type) }
30
49
  attr_accessor :type
31
50
 
32
51
  # Returns the parameters of the component. For button type, it's required.
33
52
  #
34
53
  # @returns parameter [Array<ButtonParameter, ParameterObject>] .
54
+ sig { returns(T::Array[T.any(ButtonParameter, ParameterObject)]) }
35
55
  attr_accessor :parameters
36
56
 
37
57
  # Returns the Type of button to create. Required when type=button. Not used for the other types.
@@ -42,40 +62,52 @@ module WhatsappSdk
42
62
  # appending the text parameter to the predefined prefix URL in the template.
43
63
  #
44
64
  # @returns subtype [String]. Valid options are quick_reply and url.
65
+ sig { returns(T.nilable(WhatsappSdk::Resource::Component::Subtype)) }
45
66
  attr_accessor :sub_type
46
67
 
47
68
  # Required when type=button. Not used for the other types.
48
69
  # Position index of the button. You can have up to 3 buttons using index values of 0 to 2.
49
70
  #
50
71
  # @returns index [Integer].
72
+ sig { returns(T.nilable(Integer)) }
51
73
  attr_accessor :index
52
74
 
75
+ sig { params(parameter: T.any(ButtonParameter, ParameterObject)).void }
53
76
  def add_parameter(parameter)
54
77
  @parameters << parameter
55
78
  end
56
79
 
80
+ sig do
81
+ params(
82
+ type: Type, parameters: T::Array[T.any(ButtonParameter, ParameterObject)],
83
+ sub_type: T.nilable(WhatsappSdk::Resource::Component::Subtype), index: T.nilable(Integer)
84
+ ).void
85
+ end
57
86
  def initialize(type:, parameters: [], sub_type: nil, index: nil)
58
87
  @parameters = parameters
59
88
  @type = type
60
89
  @sub_type = sub_type
61
- @index = index.nil? && type == Type::BUTTON ? 0 : index
90
+ @index = index.nil? && type == Type::Button ? 0 : index
62
91
  validate_fields
63
92
  end
64
93
 
65
- def to_json(*_args)
94
+ sig { returns(T::Hash[T.untyped, T.untyped]) }
95
+ def to_json
66
96
  json = {
67
- type: type,
97
+ type: type.serialize,
68
98
  parameters: parameters.map(&:to_json)
69
99
  }
70
- json[:sub_type] = sub_type if sub_type
100
+ json[:sub_type] = sub_type&.serialize if sub_type
71
101
  json[:index] = index if index
72
102
  json
73
103
  end
74
104
 
75
105
  private
76
106
 
107
+ sig { void }
77
108
  def validate_fields
78
- return if type == Type::BUTTON
109
+ return if type == Type::Button
110
+
79
111
  raise InvalidField.new(:sub_type, 'sub_type is not required when type is not button') if sub_type
80
112
 
81
113
  raise InvalidField.new(:index, 'index is not required when type is not button') if index
@@ -1,10 +1,38 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  module WhatsappSdk
4
5
  module Resource
5
6
  class Contact
6
- attr_accessor :addresses, :birthday, :emails, :name, :org, :phones, :urls
7
+ extend T::Sig
7
8
 
9
+ sig { returns(T::Array[Address]) }
10
+ attr_accessor :addresses
11
+
12
+ sig { returns(String) }
13
+ attr_accessor :birthday
14
+
15
+ sig { returns(T::Array[Email]) }
16
+ attr_accessor :emails
17
+
18
+ sig { returns(Name) }
19
+ attr_accessor :name
20
+
21
+ sig { returns(Org) }
22
+ attr_accessor :org
23
+
24
+ sig { returns(T::Array[PhoneNumber]) }
25
+ attr_accessor :phones
26
+
27
+ sig { returns(T::Array[Url]) }
28
+ attr_accessor :urls
29
+
30
+ sig do
31
+ params(
32
+ addresses: T::Array[Address], birthday: String, emails: T::Array[Email],
33
+ name: Name, org: Org, phones: T::Array[PhoneNumber], urls: T::Array[Url]
34
+ ).void
35
+ end
8
36
  def initialize(addresses:, birthday:, emails:, name:, org:, phones:, urls:)
9
37
  @addresses = addresses
10
38
  @birthday = birthday
@@ -15,6 +43,7 @@ module WhatsappSdk
15
43
  @urls = urls
16
44
  end
17
45
 
46
+ sig { returns(T::Hash[T.untyped, T.untyped]) }
18
47
  def to_h
19
48
  {
20
49
  addresses: addresses.map(&:to_h),
@@ -1,10 +1,18 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  module WhatsappSdk
4
5
  module Resource
5
6
  class ContactResponse
6
- attr_accessor :input, :wa_id
7
+ extend T::Sig
7
8
 
9
+ sig { returns(String) }
10
+ attr_accessor :wa_id
11
+
12
+ sig { returns(String) }
13
+ attr_accessor :input
14
+
15
+ sig { params(input: String, wa_id: String).void }
8
16
  def initialize(input:, wa_id:)
9
17
  @input = input
10
18
  @wa_id = wa_id
@@ -1,30 +1,38 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  module WhatsappSdk
4
5
  module Resource
5
6
  class Currency
7
+ extend T::Sig
8
+
6
9
  # Returns default text if localization fails.
7
10
  #
8
11
  # @returns fallback_value [String].
12
+ sig { returns(String) }
9
13
  attr_accessor :fallback_value
10
14
 
11
15
  # Currency code as defined in ISO 4217.
12
16
  #
13
17
  # @returns code [String].
18
+ sig { returns(String) }
14
19
  attr_accessor :code
15
20
 
16
21
  # Amount multiplied by 1000.
17
22
  #
18
23
  # @returns code [Float].
24
+ sig { returns(T.any(Float, Integer)) }
19
25
  attr_accessor :amount
20
26
 
27
+ sig { params(fallback_value: String, code: String, amount: T.any(Float, Integer)).void }
21
28
  def initialize(fallback_value:, code:, amount:)
22
29
  @fallback_value = fallback_value
23
30
  @code = code
24
31
  @amount = amount
25
32
  end
26
33
 
27
- def to_json(*_args)
34
+ sig { returns(T::Hash[T.untyped, T.untyped]) }
35
+ def to_json
28
36
  {
29
37
  fallback_value: fallback_value,
30
38
  code: code,
@@ -1,18 +1,24 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  module WhatsappSdk
4
5
  module Resource
5
6
  class DateTime
7
+ extend T::Sig
8
+
6
9
  # Returns default text if localization fails.
7
10
  #
8
11
  # @returns fallback_value [String].
12
+ sig { returns(String) }
9
13
  attr_accessor :fallback_value
10
14
 
15
+ sig { params(fallback_value: String).void }
11
16
  def initialize(fallback_value:)
12
17
  @fallback_value = fallback_value
13
18
  end
14
19
 
15
- def to_json(*_args)
20
+ sig { returns(T::Hash[T.untyped, T.untyped]) }
21
+ def to_json
16
22
  {
17
23
  fallback_value: fallback_value
18
24
  }
@@ -1,20 +1,24 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  module WhatsappSdk
4
5
  module Resource
5
6
  class Email
6
- attr_accessor :email, :type
7
+ extend T::Sig
7
8
 
8
- EMAIL_TYPE = {
9
- home: "HOME",
10
- work: "WORK"
11
- }.freeze
9
+ sig { returns(String) }
10
+ attr_accessor :email
12
11
 
12
+ sig { returns(AddressType) }
13
+ attr_accessor :type
14
+
15
+ sig { params(email: String, type: AddressType).void }
13
16
  def initialize(email:, type:)
14
17
  @email = email
15
18
  @type = type
16
19
  end
17
20
 
21
+ sig { returns(T::Hash[T.untyped, T.untyped]) }
18
22
  def to_h
19
23
  {
20
24
  email: @email,