whatsapp_sdk 0.12.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.cursorrules +53 -0
  3. data/.github/workflows/codeql-analysis.yml +8 -6
  4. data/.gitignore +1 -0
  5. data/.rubocop.yml +0 -3
  6. data/CHANGELOG.md +19 -7
  7. data/Gemfile +1 -4
  8. data/Gemfile.lock +9 -23
  9. data/README.md +148 -223
  10. data/SECURITY.md +21 -0
  11. data/example.rb +217 -125
  12. data/lib/whatsapp_sdk/api/api_configuration.rb +2 -5
  13. data/lib/whatsapp_sdk/api/business_profile.rb +12 -26
  14. data/lib/whatsapp_sdk/api/client.rb +31 -43
  15. data/lib/whatsapp_sdk/api/medias.rb +31 -46
  16. data/lib/whatsapp_sdk/api/messages.rb +28 -142
  17. data/lib/whatsapp_sdk/api/phone_numbers.rb +32 -36
  18. data/lib/whatsapp_sdk/api/request.rb +2 -2
  19. data/lib/whatsapp_sdk/api/responses/generic_error_response.rb +12 -30
  20. data/lib/whatsapp_sdk/api/responses/http_response_error.rb +18 -0
  21. data/lib/whatsapp_sdk/api/responses/id_response.rb +15 -0
  22. data/lib/whatsapp_sdk/api/responses/message_data_response.rb +18 -37
  23. data/lib/whatsapp_sdk/api/responses/pagination_records.rb +17 -0
  24. data/lib/whatsapp_sdk/api/responses/success_response.rb +3 -20
  25. data/lib/whatsapp_sdk/api/templates.rb +30 -63
  26. data/lib/whatsapp_sdk/configuration.rb +2 -24
  27. data/lib/whatsapp_sdk/error.rb +0 -1
  28. data/lib/whatsapp_sdk/resource/address.rb +1 -30
  29. data/lib/whatsapp_sdk/resource/address_type.rb +3 -8
  30. data/lib/whatsapp_sdk/resource/business_profile.rb +28 -3
  31. data/lib/whatsapp_sdk/resource/button_parameter.rb +4 -20
  32. data/lib/whatsapp_sdk/resource/component.rb +12 -43
  33. data/lib/whatsapp_sdk/resource/contact.rb +1 -30
  34. data/lib/whatsapp_sdk/resource/contact_response.rb +1 -9
  35. data/lib/whatsapp_sdk/resource/currency.rb +0 -8
  36. data/lib/whatsapp_sdk/resource/date_time.rb +0 -6
  37. data/lib/whatsapp_sdk/resource/email.rb +1 -10
  38. data/lib/whatsapp_sdk/resource/errors.rb +3 -17
  39. data/lib/whatsapp_sdk/resource/interactive.rb +6 -27
  40. data/lib/whatsapp_sdk/resource/interactive_action.rb +10 -24
  41. data/lib/whatsapp_sdk/resource/interactive_action_reply_button.rb +5 -19
  42. data/lib/whatsapp_sdk/resource/interactive_action_section.rb +1 -11
  43. data/lib/whatsapp_sdk/resource/interactive_action_section_row.rb +0 -11
  44. data/lib/whatsapp_sdk/resource/interactive_body.rb +0 -10
  45. data/lib/whatsapp_sdk/resource/interactive_footer.rb +0 -10
  46. data/lib/whatsapp_sdk/resource/interactive_header.rb +25 -53
  47. data/lib/whatsapp_sdk/resource/location.rb +44 -0
  48. data/lib/whatsapp_sdk/resource/media.rb +28 -114
  49. data/lib/whatsapp_sdk/resource/media_component.rb +89 -0
  50. data/lib/whatsapp_sdk/resource/media_types.rb +0 -3
  51. data/lib/whatsapp_sdk/resource/message.rb +0 -5
  52. data/lib/whatsapp_sdk/resource/message_template_namespace.rb +17 -0
  53. data/lib/whatsapp_sdk/resource/name.rb +1 -28
  54. data/lib/whatsapp_sdk/resource/org.rb +1 -13
  55. data/lib/whatsapp_sdk/resource/parameter_object.rb +71 -74
  56. data/lib/whatsapp_sdk/resource/phone_number.rb +40 -22
  57. data/lib/whatsapp_sdk/resource/phone_number_component.rb +25 -0
  58. data/lib/whatsapp_sdk/resource/template.rb +43 -36
  59. data/lib/whatsapp_sdk/resource/url.rb +1 -10
  60. data/lib/whatsapp_sdk/version.rb +1 -2
  61. data/lib/whatsapp_sdk.rb +0 -4
  62. data/whatsapp_sdk.gemspec +1 -4
  63. metadata +13 -62
  64. data/lib/whatsapp_sdk/api/response.rb +0 -51
  65. data/lib/whatsapp_sdk/api/responses/business_profile_data_response.rb +0 -56
  66. data/lib/whatsapp_sdk/api/responses/data_response.rb +0 -26
  67. data/lib/whatsapp_sdk/api/responses/error_response.rb +0 -32
  68. data/lib/whatsapp_sdk/api/responses/media_data_response.rb +0 -48
  69. data/lib/whatsapp_sdk/api/responses/message_error_response.rb +0 -13
  70. data/lib/whatsapp_sdk/api/responses/message_template_namespace_data_response.rb +0 -37
  71. data/lib/whatsapp_sdk/api/responses/phone_number_data_response.rb +0 -60
  72. data/lib/whatsapp_sdk/api/responses/phone_numbers_data_response.rb +0 -39
  73. data/lib/whatsapp_sdk/api/responses/read_message_data_response.rb +0 -34
  74. data/lib/whatsapp_sdk/api/responses/template_data_response.rb +0 -51
  75. data/lib/whatsapp_sdk/api/responses/templates_data_response.rb +0 -39
  76. data/sorbet/config +0 -6
  77. data/sorbet/rbi/annotations/faraday.rbi +0 -17
  78. data/sorbet/rbi/annotations/mocha.rbi +0 -34
  79. data/sorbet/rbi/annotations/rainbow.rbi +0 -269
  80. data/sorbet/rbi/gems/faraday-multipart@1.0.4.rbi +0 -270
  81. data/sorbet/rbi/gems/faraday-net_http@2.0.3.rbi +0 -182
  82. data/sorbet/rbi/gems/faraday@2.3.0.rbi +0 -2494
  83. data/sorbet/rbi/gems/method_source@1.0.0.rbi +0 -272
  84. data/sorbet/rbi/gems/minitest@5.16.1.rbi +0 -1459
  85. data/sorbet/rbi/gems/mocha@1.14.0.rbi +0 -60
  86. data/sorbet/rbi/gems/multipart-post@2.2.3.rbi +0 -239
  87. data/sorbet/rbi/gems/netrc@0.11.0.rbi +0 -150
  88. data/sorbet/rbi/gems/oj@3.13.14.rbi +0 -589
  89. data/sorbet/rbi/gems/zeitwerk@2.6.0.rbi +0 -867
  90. data/sorbet/rbi/todo.rbi +0 -8
  91. data/sorbet/shims/request.rbi +0 -10
  92. data/sorbet/tapioca/config.yml +0 -13
  93. data/sorbet/tapioca/require.rb +0 -4
