whatsapp_sdk 0.13.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.cursorrules +53 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +9 -4
- data/README.md +115 -170
- data/example.rb +197 -113
- data/lib/whatsapp_sdk/api/business_profile.rb +12 -14
- data/lib/whatsapp_sdk/api/client.rb +26 -2
- data/lib/whatsapp_sdk/api/medias.rb +23 -31
- data/lib/whatsapp_sdk/api/messages.rb +24 -61
- data/lib/whatsapp_sdk/api/phone_numbers.rb +32 -22
- data/lib/whatsapp_sdk/api/request.rb +2 -0
- data/lib/whatsapp_sdk/api/responses/generic_error_response.rb +4 -4
- data/lib/whatsapp_sdk/api/responses/http_response_error.rb +18 -0
- data/lib/whatsapp_sdk/api/responses/{message_error_response.rb → id_response.rb} +6 -3
- data/lib/whatsapp_sdk/api/responses/message_data_response.rb +17 -20
- data/lib/whatsapp_sdk/api/responses/pagination_records.rb +17 -0
- data/lib/whatsapp_sdk/api/responses/success_response.rb +3 -16
- data/lib/whatsapp_sdk/api/templates.rb +27 -36
- data/lib/whatsapp_sdk/resource/business_profile.rb +28 -0
- data/lib/whatsapp_sdk/resource/errors.rb +2 -0
- data/lib/whatsapp_sdk/resource/media.rb +18 -68
- data/lib/whatsapp_sdk/resource/media_component.rb +89 -0
- data/lib/whatsapp_sdk/resource/message_template_namespace.rb +17 -0
- data/lib/whatsapp_sdk/resource/phone_number.rb +41 -11
- data/lib/whatsapp_sdk/resource/phone_number_component.rb +25 -0
- data/lib/whatsapp_sdk/resource/template.rb +20 -0
- data/lib/whatsapp_sdk/version.rb +1 -1
- data/whatsapp_sdk.gemspec +1 -1
- metadata +10 -15
- data/lib/whatsapp_sdk/api/response.rb +0 -32
- data/lib/whatsapp_sdk/api/responses/business_profile_data_response.rb +0 -33
- data/lib/whatsapp_sdk/api/responses/data_response.rb +0 -17
- data/lib/whatsapp_sdk/api/responses/error_response.rb +0 -25
- data/lib/whatsapp_sdk/api/responses/media_data_response.rb +0 -30
- data/lib/whatsapp_sdk/api/responses/message_template_namespace_data_response.rb +0 -27
- data/lib/whatsapp_sdk/api/responses/phone_number_data_response.rb +0 -42
- data/lib/whatsapp_sdk/api/responses/phone_numbers_data_response.rb +0 -32
- data/lib/whatsapp_sdk/api/responses/read_message_data_response.rb +0 -29
- data/lib/whatsapp_sdk/api/responses/template_data_response.rb +0 -46
- data/lib/whatsapp_sdk/api/responses/templates_data_response.rb +0 -32
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module WhatsappSdk
|
4
|
-
module Api
|
5
|
-
module Responses
|
6
|
-
class DataResponse
|
7
|
-
attr_reader :raw_data_response
|
8
|
-
|
9
|
-
def initialize(response)
|
10
|
-
@raw_data_response = response
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.build_from_response(response:); end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "data_response"
|
4
|
-
|
5
|
-
module WhatsappSdk
|
6
|
-
module Api
|
7
|
-
module Responses
|
8
|
-
class ErrorResponse < DataResponse
|
9
|
-
attr_accessor :error, :status
|
10
|
-
|
11
|
-
def initialize(response:)
|
12
|
-
@error = response["error"]
|
13
|
-
@status = response["status"]
|
14
|
-
super(response)
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.build_from_response(response:)
|
18
|
-
return unless response["error"]
|
19
|
-
|
20
|
-
new(response: response)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "data_response"
|
4
|
-
|
5
|
-
module WhatsappSdk
|
6
|
-
module Api
|
7
|
-
module Responses
|
8
|
-
class MediaDataResponse < DataResponse
|
9
|
-
attr_accessor :id, :url, :mime_type, :sha256, :file_size, :messaging_product
|
10
|
-
|
11
|
-
def initialize(response)
|
12
|
-
@id = response["id"]
|
13
|
-
@messaging_product = response["messaging_product"]
|
14
|
-
@url = response["url"]
|
15
|
-
@mime_type = response["mime_type"]
|
16
|
-
@sha256 = response["sha256"]
|
17
|
-
@file_size = response["file_size"]
|
18
|
-
|
19
|
-
super(response)
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.build_from_response(response:)
|
23
|
-
return unless response["id"]
|
24
|
-
|
25
|
-
new(response)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "data_response"
|
4
|
-
require_relative "../../resource/template"
|
5
|
-
|
6
|
-
module WhatsappSdk
|
7
|
-
module Api
|
8
|
-
module Responses
|
9
|
-
class MessageTemplateNamespaceDataResponse < DataResponse
|
10
|
-
attr_accessor :message_template_namespace, :id
|
11
|
-
|
12
|
-
def initialize(response)
|
13
|
-
@id = response["id"]
|
14
|
-
@message_template_namespace = response["message_template_namespace"]
|
15
|
-
|
16
|
-
super(response)
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.build_from_response(response:)
|
20
|
-
return unless response["id"]
|
21
|
-
|
22
|
-
new(response)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "data_response"
|
4
|
-
|
5
|
-
module WhatsappSdk
|
6
|
-
module Api
|
7
|
-
module Responses
|
8
|
-
class PhoneNumberDataResponse < DataResponse
|
9
|
-
attr_accessor :id, :verified_name, :display_phone_number, :quality_rating, :is_pin_enabled,
|
10
|
-
:is_official_business_account, :account_mode, :certificate, :code_verification_status,
|
11
|
-
:eligibility_for_api_business_global_search, :name_status, :new_name_status, :status,
|
12
|
-
:search_visibility, :messaging_limit_tier
|
13
|
-
|
14
|
-
def initialize(response)
|
15
|
-
@id = response["id"]
|
16
|
-
@verified_name = response["verified_name"]
|
17
|
-
@display_phone_number = response["display_phone_number"]
|
18
|
-
@quality_rating = response["quality_rating"]
|
19
|
-
@is_pin_enabled = response["is_pin_enabled"]
|
20
|
-
@is_official_business_account = response["is_official_business_account"]
|
21
|
-
@account_mode = response["account_mode"]
|
22
|
-
@certificate = response["certificate"]
|
23
|
-
@code_verification_status = response["code_verification_status"]
|
24
|
-
@eligibility_for_api_business_global_search = response["eligibility_for_api_business_global_search"]
|
25
|
-
@name_status = response["name_status"]
|
26
|
-
@new_name_status = response["new_name_status"]
|
27
|
-
@status = response["status"]
|
28
|
-
@search_visibility = response["search_visibility"]
|
29
|
-
@messaging_limit_tier = response["messaging_limit_tier"]
|
30
|
-
|
31
|
-
super(response)
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.build_from_response(response:)
|
35
|
-
return unless response["id"]
|
36
|
-
|
37
|
-
new(response)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "data_response"
|
4
|
-
require_relative "phone_number_data_response"
|
5
|
-
|
6
|
-
module WhatsappSdk
|
7
|
-
module Api
|
8
|
-
module Responses
|
9
|
-
class PhoneNumbersDataResponse < DataResponse
|
10
|
-
attr_reader :phone_numbers
|
11
|
-
|
12
|
-
def initialize(response)
|
13
|
-
@phone_numbers = response['data']&.map { |phone_number| parse_phone_number(phone_number) }
|
14
|
-
|
15
|
-
super(response)
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.build_from_response(response:)
|
19
|
-
return unless response["data"]
|
20
|
-
|
21
|
-
new(response)
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def parse_phone_number(phone_number)
|
27
|
-
PhoneNumberDataResponse.new(phone_number)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../request"
|
4
|
-
require_relative "data_response"
|
5
|
-
require_relative "../../resource/message"
|
6
|
-
require_relative "../../resource/contact_response"
|
7
|
-
|
8
|
-
module WhatsappSdk
|
9
|
-
module Api
|
10
|
-
module Responses
|
11
|
-
class ReadMessageDataResponse < DataResponse
|
12
|
-
def initialize(response:)
|
13
|
-
@success = response["success"]
|
14
|
-
super(response)
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.build_from_response(response:)
|
18
|
-
return if response["error"]
|
19
|
-
|
20
|
-
new(response: response)
|
21
|
-
end
|
22
|
-
|
23
|
-
def success?
|
24
|
-
@success
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "data_response"
|
4
|
-
require_relative "../../resource/template"
|
5
|
-
|
6
|
-
module WhatsappSdk
|
7
|
-
module Api
|
8
|
-
module Responses
|
9
|
-
class TemplateDataResponse < DataResponse
|
10
|
-
attr_reader :template
|
11
|
-
|
12
|
-
def initialize(response:)
|
13
|
-
@template = parse_template(response)
|
14
|
-
|
15
|
-
super(response)
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.build_from_response(response:)
|
19
|
-
return unless response["id"]
|
20
|
-
|
21
|
-
new(response: response)
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def parse_template(template_json)
|
27
|
-
status = template_json["status"]
|
28
|
-
category = template_json["category"]
|
29
|
-
id = template_json["id"]
|
30
|
-
language = template_json["language"]
|
31
|
-
name = template_json["name"]
|
32
|
-
components_json = template_json["components"]
|
33
|
-
|
34
|
-
::WhatsappSdk::Resource::Template.new(
|
35
|
-
id: id,
|
36
|
-
status: status,
|
37
|
-
category: category,
|
38
|
-
language: language,
|
39
|
-
name: name,
|
40
|
-
components_json: components_json
|
41
|
-
)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "data_response"
|
4
|
-
require_relative "template_data_response"
|
5
|
-
|
6
|
-
module WhatsappSdk
|
7
|
-
module Api
|
8
|
-
module Responses
|
9
|
-
class TemplatesDataResponse < DataResponse
|
10
|
-
attr_reader :templates
|
11
|
-
|
12
|
-
def initialize(response)
|
13
|
-
@templates = response['data']&.map { |template| parse_templates(template) }
|
14
|
-
|
15
|
-
super(response)
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.build_from_response(response:)
|
19
|
-
return unless response["data"]
|
20
|
-
|
21
|
-
new(response)
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def parse_templates(template)
|
27
|
-
TemplateDataResponse.new(response: template)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|