whatsapp-ruby-sdk 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +28 -0
- data/README.md +85 -0
- data/lib/whats_app_cloud_api/api_helper.rb +277 -0
- data/lib/whats_app_cloud_api/client.rb +68 -0
- data/lib/whats_app_cloud_api/configuration.rb +132 -0
- data/lib/whats_app_cloud_api/controllers/base_controller.rb +52 -0
- data/lib/whats_app_cloud_api/controllers/business_profiles_controller.rb +94 -0
- data/lib/whats_app_cloud_api/controllers/media_controller.rb +142 -0
- data/lib/whats_app_cloud_api/controllers/messages_controller.rb +51 -0
- data/lib/whats_app_cloud_api/controllers/phone_numbers_controller.rb +141 -0
- data/lib/whats_app_cloud_api/controllers/registration_controller.rb +91 -0
- data/lib/whats_app_cloud_api/controllers/two_step_verification_controller.rb +57 -0
- data/lib/whats_app_cloud_api/exceptions/api_exception.rb +20 -0
- data/lib/whats_app_cloud_api/http/auth/o_auth2.rb +17 -0
- data/lib/whats_app_cloud_api/http/faraday_client.rb +97 -0
- data/lib/whats_app_cloud_api/http/http_call_back.rb +24 -0
- data/lib/whats_app_cloud_api/http/http_client.rb +123 -0
- data/lib/whats_app_cloud_api/http/http_method_enum.rb +13 -0
- data/lib/whats_app_cloud_api/http/http_request.rb +54 -0
- data/lib/whats_app_cloud_api/http/http_response.rb +29 -0
- data/lib/whats_app_cloud_api/models/action.rb +91 -0
- data/lib/whats_app_cloud_api/models/address.rb +110 -0
- data/lib/whats_app_cloud_api/models/audio.rb +61 -0
- data/lib/whats_app_cloud_api/models/base_model.rb +58 -0
- data/lib/whats_app_cloud_api/models/body.rb +49 -0
- data/lib/whats_app_cloud_api/models/business_profile.rb +123 -0
- data/lib/whats_app_cloud_api/models/button.rb +71 -0
- data/lib/whats_app_cloud_api/models/button_parameter.rb +72 -0
- data/lib/whats_app_cloud_api/models/button_parameter_type_enum.rb +17 -0
- data/lib/whats_app_cloud_api/models/component.rb +83 -0
- data/lib/whats_app_cloud_api/models/component_type_enum.rb +20 -0
- data/lib/whats_app_cloud_api/models/contact.rb +145 -0
- data/lib/whats_app_cloud_api/models/content_type_enum.rb +14 -0
- data/lib/whats_app_cloud_api/models/currency.rb +67 -0
- data/lib/whats_app_cloud_api/models/date_time_object.rb +128 -0
- data/lib/whats_app_cloud_api/models/document.rb +81 -0
- data/lib/whats_app_cloud_api/models/email_object.rb +60 -0
- data/lib/whats_app_cloud_api/models/footer.rb +49 -0
- data/lib/whats_app_cloud_api/models/get_business_profile_id_response.rb +57 -0
- data/lib/whats_app_cloud_api/models/get_phone_number_by_id_response.rb +78 -0
- data/lib/whats_app_cloud_api/models/header.rb +93 -0
- data/lib/whats_app_cloud_api/models/header_type_enum.rb +23 -0
- data/lib/whats_app_cloud_api/models/image.rb +71 -0
- data/lib/whats_app_cloud_api/models/interactive.rb +87 -0
- data/lib/whats_app_cloud_api/models/interactive_type_enum.rb +17 -0
- data/lib/whats_app_cloud_api/models/language.rb +60 -0
- data/lib/whats_app_cloud_api/models/location.rb +78 -0
- data/lib/whats_app_cloud_api/models/message.rb +194 -0
- data/lib/whats_app_cloud_api/models/message_type_enum.rb +41 -0
- data/lib/whats_app_cloud_api/models/name.rb +100 -0
- data/lib/whats_app_cloud_api/models/org.rb +70 -0
- data/lib/whats_app_cloud_api/models/parameter.rb +113 -0
- data/lib/whats_app_cloud_api/models/parameter_type_enum.rb +29 -0
- data/lib/whats_app_cloud_api/models/personal_information_type_enum.rb +17 -0
- data/lib/whats_app_cloud_api/models/phone_object.rb +70 -0
- data/lib/whats_app_cloud_api/models/phone_type_enum.rb +26 -0
- data/lib/whats_app_cloud_api/models/quality_rating_enum.rb +25 -0
- data/lib/whats_app_cloud_api/models/register_phone_request.rb +58 -0
- data/lib/whats_app_cloud_api/models/request_verification_code_method_enum.rb +17 -0
- data/lib/whats_app_cloud_api/models/request_verification_code_request.rb +57 -0
- data/lib/whats_app_cloud_api/models/response_contact.rb +57 -0
- data/lib/whats_app_cloud_api/models/response_message.rb +48 -0
- data/lib/whats_app_cloud_api/models/retrieve_media_url_response.rb +94 -0
- data/lib/whats_app_cloud_api/models/row.rb +68 -0
- data/lib/whats_app_cloud_api/models/section.rb +72 -0
- data/lib/whats_app_cloud_api/models/send_message_response.rb +85 -0
- data/lib/whats_app_cloud_api/models/set_two_step_verification_code_request.rb +48 -0
- data/lib/whats_app_cloud_api/models/sticker.rb +61 -0
- data/lib/whats_app_cloud_api/models/sub_type_enum.rb +20 -0
- data/lib/whats_app_cloud_api/models/success_response.rb +48 -0
- data/lib/whats_app_cloud_api/models/template.rb +78 -0
- data/lib/whats_app_cloud_api/models/text.rb +72 -0
- data/lib/whats_app_cloud_api/models/update_business_profile_request.rb +116 -0
- data/lib/whats_app_cloud_api/models/upload_media.rb +48 -0
- data/lib/whats_app_cloud_api/models/upload_media_request.rb +80 -0
- data/lib/whats_app_cloud_api/models/url_object.rb +60 -0
- data/lib/whats_app_cloud_api/models/verify_code_request.rb +48 -0
- data/lib/whats_app_cloud_api/models/vertical_enum.rb +68 -0
- data/lib/whats_app_cloud_api/models/video.rb +61 -0
- data/lib/whats_app_cloud_api/utilities/date_time_helper.rb +156 -0
- data/lib/whats_app_cloud_api/utilities/file_wrapper.rb +16 -0
- data/lib/whats_app_cloud_api.rb +104 -0
- metadata +266 -0
@@ -0,0 +1,94 @@
|
|
1
|
+
# whats_app_cloud_api
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module WhatsAppCloudApi
|
7
|
+
# BusinessProfilesController
|
8
|
+
class BusinessProfilesController < BaseController
|
9
|
+
def initialize(config, http_call_back: nil)
|
10
|
+
super(config, http_call_back: http_call_back)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Use this endpoint to update your business’ profile information such as the
|
14
|
+
# business description, email or address.
|
15
|
+
# @param [String] phone_number_id Required parameter: Example:
|
16
|
+
# @param [UpdateBusinessProfileRequest] body Required parameter: Example:
|
17
|
+
# @return [SuccessResponse] response from the API call
|
18
|
+
def update_business_profile(phone_number_id,
|
19
|
+
body)
|
20
|
+
# Prepare query url.
|
21
|
+
_query_builder = config.get_base_uri
|
22
|
+
_query_builder << '/{Phone-Number-ID}/whatsapp_business_profile'
|
23
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
24
|
+
_query_builder,
|
25
|
+
'Phone-Number-ID' => { 'value' => phone_number_id, 'encode' => true }
|
26
|
+
)
|
27
|
+
_query_url = APIHelper.clean_url _query_builder
|
28
|
+
|
29
|
+
# Prepare headers.
|
30
|
+
_headers = {
|
31
|
+
'accept' => 'application/json',
|
32
|
+
'Content-Type' => 'application/json'
|
33
|
+
}
|
34
|
+
|
35
|
+
# Prepare and execute HttpRequest.
|
36
|
+
_request = config.http_client.post(
|
37
|
+
_query_url,
|
38
|
+
headers: _headers,
|
39
|
+
parameters: body.to_json
|
40
|
+
)
|
41
|
+
OAuth2.apply(config, _request)
|
42
|
+
_response = execute_request(_request)
|
43
|
+
validate_response(_response)
|
44
|
+
|
45
|
+
# Return appropriate response type.
|
46
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
47
|
+
SuccessResponse.from_hash(decoded)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Use this endpoint to retrieve your business’ profile. This business
|
51
|
+
# profile is visible to consumers in the chat thread next to the profile
|
52
|
+
# photo. The profile information will contain a business profile ID which
|
53
|
+
# you can use to make API calls.
|
54
|
+
# @param [String] phone_number_id Required parameter: Example:
|
55
|
+
# @param [String] fields Optional parameter: Here you can specify what you
|
56
|
+
# want to know from your business as a comma separated list of fields.
|
57
|
+
# Available fields include: id, about, messaging_product, address,
|
58
|
+
# description, vertical, email, websites, profile_picture_url
|
59
|
+
# @return [GetBusinessProfileIDResponse] response from the API call
|
60
|
+
def get_business_profile_id(phone_number_id,
|
61
|
+
fields: nil)
|
62
|
+
# Prepare query url.
|
63
|
+
_query_builder = config.get_base_uri
|
64
|
+
_query_builder << '/{Phone-Number-ID}/whatsapp_business_profile'
|
65
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
66
|
+
_query_builder,
|
67
|
+
'Phone-Number-ID' => { 'value' => phone_number_id, 'encode' => true }
|
68
|
+
)
|
69
|
+
_query_builder = APIHelper.append_url_with_query_parameters(
|
70
|
+
_query_builder,
|
71
|
+
'fields' => fields
|
72
|
+
)
|
73
|
+
_query_url = APIHelper.clean_url _query_builder
|
74
|
+
|
75
|
+
# Prepare headers.
|
76
|
+
_headers = {
|
77
|
+
'accept' => 'application/json'
|
78
|
+
}
|
79
|
+
|
80
|
+
# Prepare and execute HttpRequest.
|
81
|
+
_request = config.http_client.get(
|
82
|
+
_query_url,
|
83
|
+
headers: _headers
|
84
|
+
)
|
85
|
+
OAuth2.apply(config, _request)
|
86
|
+
_response = execute_request(_request)
|
87
|
+
validate_response(_response)
|
88
|
+
|
89
|
+
# Return appropriate response type.
|
90
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
91
|
+
GetBusinessProfileIDResponse.from_hash(decoded)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# whats_app_cloud_api
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module WhatsAppCloudApi
|
7
|
+
# MediaController
|
8
|
+
class MediaController < BaseController
|
9
|
+
def initialize(config, http_call_back: nil)
|
10
|
+
super(config, http_call_back: http_call_back)
|
11
|
+
end
|
12
|
+
|
13
|
+
# This endpoint can be used for deleting a media object.
|
14
|
+
# @param [String] media_id Required parameter: Media object ID from either
|
15
|
+
# uploading media endpoint or media message Webhooks
|
16
|
+
# @return [SuccessResponse] response from the API call
|
17
|
+
def delete_media(media_id)
|
18
|
+
# Prepare query url.
|
19
|
+
_query_builder = config.get_base_uri
|
20
|
+
_query_builder << '/{Media-ID}'
|
21
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
22
|
+
_query_builder,
|
23
|
+
'Media-ID' => { 'value' => media_id, 'encode' => true }
|
24
|
+
)
|
25
|
+
_query_url = APIHelper.clean_url _query_builder
|
26
|
+
|
27
|
+
# Prepare headers.
|
28
|
+
_headers = {
|
29
|
+
'accept' => 'application/json'
|
30
|
+
}
|
31
|
+
|
32
|
+
# Prepare and execute HttpRequest.
|
33
|
+
_request = config.http_client.delete(
|
34
|
+
_query_url,
|
35
|
+
headers: _headers
|
36
|
+
)
|
37
|
+
OAuth2.apply(config, _request)
|
38
|
+
_response = execute_request(_request)
|
39
|
+
validate_response(_response)
|
40
|
+
|
41
|
+
# Return appropriate response type.
|
42
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
43
|
+
SuccessResponse.from_hash(decoded)
|
44
|
+
end
|
45
|
+
|
46
|
+
# To retrieve your media’s URL, make a request to this endpoint. Later, you
|
47
|
+
# can use this URL to download the media file.
|
48
|
+
# @param [String] media_id Required parameter: Media object ID from either
|
49
|
+
# uploading media endpoint or media message Webhooks
|
50
|
+
# @return [RetrieveMediaURLResponse] response from the API call
|
51
|
+
def retrieve_media_url(media_id)
|
52
|
+
# Prepare query url.
|
53
|
+
_query_builder = config.get_base_uri
|
54
|
+
_query_builder << '/{Media-ID}'
|
55
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
56
|
+
_query_builder,
|
57
|
+
'Media-ID' => { 'value' => media_id, 'encode' => true }
|
58
|
+
)
|
59
|
+
_query_url = APIHelper.clean_url _query_builder
|
60
|
+
|
61
|
+
# Prepare headers.
|
62
|
+
_headers = {
|
63
|
+
'accept' => 'application/json'
|
64
|
+
}
|
65
|
+
|
66
|
+
# Prepare and execute HttpRequest.
|
67
|
+
_request = config.http_client.get(
|
68
|
+
_query_url,
|
69
|
+
headers: _headers
|
70
|
+
)
|
71
|
+
OAuth2.apply(config, _request)
|
72
|
+
_response = execute_request(_request)
|
73
|
+
validate_response(_response)
|
74
|
+
|
75
|
+
# Return appropriate response type.
|
76
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
77
|
+
RetrieveMediaURLResponse.from_hash(decoded)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Used to upload media. All media files sent through this endpoint are
|
81
|
+
# encrypted and persist for 30 days.
|
82
|
+
# @param [String] phone_number_id Required parameter: Example:
|
83
|
+
# @param [String] messaging_product Required parameter: Messaging service
|
84
|
+
# used for the request. In this case, use whatsapp.
|
85
|
+
# @param [String] file Required parameter: Path to the file stored in your
|
86
|
+
# local directory. For example: "@/local/path/file.jpg".
|
87
|
+
# @param [String] type Required parameter: Type of media file being
|
88
|
+
# uploaded. See Supported Media Types for more information. Supported
|
89
|
+
# options for images are: `image/jpeg`, `image/png` Supported options for
|
90
|
+
# documents are: `text/plain`, `application/pdf`,
|
91
|
+
# `application/vnd.ms-powerpoint`, `application/msword`,
|
92
|
+
# `application/vnd.ms-excel`,
|
93
|
+
# `application/vnd.openxmlformats-officedocument.wordprocessingml.document`,
|
94
|
+
# `application/vnd.openxmlformats-officedocument.presentationml.presentation
|
95
|
+
# `, `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`
|
96
|
+
# Supported options for audio are: `audio/aac`, `audio/mp4`, `audio/mpeg`,
|
97
|
+
# `audio/amr`, `audio/ogg`, `audio/opus` Supported options for video are:
|
98
|
+
# `video/mp4`, `video/3gp` Supported options for stickers are:
|
99
|
+
# `image/webp`
|
100
|
+
# @return [UploadMedia] response from the API call
|
101
|
+
def upload_media(phone_number_id,
|
102
|
+
messaging_product,
|
103
|
+
file,
|
104
|
+
type)
|
105
|
+
# Prepare query url.
|
106
|
+
_query_builder = config.get_base_uri
|
107
|
+
_query_builder << '/{Phone-Number-ID}/media'
|
108
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
109
|
+
_query_builder,
|
110
|
+
'Phone-Number-ID' => { 'value' => phone_number_id, 'encode' => true }
|
111
|
+
)
|
112
|
+
_query_url = APIHelper.clean_url _query_builder
|
113
|
+
|
114
|
+
# Prepare headers.
|
115
|
+
_headers = {
|
116
|
+
'accept' => 'application/json'
|
117
|
+
}
|
118
|
+
|
119
|
+
# Prepare form parameters.
|
120
|
+
_parameters = {
|
121
|
+
'messaging_product' => messaging_product,
|
122
|
+
'file' => file,
|
123
|
+
'type' => type
|
124
|
+
}
|
125
|
+
_parameters = APIHelper.form_encode_parameters(_parameters)
|
126
|
+
|
127
|
+
# Prepare and execute HttpRequest.
|
128
|
+
_request = config.http_client.post(
|
129
|
+
_query_url,
|
130
|
+
headers: _headers,
|
131
|
+
parameters: _parameters
|
132
|
+
)
|
133
|
+
OAuth2.apply(config, _request)
|
134
|
+
_response = execute_request(_request)
|
135
|
+
validate_response(_response)
|
136
|
+
|
137
|
+
# Return appropriate response type.
|
138
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
139
|
+
UploadMedia.from_hash(decoded)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# whats_app_cloud_api
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module WhatsAppCloudApi
|
7
|
+
# MessagesController
|
8
|
+
class MessagesController < BaseController
|
9
|
+
def initialize(config, http_call_back: nil)
|
10
|
+
super(config, http_call_back: http_call_back)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Use this endpoint to send text messages, media, message templates to your
|
14
|
+
# customers.
|
15
|
+
# @param [String] phone_number_id Required parameter: Example:
|
16
|
+
# @param [Message] body Required parameter: To send a message, you must
|
17
|
+
# first assemble a message object with the content you want to send.
|
18
|
+
# @return [SendMessageResponse] response from the API call
|
19
|
+
def send_message(phone_number_id,
|
20
|
+
body)
|
21
|
+
# Prepare query url.
|
22
|
+
_query_builder = config.get_base_uri
|
23
|
+
_query_builder << '/{Phone-Number-ID}/messages'
|
24
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
25
|
+
_query_builder,
|
26
|
+
'Phone-Number-ID' => { 'value' => phone_number_id, 'encode' => true }
|
27
|
+
)
|
28
|
+
_query_url = APIHelper.clean_url _query_builder
|
29
|
+
|
30
|
+
# Prepare headers.
|
31
|
+
_headers = {
|
32
|
+
'accept' => 'application/json',
|
33
|
+
'Content-Type' => 'application/json'
|
34
|
+
}
|
35
|
+
|
36
|
+
# Prepare and execute HttpRequest.
|
37
|
+
_request = config.http_client.post(
|
38
|
+
_query_url,
|
39
|
+
headers: _headers,
|
40
|
+
parameters: body.to_json
|
41
|
+
)
|
42
|
+
OAuth2.apply(config, _request)
|
43
|
+
_response = execute_request(_request)
|
44
|
+
validate_response(_response)
|
45
|
+
|
46
|
+
# Return appropriate response type.
|
47
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
48
|
+
SendMessageResponse.from_hash(decoded)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
# whats_app_cloud_api
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module WhatsAppCloudApi
|
7
|
+
# PhoneNumbersController
|
8
|
+
class PhoneNumbersController < BaseController
|
9
|
+
def initialize(config, http_call_back: nil)
|
10
|
+
super(config, http_call_back: http_call_back)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Used to verify a phone number's ownership. After you have received a SMS
|
14
|
+
# or Voice request code for verification, you need to verify the code that
|
15
|
+
# was sent to you.
|
16
|
+
# @param [String] phone_number_id Required parameter: Example:
|
17
|
+
# @param [String] code Required parameter: The code you received after
|
18
|
+
# calling FROM_PHONE_NUMBER_ID/request_code.
|
19
|
+
# @return [SuccessResponse] response from the API call
|
20
|
+
def verify_code(phone_number_id,
|
21
|
+
code)
|
22
|
+
# Prepare query url.
|
23
|
+
_query_builder = config.get_base_uri
|
24
|
+
_query_builder << '/{Phone-Number-ID}/verify_code'
|
25
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
26
|
+
_query_builder,
|
27
|
+
'Phone-Number-ID' => { 'value' => phone_number_id, 'encode' => true }
|
28
|
+
)
|
29
|
+
_query_url = APIHelper.clean_url _query_builder
|
30
|
+
|
31
|
+
# Prepare headers.
|
32
|
+
_headers = {
|
33
|
+
'accept' => 'application/json'
|
34
|
+
}
|
35
|
+
|
36
|
+
# Prepare form parameters.
|
37
|
+
_parameters = {
|
38
|
+
'code' => code
|
39
|
+
}
|
40
|
+
_parameters = APIHelper.form_encode_parameters(_parameters)
|
41
|
+
|
42
|
+
# Prepare and execute HttpRequest.
|
43
|
+
_request = config.http_client.post(
|
44
|
+
_query_url,
|
45
|
+
headers: _headers,
|
46
|
+
parameters: _parameters
|
47
|
+
)
|
48
|
+
OAuth2.apply(config, _request)
|
49
|
+
_response = execute_request(_request)
|
50
|
+
validate_response(_response)
|
51
|
+
|
52
|
+
# Return appropriate response type.
|
53
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
54
|
+
SuccessResponse.from_hash(decoded)
|
55
|
+
end
|
56
|
+
|
57
|
+
# When you query all the phone numbers for a WhatsApp Business Account, each
|
58
|
+
# phone number has an id. You can directly query for a phone number using
|
59
|
+
# this id.
|
60
|
+
# @param [String] phone_number_id Required parameter: Example:
|
61
|
+
# @return [GetPhoneNumberByIDResponse] response from the API call
|
62
|
+
def get_phone_number_by_id(phone_number_id)
|
63
|
+
# Prepare query url.
|
64
|
+
_query_builder = config.get_base_uri
|
65
|
+
_query_builder << '/{Phone-Number-ID}'
|
66
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
67
|
+
_query_builder,
|
68
|
+
'Phone-Number-ID' => { 'value' => phone_number_id, 'encode' => true }
|
69
|
+
)
|
70
|
+
_query_url = APIHelper.clean_url _query_builder
|
71
|
+
|
72
|
+
# Prepare headers.
|
73
|
+
_headers = {
|
74
|
+
'accept' => 'application/json'
|
75
|
+
}
|
76
|
+
|
77
|
+
# Prepare and execute HttpRequest.
|
78
|
+
_request = config.http_client.get(
|
79
|
+
_query_url,
|
80
|
+
headers: _headers
|
81
|
+
)
|
82
|
+
OAuth2.apply(config, _request)
|
83
|
+
_response = execute_request(_request)
|
84
|
+
validate_response(_response)
|
85
|
+
|
86
|
+
# Return appropriate response type.
|
87
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
88
|
+
GetPhoneNumberByIDResponse.from_hash(decoded)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Used to request a code to verify a phone number's ownership. You need to
|
92
|
+
# verify the phone number you want to use to send messages to your
|
93
|
+
# customers. Phone numbers must be verified through SMS/voice call. The
|
94
|
+
# verification process can be done through the Graph API calls specified
|
95
|
+
# below.
|
96
|
+
# @param [String] phone_number_id Required parameter: Example:
|
97
|
+
# @param [RequestVerificationCodeMethodEnum] code_method Required parameter:
|
98
|
+
# Chosen method for verification.
|
99
|
+
# @param [String] locale Required parameter: Your locale. For example:
|
100
|
+
# "en_US".
|
101
|
+
# @return [SuccessResponse] response from the API call
|
102
|
+
def request_verification_code(phone_number_id,
|
103
|
+
code_method,
|
104
|
+
locale)
|
105
|
+
# Prepare query url.
|
106
|
+
_query_builder = config.get_base_uri
|
107
|
+
_query_builder << '/{Phone-Number-ID}/request_code'
|
108
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
109
|
+
_query_builder,
|
110
|
+
'Phone-Number-ID' => { 'value' => phone_number_id, 'encode' => true }
|
111
|
+
)
|
112
|
+
_query_url = APIHelper.clean_url _query_builder
|
113
|
+
|
114
|
+
# Prepare headers.
|
115
|
+
_headers = {
|
116
|
+
'accept' => 'application/json'
|
117
|
+
}
|
118
|
+
|
119
|
+
# Prepare form parameters.
|
120
|
+
_parameters = {
|
121
|
+
'code_method' => code_method,
|
122
|
+
'locale' => locale
|
123
|
+
}
|
124
|
+
_parameters = APIHelper.form_encode_parameters(_parameters)
|
125
|
+
|
126
|
+
# Prepare and execute HttpRequest.
|
127
|
+
_request = config.http_client.post(
|
128
|
+
_query_url,
|
129
|
+
headers: _headers,
|
130
|
+
parameters: _parameters
|
131
|
+
)
|
132
|
+
OAuth2.apply(config, _request)
|
133
|
+
_response = execute_request(_request)
|
134
|
+
validate_response(_response)
|
135
|
+
|
136
|
+
# Return appropriate response type.
|
137
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
138
|
+
SuccessResponse.from_hash(decoded)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# whats_app_cloud_api
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module WhatsAppCloudApi
|
7
|
+
# RegistrationController
|
8
|
+
class RegistrationController < BaseController
|
9
|
+
def initialize(config, http_call_back: nil)
|
10
|
+
super(config, http_call_back: http_call_back)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Used to register a phone number or to migrate WhatsApp Business Accounts
|
14
|
+
# from a current On-Premises deployment to the new Cloud-Based API. Business
|
15
|
+
# Solution Providers (BSPs) must authenticate themselves with an access
|
16
|
+
# token with the whatsapp_business_management permission.
|
17
|
+
# @param [String] phone_number_id Required parameter: Example:
|
18
|
+
# @param [RegisterPhoneRequest] body Required parameter: Example:
|
19
|
+
# @return [SuccessResponse] response from the API call
|
20
|
+
def register_phone(phone_number_id,
|
21
|
+
body)
|
22
|
+
# Prepare query url.
|
23
|
+
_query_builder = config.get_base_uri
|
24
|
+
_query_builder << '/{Phone-Number-ID}/register'
|
25
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
26
|
+
_query_builder,
|
27
|
+
'Phone-Number-ID' => { 'value' => phone_number_id, 'encode' => true }
|
28
|
+
)
|
29
|
+
_query_url = APIHelper.clean_url _query_builder
|
30
|
+
|
31
|
+
# Prepare headers.
|
32
|
+
_headers = {
|
33
|
+
'accept' => 'application/json',
|
34
|
+
'Content-Type' => 'application/json'
|
35
|
+
}
|
36
|
+
|
37
|
+
# Prepare and execute HttpRequest.
|
38
|
+
_request = config.http_client.post(
|
39
|
+
_query_url,
|
40
|
+
headers: _headers,
|
41
|
+
parameters: body.to_json
|
42
|
+
)
|
43
|
+
OAuth2.apply(config, _request)
|
44
|
+
_response = execute_request(_request)
|
45
|
+
validate_response(_response)
|
46
|
+
|
47
|
+
# Return appropriate response type.
|
48
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
49
|
+
SuccessResponse.from_hash(decoded)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Used to deregister a phone number. Deregister phone removes a previously
|
53
|
+
# registered phone. You can always re-register your phone using by repeating
|
54
|
+
# the registration process. Business Solution Providers (BSPs) must
|
55
|
+
# authenticate themselves with an access token with the
|
56
|
+
# whatsapp_business_management permission.
|
57
|
+
# @param [ContentTypeEnum] content_type Required parameter: Example:
|
58
|
+
# @param [String] phone_number_id Required parameter: Example:
|
59
|
+
# @return [SuccessResponse] response from the API call
|
60
|
+
def deregister_phone(content_type,
|
61
|
+
phone_number_id)
|
62
|
+
# Prepare query url.
|
63
|
+
_query_builder = config.get_base_uri
|
64
|
+
_query_builder << '/{Phone-Number-ID}/deregister'
|
65
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
66
|
+
_query_builder,
|
67
|
+
'Phone-Number-ID' => { 'value' => phone_number_id, 'encode' => true }
|
68
|
+
)
|
69
|
+
_query_url = APIHelper.clean_url _query_builder
|
70
|
+
|
71
|
+
# Prepare headers.
|
72
|
+
_headers = {
|
73
|
+
'accept' => 'application/json',
|
74
|
+
'Content-Type' => content_type
|
75
|
+
}
|
76
|
+
|
77
|
+
# Prepare and execute HttpRequest.
|
78
|
+
_request = config.http_client.post(
|
79
|
+
_query_url,
|
80
|
+
headers: _headers
|
81
|
+
)
|
82
|
+
OAuth2.apply(config, _request)
|
83
|
+
_response = execute_request(_request)
|
84
|
+
validate_response(_response)
|
85
|
+
|
86
|
+
# Return appropriate response type.
|
87
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
88
|
+
SuccessResponse.from_hash(decoded)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# whats_app_cloud_api
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module WhatsAppCloudApi
|
7
|
+
# TwoStepVerificationController
|
8
|
+
class TwoStepVerificationController < BaseController
|
9
|
+
def initialize(config, http_call_back: nil)
|
10
|
+
super(config, http_call_back: http_call_back)
|
11
|
+
end
|
12
|
+
|
13
|
+
# You are required to set up two-step verification for your phone number, as
|
14
|
+
# this provides an extra layer of security to the business accounts. You can
|
15
|
+
# use this endpoint to change two-step verification code associated with
|
16
|
+
# your account.
|
17
|
+
# After you change the verification code, future requests like changing the
|
18
|
+
# name, must use the new code.
|
19
|
+
# You set up two-factor verification and register a phone number in the same
|
20
|
+
# API call.
|
21
|
+
# @param [String] phone_number_id Required parameter: Example:
|
22
|
+
# @param [SetTwoStepVerificationCodeRequest] body Required parameter:
|
23
|
+
# Example:
|
24
|
+
# @return [SuccessResponse] response from the API call
|
25
|
+
def set_two_step_verification_code(phone_number_id,
|
26
|
+
body)
|
27
|
+
# Prepare query url.
|
28
|
+
_query_builder = config.get_base_uri
|
29
|
+
_query_builder << '/{Phone-Number-ID}'
|
30
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
31
|
+
_query_builder,
|
32
|
+
'Phone-Number-ID' => { 'value' => phone_number_id, 'encode' => true }
|
33
|
+
)
|
34
|
+
_query_url = APIHelper.clean_url _query_builder
|
35
|
+
|
36
|
+
# Prepare headers.
|
37
|
+
_headers = {
|
38
|
+
'accept' => 'application/json',
|
39
|
+
'Content-Type' => 'application/json'
|
40
|
+
}
|
41
|
+
|
42
|
+
# Prepare and execute HttpRequest.
|
43
|
+
_request = config.http_client.post(
|
44
|
+
_query_url,
|
45
|
+
headers: _headers,
|
46
|
+
parameters: body.to_json
|
47
|
+
)
|
48
|
+
OAuth2.apply(config, _request)
|
49
|
+
_response = execute_request(_request)
|
50
|
+
validate_response(_response)
|
51
|
+
|
52
|
+
# Return appropriate response type.
|
53
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
54
|
+
SuccessResponse.from_hash(decoded)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# whats_app_cloud_api
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module WhatsAppCloudApi
|
7
|
+
# Class for exceptions when there is a network error, status code error, etc.
|
8
|
+
class APIException < StandardError
|
9
|
+
attr_reader :response, :response_code
|
10
|
+
|
11
|
+
# The constructor.
|
12
|
+
# @param [String] The reason for raising an exception.
|
13
|
+
# @param [HttpResponse] The HttpReponse of the API call.
|
14
|
+
def initialize(reason, response)
|
15
|
+
super(reason)
|
16
|
+
@response = response
|
17
|
+
@response_code = response.status_code
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# whats_app_cloud_api
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module WhatsAppCloudApi
|
7
|
+
# Utility class for OAuth 2 authorization and token management.
|
8
|
+
class OAuth2
|
9
|
+
# Add OAuth2 authentication to the http request.
|
10
|
+
# @param [HttpRequest] The HttpRequest object to which authentication will
|
11
|
+
# be added.
|
12
|
+
def self.apply(config, http_request)
|
13
|
+
token = config.access_token
|
14
|
+
http_request.headers['Authorization'] = "Bearer #{token}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|