@@ -1,8 +1,6 @@
1
- # typed: strict
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require_relative "request"
5
- require_relative "response"
6
4
 
7
5
  module WhatsappSdk
8
6
  module Api
@@ -17,47 +15,37 @@ module WhatsappSdk
17
15
  #
18
16
  # @param business_id [Integer] Business Id.
19
17
  # @return [Api::Response] Response object.
20
- sig { params(business_id: Integer).returns(Api::Response) }
21
- def registered_numbers(business_id)
18
+ def list(business_id)
22
19
  response = send_request(
23
20
  http_method: "get",
24
21
  endpoint: "#{business_id}/phone_numbers?fields=#{DEFAULT_FIELDS}"
25
22
  )
26
23
 
27
- Api::Response.new(
28
- response: response,
29
- data_class_type: Api::Responses::PhoneNumbersDataResponse
24
+ Api::Responses::PaginationRecords.new(
25
+ records: parse_phone_numbers(response['data']),
26
+ before: response['paging']['cursors']['before'],
27
+ after: response['paging']['cursors']['after']
30
28
  )
31
29
  end
32
30
 
33
- # Get the registered number id.
31
+ # Get the registered number.
34
32
  #
35
33
  # @param phone_number_id [Integer] The registered number we want to retrieve.
36
- # @return [Api::Response] Response object.
37
- sig { params(phone_number_id: Integer).returns(Api::Response) }
38
- def registered_number(phone_number_id)
34
+ # @return [Resource::PhoneNumber] A PhoneNumber object.
35
+ def get(phone_number_id)
39
36
  response = send_request(
40
37
  http_method: "get",
41
38
  endpoint: "#{phone_number_id}?fields=#{DEFAULT_FIELDS}"
42
39
  )
43
40
 
44
- Api::Response.new(
45
- response: response,
46
- data_class_type: Api::Responses::PhoneNumberDataResponse
47
- )
41
+ Resource::PhoneNumber.from_hash(response)
48
42
  end
49
43
 
50
44
  # Register a phone number.
51
45
  #
52
46
  # @param phone_number_id [Integer] The registered number we want to retrieve.
53
47
  # @param pin [Integer] Pin of 6 digits.
54
- # @return [Api::Response] Response object.
55
- sig do
56
- params(
57
- phone_number_id: Integer,
58
- pin: Integer
59
- ).returns(Api::Response)
60
- end
48
+ # @return [Boolean] Whether the registration was successful.
61
49
  def register_number(phone_number_id, pin)
62
50
  response = send_request(
63
51
  http_method: "post",
@@ -65,21 +53,13 @@ module WhatsappSdk
65
53
  params: { messaging_product: 'whatsapp', pin: pin }
66
54
  )
67
55
 
68
- Api::Response.new(
69
- response: response,
70
- data_class_type: Api::Responses::PhoneNumberDataResponse
71
- )
56
+ Api::Responses::SuccessResponse.success_response?(response: response)
72
57
  end
73
58
 
74
59
  # Deregister a phone number.
75
60
  #
76
61
  # @param phone_number_id [Integer] The registered number we want to retrieve.
77
- # @return [Api::Response] Response object.
78
- sig do
79
- params(
80
- phone_number_id: Integer
81
- ).returns(Api::Response)
82
- end
62
+ # @return [Boolean] Whether the deregistration was successful.
83
63
  def deregister_number(phone_number_id)
84
64
  response = send_request(
85
65
  http_method: "post",
@@ -87,10 +67,26 @@ module WhatsappSdk
87
67
  params: {}
88
68
  )
89
69
 
90
- Api::Response.new(
91
- response: response,
92
- data_class_type: Api::Responses::PhoneNumberDataResponse
93
- )
70
+ Api::Responses::SuccessResponse.success_response?(response: response)
71
+ end
72
+
73
+ # deprecated methods
74
+ def registered_numbers(business_id)
75
+ warn "[DEPRECATION] `registered_numbers` is deprecated. Please use `list` instead."
76
+ list(business_id)
77
+ end
78
+
79
+ def registered_number(phone_number_id)
80
+ warn "[DEPRECATION] `registered_number` is deprecated. Please use `get` instead."
81
+ get(phone_number_id)
82
+ end
83
+
84
+ private
85
+
86
+ def parse_phone_numbers(phone_numbers_data)
87
+ phone_numbers_data.map do |phone_number|
88
+ Resource::PhoneNumber.from_hash(phone_number)
89
+ end
94
90
  end
95
91
  end
96
92
  end
@@ -1,11 +1,11 @@
1
1
  # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
+ require_relative "../../whatsapp_sdk"
5
+
4
6
  module WhatsappSdk
5
7
  module Api
6
8
  class Request
7
- extend T::Sig
8
-
9
9
  def initialize(client = WhatsappSdk.configuration.client)
10
10
  @client = client
11
11
  end
@@ -1,42 +1,24 @@
1
- # typed: strict
2
1
  # frozen_string_literal: true
3
2
 
4
- require_relative "error_response"
5
-
6
3
  module WhatsappSdk
7
4
  module Api
8
5
  module Responses
9
- class GenericErrorResponse < ErrorResponse
10
- sig { returns(Integer) }
11
- attr_reader :code
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
6
+ class GenericErrorResponse
7
+ attr_reader :code, :subcode, :message, :type, :data, :fbtrace_id
21
8
 
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 }
29
9
  def initialize(response:)
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))
36
- super(response: response)
10
+ @code = response["code"]
11
+ @subcode = response["error_subcode"]
12
+ @message = response["message"]
13
+ @type = response["type"]
14
+ @data = response["data"]
15
+ @fbtrace_id = response["fbtrace_id"]
16
+ end
17
+
18
+ def self.response_error?(response:)
19
+ response["error"]
37
20
  end
38
21
 
39
- sig { override.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(GenericErrorResponse)) }
40
22
  def self.build_from_response(response:)
41
23
  error_response = response["error"]
42
24
  return unless error_response
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WhatsappSdk
4
+ module Api
5
+ module Responses
6
+ class HttpResponseError < StandardError
7
+ attr_reader :http_status, :body, :error_info
8
+
9
+ def initialize(http_status:, body:)
10
+ super
11
+ @http_status = http_status
12
+ @body = body
13
+ @error_info = GenericErrorResponse.build_from_response(response: body)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WhatsappSdk
4
+ module Api
5
+ module Responses
6
+ class IdResponse
7
+ attr_accessor :id
8
+
9
+ def initialize(id)
10
+ @id = id
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,53 +1,34 @@
1
- # typed: strict
2
1
  # frozen_string_literal: true
3
2
 
4
- require_relative "../request"
5
- require_relative "data_response"
6
3
  require_relative "../../resource/message"
7
4
  require_relative "../../resource/contact_response"
8
5
 
9
6
  module WhatsappSdk
10
7
  module Api
11
8
  module Responses
12
- class MessageDataResponse < DataResponse
13
- extend T::Sig
14
-
15
- sig { returns(T::Array[Resource::ContactResponse]) }
16
- attr_reader :contacts
17
-
18
- sig { returns(T::Array[Resource::Message]) }
19
- attr_reader :messages
20
-
21
- sig { params(response: T::Hash[T.untyped, T.untyped]).void }
22
- def initialize(response:)
23
- @contacts = T.let(
24
- response["contacts"]&.map { |contact_json| parse_contact(contact_json) },
25
- T::Array[Resource::ContactResponse]
26
- )
27
- @messages = T.let(
28
- response["messages"]&.map { |contact_json| parse_message(contact_json) },
29
- T::Array[Resource::Message]
30
- )
31
- super(response)
32
- end
9
+ class MessageDataResponse
10
+ attr_accessor :contacts, :messages
33
11
 
34
- sig { override.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(MessageDataResponse)) }
35
- def self.build_from_response(response:)
36
- return unless response["messages"]
12
+ class << self
13
+ def build_from_response(response:)
14
+ return unless response["messages"]
37
15
 
38
- new(response: response)
39
- end
16
+ data_response = new
17
+ data_response.contacts = response["contacts"]&.map { |contact_json| parse_contact(contact_json) }
18
+ data_response.messages = response["messages"]&.map { |contact_json| parse_message(contact_json) }
40
19
 
41
- private
20
+ data_response
21
+ end
42
22
 
43
- sig { params(message_json: T::Hash[T.untyped, T.untyped]).returns(Resource::Message) }
44
- def parse_message(message_json)
45
- Resource::Message.new(id: message_json["id"])
46
- end
23
+ private
24
+
25
+ def parse_message(message_json)
26
+ Resource::Message.new(id: message_json["id"])
27
+ end
47
28
 
48
- sig { params(contact_json: T::Hash[T.untyped, T.untyped]).returns(Resource::ContactResponse) }
49
- def parse_contact(contact_json)
50
- Resource::ContactResponse.new(input: contact_json["input"], wa_id: contact_json["wa_id"])
29
+ def parse_contact(contact_json)
30
+ Resource::ContactResponse.new(input: contact_json["input"], wa_id: contact_json["wa_id"])
31
+ end
51
32
  end
52
33
  end
53
34
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WhatsappSdk
4
+ module Api
5
+ module Responses
6
+ class PaginationRecords
7
+ attr_reader :records, :before, :after
8
+
9
+ def initialize(records:, before:, after:)
10
+ @records = records
11
+ @before = before
12
+ @after = after
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,28 +1,11 @@
1
- # typed: strict
2
1
  # frozen_string_literal: true
3
2
 
4
- require_relative "data_response"
5
-
6
3
  module WhatsappSdk
7
4
  module Api
8
5
  module Responses
9
- class SuccessResponse < DataResponse
10
- sig { params(response: T::Hash[T.untyped, T.untyped]).void }
11
- def initialize(response:)
12
- @success = T.let(response["success"], T::Boolean)
13
- super(response)
14
- end
15
-
16
- sig { override.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(SuccessResponse)) }
17
- def self.build_from_response(response:)
18
- return unless response["success"]
19
-
20
- new(response: response)
21
- end
22
-
23
- sig { returns(T::Boolean) }
24
- def success?
25
- @success
6
+ class SuccessResponse
7
+ def self.success_response?(response:)
8
+ response["success"] == true
26
9
  end
27
10
  end
28
11
  end
@@ -1,27 +1,16 @@
1
- # typed: strict
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require_relative "request"
5
- require_relative "response"
6
- require_relative 'responses/success_response'
7
- require_relative 'responses/message_template_namespace_data_response'
8
- require_relative 'responses/generic_error_response'
9
- require_relative 'responses/template_data_response'
10
- require_relative 'responses/templates_data_response'
11
4
  require_relative "../resource/languages"
12
5
 
13
6
  module WhatsappSdk
14
7
  module Api
15
8
  class Templates < Request
16
- DEFAULT_HEADERS = T.let({ 'Content-Type' => 'application/json' }.freeze, Hash)
9
+ DEFAULT_HEADERS = { 'Content-Type' => 'application/json' }.freeze
17
10
 
18
11
  class InvalidCategoryError < StandardError
19
- extend T::Sig
20
-
21
- sig { returns(String) }
22
12
  attr_reader :category
23
13
 
24
- sig { params(category: String).void }
25
14
  def initialize(category:)
26
15
  @category = category
27
16
 
@@ -41,21 +30,11 @@ module WhatsappSdk
41
30
  # @param allow_category_change [Boolean] Optional Allow category change.
42
31
  # Set to true to allow us to assign a category based on the template guidelines and the template's contents.
43
32
  # This can prevent your template from being rejected for miscategorization.
44
- # @return [Response] Response object.
45
- sig do
46
- params(
47
- business_id: Integer,
48
- name: String,
49
- category: String,
50
- language: String,
51
- components_json: T.nilable(T::Array[T::Hash[T.untyped, T.untyped]]),
52
- allow_category_change: T.nilable(T::Boolean)
53
- ).returns(Response)
54
- end
33
+ # @return [Template] Template object.
55
34
  def create(
56
35
  business_id:, name:, category:, language:, components_json: nil, allow_category_change: nil
57
36
  )
58
- unless WhatsappSdk::Resource::Template::Category.try_deserialize(category)
37
+ unless WhatsappSdk::Resource::Template::Category.valid?(category)
59
38
  raise InvalidCategoryError.new(category: category)
60
39
  end
61
40
 
@@ -78,20 +57,15 @@ module WhatsappSdk
78
57
  headers: DEFAULT_HEADERS
79
58
  )
80
59
 
81
- Response.new(
82
- response: response,
83
- data_class_type: Responses::TemplateDataResponse,
84
- error_class_type: Responses::GenericErrorResponse
85
- )
60
+ Resource::Template.from_hash(response)
86
61
  end
87
62
 
88
63
  # Get templates
89
64
  #
90
65
  # @param business_id [Integer] The business ID.
91
66
  # @param limit [Integer] Optional. Number of templates to return in a single page.
92
- # @return [Response] Response object.
93
- sig { params(business_id: Integer, limit: T.nilable(Integer)).returns(Response) }
94
- def templates(business_id:, limit: 100)
67
+ # @return [Template] Pagination Record containing an array of Template objects.
68
+ def list(business_id:, limit: 100)
95
69
  params = {}
96
70
  params["limit"] = limit if limit
97
71
 
@@ -101,19 +75,23 @@ module WhatsappSdk
101
75
  params: params
102
76
  )
103
77
 
104
- Response.new(
105
- response: response,
106
- data_class_type: Responses::TemplatesDataResponse,
107
- error_class_type: Responses::GenericErrorResponse
78
+ Api::Responses::PaginationRecords.new(
79
+ records: parse_templates(response['data']),
80
+ before: response['paging']['cursors']['before'],
81
+ after: response['paging']['cursors']['after']
108
82
  )
109
83
  end
110
84
 
85
+ def templates(business_id:)
86
+ warn "[DEPRECATION] `templates` is deprecated. Please use `list` instead."
87
+ list(business_id: business_id)
88
+ end
89
+
111
90
  # Get Message Template Namespace
112
91
  # The message template namespace is required to send messages using the message templates.
113
92
  #
114
93
  # @param business_id [Integer] The business ID.
115
- # @return [Response] Response object.
116
- sig { params(business_id: Integer).returns(Response) }
94
+ # @return [MessageTemplateNamespace] MessageTemplateNamespace object.
117
95
  def get_message_template_namespace(business_id:)
118
96
  response = send_request(
119
97
  endpoint: business_id.to_s,
@@ -121,11 +99,7 @@ module WhatsappSdk
121
99
  params: { "fields" => "message_template_namespace" }
122
100
  )
123
101
 
124
- Response.new(
125
- response: response,
126
- data_class_type: Responses::MessageTemplateNamespaceDataResponse,
127
- error_class_type: Responses::GenericErrorResponse
128
- )
102
+ WhatsappSdk::Resource::MessageTemplateNamespace.from_hash(response)
129
103
  end
130
104
 
131
105
  # Edit Template
@@ -137,9 +111,9 @@ module WhatsappSdk
137
111
  #
138
112
  # @param id [String] Required. The message_template-id.
139
113
  # @param components_json [Json] Components that make up the template..
140
- # return [Response] Response object.
114
+ # @return [Boolean] Whether the update was successful.
141
115
  def update(template_id:, category: nil, components_json: nil)
142
- if category && !WhatsappSdk::Resource::Template::Category.try_deserialize(category)
116
+ if category && !WhatsappSdk::Resource::Template::Category.valid?(category)
143
117
  raise InvalidCategoryError.new(category: category)
144
118
  end
145
119
 
@@ -154,11 +128,7 @@ module WhatsappSdk
154
128
  headers: { "Content-Type" => "application/json" }
155
129
  )
156
130
 
157
- Response.new(
158
- response: response,
159
- data_class_type: Responses::SuccessResponse,
160
- error_class_type: Responses::GenericErrorResponse
161
- )
131
+ Api::Responses::SuccessResponse.success_response?(response: response)
162
132
  end
163
133
 
164
134
  # Delete Template
@@ -172,14 +142,7 @@ module WhatsappSdk
172
142
  # @param name [String] Required. The template's name.
173
143
  # @param hsm_id [String] Optional. The template's id.
174
144
  #
175
- # @return [Response] Response object.
176
- sig do
177
- params(
178
- business_id: Integer,
179
- name: String,
180
- hsm_id: T.nilable(String)
181
- ).returns(Response)
182
- end
145
+ # @return [Boolean] Whether the deletion was successful.
183
146
  def delete(business_id:, name:, hsm_id: nil)
184
147
  params = { name: name }
185
148
  params[:hsm_id] = hsm_id if hsm_id
@@ -190,11 +153,15 @@ module WhatsappSdk
190
153
  params: params
191
154
  )
192
155
 
193
- Response.new(
194
- response: response,
195
- data_class_type: Responses::SuccessResponse,
196
- error_class_type: Responses::GenericErrorResponse
197
- )
156
+ Api::Responses::SuccessResponse.success_response?(response: response)
157
+ end
158
+
159
+ private
160
+
161
+ def parse_templates(templates_data)
162
+ templates_data.map do |template|
163
+ Resource::Template.from_hash(template)
164
+ end
198
165
  end
199
166
  end
200
167
  end
@@ -1,4 +1,3 @@
1
- # typed: strict
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module WhatsappSdk
@@ -10,31 +9,11 @@ module WhatsappSdk
10
9
  #
11
10
  # The gem have access to the client through WhatsappSdk.configuration.client
12
11
  class Configuration
13
- extend T::Sig
14
-
15
- logger_or_subclass_or_nil = T.nilable(T.any(Logger, T.class_of(Logger)))
16
-
17
- sig { returns(String) }
18
- attr_accessor :access_token
19
-
20
- sig { returns(String) }
21
- attr_accessor :api_version
12
+ attr_accessor :access_token, :api_version
22
13
 
23
14
  # loggers like ActiveSupport::Logger (Rails.logger) is a subclass of Logger
24
- sig { returns(logger_or_subclass_or_nil) }
25
- attr_accessor :logger
15
+ attr_accessor :logger, :logger_options
26
16
 
27
- sig { returns(Hash) }
28
- attr_accessor :logger_options
29
-
30
- sig do
31
- params(
32
- access_token: String,
33
- api_version: String,
34
- logger: logger_or_subclass_or_nil,
35
- logger_options: Hash
36
- ).void
37
- end
38
17
  def initialize(
39
18
  access_token = "",
40
19
  api_version = Api::ApiConfiguration::DEFAULT_API_VERSION,
@@ -47,7 +26,6 @@ module WhatsappSdk
47
26
  @logger_options = logger_options
48
27
  end
49
28
 
50
- sig { returns(Api::Client) }
51
29
  def client
52
30
  Api::Client.new(access_token, api_version, logger, logger_options)
53
31
  end
@@ -1,4 +1,3 @@
1
- # typed: strict
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module WhatsappSdk
@@ -1,38 +1,10 @@
1
- # typed: strict
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module WhatsappSdk
5
4
  module Resource
6
5
  class Address
7
- extend T::Sig
6
+ attr_accessor :street, :city, :state, :zip, :country, :country_code, :type
8
7
 
9
- sig { returns(String) }
10
- attr_accessor :street
11
-
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
8
  def initialize(street:, city:, state:, zip:, country:, country_code:, type: AddressType::Home)
37
9
  @street = street
38
10
  @city = city
@@ -43,7 +15,6 @@ module WhatsappSdk
43
15
  @type = type
44
16
  end
45
17
 
46
- sig { returns(T::Hash[T.untyped, T.untyped]) }
47
18
  def to_h
48
19
  {
49
20
  street: @street,
@@ -1,15 +1,10 @@
1
- # typed: strict
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module WhatsappSdk
5
4
  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
5
+ module AddressType
6
+ HOME = "Home"
7
+ WORK = "Work"
13
8
  end
14
9
  end
15
10
  end