whatsapp-ruby-sdk 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +28 -0
  3. data/README.md +85 -0
  4. data/lib/whats_app_cloud_api/api_helper.rb +277 -0
  5. data/lib/whats_app_cloud_api/client.rb +68 -0
  6. data/lib/whats_app_cloud_api/configuration.rb +132 -0
  7. data/lib/whats_app_cloud_api/controllers/base_controller.rb +52 -0
  8. data/lib/whats_app_cloud_api/controllers/business_profiles_controller.rb +94 -0
  9. data/lib/whats_app_cloud_api/controllers/media_controller.rb +142 -0
  10. data/lib/whats_app_cloud_api/controllers/messages_controller.rb +51 -0
  11. data/lib/whats_app_cloud_api/controllers/phone_numbers_controller.rb +141 -0
  12. data/lib/whats_app_cloud_api/controllers/registration_controller.rb +91 -0
  13. data/lib/whats_app_cloud_api/controllers/two_step_verification_controller.rb +57 -0
  14. data/lib/whats_app_cloud_api/exceptions/api_exception.rb +20 -0
  15. data/lib/whats_app_cloud_api/http/auth/o_auth2.rb +17 -0
  16. data/lib/whats_app_cloud_api/http/faraday_client.rb +97 -0
  17. data/lib/whats_app_cloud_api/http/http_call_back.rb +24 -0
  18. data/lib/whats_app_cloud_api/http/http_client.rb +123 -0
  19. data/lib/whats_app_cloud_api/http/http_method_enum.rb +13 -0
  20. data/lib/whats_app_cloud_api/http/http_request.rb +54 -0
  21. data/lib/whats_app_cloud_api/http/http_response.rb +29 -0
  22. data/lib/whats_app_cloud_api/models/action.rb +91 -0
  23. data/lib/whats_app_cloud_api/models/address.rb +110 -0
  24. data/lib/whats_app_cloud_api/models/audio.rb +61 -0
  25. data/lib/whats_app_cloud_api/models/base_model.rb +58 -0
  26. data/lib/whats_app_cloud_api/models/body.rb +49 -0
  27. data/lib/whats_app_cloud_api/models/business_profile.rb +123 -0
  28. data/lib/whats_app_cloud_api/models/button.rb +71 -0
  29. data/lib/whats_app_cloud_api/models/button_parameter.rb +72 -0
  30. data/lib/whats_app_cloud_api/models/button_parameter_type_enum.rb +17 -0
  31. data/lib/whats_app_cloud_api/models/component.rb +83 -0
  32. data/lib/whats_app_cloud_api/models/component_type_enum.rb +20 -0
  33. data/lib/whats_app_cloud_api/models/contact.rb +145 -0
  34. data/lib/whats_app_cloud_api/models/content_type_enum.rb +14 -0
  35. data/lib/whats_app_cloud_api/models/currency.rb +67 -0
  36. data/lib/whats_app_cloud_api/models/date_time_object.rb +128 -0
  37. data/lib/whats_app_cloud_api/models/document.rb +81 -0
  38. data/lib/whats_app_cloud_api/models/email_object.rb +60 -0
  39. data/lib/whats_app_cloud_api/models/footer.rb +49 -0
  40. data/lib/whats_app_cloud_api/models/get_business_profile_id_response.rb +57 -0
  41. data/lib/whats_app_cloud_api/models/get_phone_number_by_id_response.rb +78 -0
  42. data/lib/whats_app_cloud_api/models/header.rb +93 -0
  43. data/lib/whats_app_cloud_api/models/header_type_enum.rb +23 -0
  44. data/lib/whats_app_cloud_api/models/image.rb +71 -0
  45. data/lib/whats_app_cloud_api/models/interactive.rb +87 -0
  46. data/lib/whats_app_cloud_api/models/interactive_type_enum.rb +17 -0
  47. data/lib/whats_app_cloud_api/models/language.rb +60 -0
  48. data/lib/whats_app_cloud_api/models/location.rb +78 -0
  49. data/lib/whats_app_cloud_api/models/message.rb +194 -0
  50. data/lib/whats_app_cloud_api/models/message_type_enum.rb +41 -0
  51. data/lib/whats_app_cloud_api/models/name.rb +100 -0
  52. data/lib/whats_app_cloud_api/models/org.rb +70 -0
  53. data/lib/whats_app_cloud_api/models/parameter.rb +113 -0
  54. data/lib/whats_app_cloud_api/models/parameter_type_enum.rb +29 -0
  55. data/lib/whats_app_cloud_api/models/personal_information_type_enum.rb +17 -0
  56. data/lib/whats_app_cloud_api/models/phone_object.rb +70 -0
  57. data/lib/whats_app_cloud_api/models/phone_type_enum.rb +26 -0
  58. data/lib/whats_app_cloud_api/models/quality_rating_enum.rb +25 -0
  59. data/lib/whats_app_cloud_api/models/register_phone_request.rb +58 -0
  60. data/lib/whats_app_cloud_api/models/request_verification_code_method_enum.rb +17 -0
  61. data/lib/whats_app_cloud_api/models/request_verification_code_request.rb +57 -0
  62. data/lib/whats_app_cloud_api/models/response_contact.rb +57 -0
  63. data/lib/whats_app_cloud_api/models/response_message.rb +48 -0
  64. data/lib/whats_app_cloud_api/models/retrieve_media_url_response.rb +94 -0
  65. data/lib/whats_app_cloud_api/models/row.rb +68 -0
  66. data/lib/whats_app_cloud_api/models/section.rb +72 -0
  67. data/lib/whats_app_cloud_api/models/send_message_response.rb +85 -0
  68. data/lib/whats_app_cloud_api/models/set_two_step_verification_code_request.rb +48 -0
  69. data/lib/whats_app_cloud_api/models/sticker.rb +61 -0
  70. data/lib/whats_app_cloud_api/models/sub_type_enum.rb +20 -0
  71. data/lib/whats_app_cloud_api/models/success_response.rb +48 -0
  72. data/lib/whats_app_cloud_api/models/template.rb +78 -0
  73. data/lib/whats_app_cloud_api/models/text.rb +72 -0
  74. data/lib/whats_app_cloud_api/models/update_business_profile_request.rb +116 -0
  75. data/lib/whats_app_cloud_api/models/upload_media.rb +48 -0
  76. data/lib/whats_app_cloud_api/models/upload_media_request.rb +80 -0
  77. data/lib/whats_app_cloud_api/models/url_object.rb +60 -0
  78. data/lib/whats_app_cloud_api/models/verify_code_request.rb +48 -0
  79. data/lib/whats_app_cloud_api/models/vertical_enum.rb +68 -0
  80. data/lib/whats_app_cloud_api/models/video.rb +61 -0
  81. data/lib/whats_app_cloud_api/utilities/date_time_helper.rb +156 -0
  82. data/lib/whats_app_cloud_api/utilities/file_wrapper.rb +16 -0
  83. data/lib/whats_app_cloud_api.rb +104 -0
  84. metadata +266 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 135d887ffef729da0fe2d5683bc829c4a24769886173503061698fb331c37c95
4
+ data.tar.gz: d6a1421398e7440bc90e4ecfabc960de2d32ba83feccffd7e6495d60e5389a58
5
+ SHA512:
6
+ metadata.gz: 53c97158cf0ac6838076325a63a8478cd49aeb8962df88282512388dc0bd8c7d4c26deecae21da234b5fc91c54cfd92d4cd13a46d9eab1c44a7dc2fcb972a870
7
+ data.tar.gz: 7adb978fb903dc7b054eb33504cb85263c0fca41da57ee675f4ebb509c382ee3248b8a2d0f68f7be522318d9e8e14eea190ddb136fc77293b976656a94b3892e
data/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ License:
2
+ ========
3
+ The MIT License (MIT)
4
+ http://opensource.org/licenses/MIT
5
+
6
+ Copyright (c) 2014 - 2022 APIMATIC Limited
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
25
+
26
+ Trade Mark:
27
+ ==========
28
+ APIMATIC is a trade mark for APIMATIC Limited
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+
2
+ # Getting Started with WhatsApp Cloud API
3
+
4
+ ## Introduction
5
+
6
+ Welcome to the WhatsApp API from Meta.
7
+
8
+ Individual developers and existing Business Service Providers (BSPs) can now send and receive messages via the WhatsApp API using a cloud-hosted version of the WhatsApp Business API. Compared to the previous solutions, the cloud-based WhatsApp API is simpler to use and is a more cost-effective way for businesses to use WhatsApp. Please keep in mind the following configurations:
9
+
10
+ | Name | Description |
11
+ | --- | --- |
12
+ | Version | Latest [Graph API version](https://developers.facebook.com/docs/graph-api/). For example: v13.0 |
13
+ | User-Access-Token | Your user access token after signing up at [developers.facebook.com](https://developers.facebook.com). |
14
+ | WABA-ID | Your WhatsApp Business Account (WABA) ID. |
15
+ | Phone-Number-ID | ID for the phone number connected to the WhatsApp Business API. You can get this with a [Get Phone Number ID request](3184f675-d289-46f1-88e5-e2b11549c418). |
16
+ | Business-ID | Your Business' ID. Once you have your Phone-Number-ID, make a [Get Business Profile request](#99fd3743-46cf-46c4-95b5-431c6a4eb0b0) to get your Business' ID. |
17
+ | Recipient-Phone-Number | Phone number that you want to send a WhatsApp message to. |
18
+ | Media-ID | ID for the media to [send a media message](#0a632754-3788-43bf-b785-ac6a73423d5a) or [media template message](#439c926a-8a6c-4972-ab2c-d99297716da9) to your customers. |
19
+ | Media-URL | URL for the media to [download media content](#cbe5ece3-246c-48f3-b338-074187dfef66). |
20
+
21
+ ## Install the Package
22
+
23
+ Install the gem from the command line:
24
+
25
+ ```ruby
26
+ gem install whatsapp-ruby-sdk -v 1.0.0
27
+ ```
28
+
29
+ Or add the gem to your Gemfile and run `bundle`:
30
+
31
+ ```ruby
32
+ gem 'whatsapp-ruby-sdk', '1.0.0'
33
+ ```
34
+
35
+ For additional gem details, see the [RubyGems page for the whatsapp-ruby-sdk gem](https://rubygems.org/gems/whatsapp-ruby-sdk/versions/1.0.0).
36
+
37
+ ## Initialize the API Client
38
+
39
+ **_Note:_** Documentation for the client can be found [here.](doc/client.md)
40
+
41
+ The following parameters are configurable for the API Client:
42
+
43
+ | Parameter | Type | Description |
44
+ | --- | --- | --- |
45
+ | `access_token` | `String` | The OAuth 2.0 Access Token to use for API requests. |
46
+ | `version` | `String` | *Default*: `'v13.0'` |
47
+ | `environment` | Environment | The API environment. <br> **Default: `Environment.PRODUCTION`** |
48
+ | `connection` | `Faraday::Connection` | The Faraday connection object passed by the SDK user for making requests |
49
+ | `adapter` | `Faraday::Adapter` | The Faraday adapter object passed by the SDK user for performing http requests |
50
+ | `timeout` | `Float` | The value to use for connection timeout. <br> **Default: 60** |
51
+ | `max_retries` | `Integer` | The number of times to retry an endpoint call if it fails. <br> **Default: 0** |
52
+ | `retry_interval` | `Float` | Pause in seconds between retries. <br> **Default: 1** |
53
+ | `backoff_factor` | `Float` | The amount to multiply each successive retry's interval amount by in order to provide backoff. <br> **Default: 2** |
54
+ | `retry_statuses` | `Array` | A list of HTTP statuses to retry. <br> **Default: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524]** |
55
+ | `retry_methods` | `Array` | A list of HTTP methods to retry. <br> **Default: %i[get put]** |
56
+
57
+ The API client can be initialized as follows:
58
+
59
+ ```ruby
60
+ client = WhatsAppCloudApi::Client.new(
61
+ access_token: 'AccessToken',
62
+ environment: Environment::PRODUCTION,
63
+ version: 'v13.0',
64
+ )
65
+ ```
66
+
67
+ ## Authorization
68
+
69
+ This API uses `OAuth 2 Bearer token`.
70
+
71
+ ## List of APIs
72
+
73
+ * [Business Profiles](doc/controllers/business-profiles.md)
74
+ * [Phone Numbers](doc/controllers/phone-numbers.md)
75
+ * [Two-Step Verification](doc/controllers/two-step-verification.md)
76
+ * [Messages](doc/controllers/messages.md)
77
+ * [Registration](doc/controllers/registration.md)
78
+ * [Media](doc/controllers/media.md)
79
+
80
+ ## Classes Documentation
81
+
82
+ * [Utility Classes](doc/utility-classes.md)
83
+ * [HttpResponse](doc/http-response.md)
84
+ * [HttpRequest](doc/http-request.md)
85
+
@@ -0,0 +1,277 @@
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
+ # API utility class
8
+ class APIHelper
9
+ # Serializes an array parameter (creates key value pairs).
10
+ # @param [String] The name of the parameter.
11
+ # @param [Array] The value of the parameter.
12
+ # @param [String] The format of the serialization.
13
+ def self.serialize_array(key, array, formatting: 'indexed')
14
+ tuples = []
15
+
16
+ tuples += case formatting
17
+ when 'csv'
18
+ [[key, array.map { |element| CGI.escape(element.to_s) }.join(',')]]
19
+ when 'psv'
20
+ [[key, array.map { |element| CGI.escape(element.to_s) }.join('|')]]
21
+ when 'tsv'
22
+ [[key, array.map { |element| CGI.escape(element.to_s) }.join("\t")]]
23
+ else
24
+ array.map { |element| [key, element] }
25
+ end
26
+ tuples
27
+ end
28
+
29
+ # Replaces template parameters in the given url.
30
+ # @param [String] The query string builder to replace the template
31
+ # parameters.
32
+ # @param [Hash] The parameters to replace in the url.
33
+ def self.append_url_with_template_parameters(query_builder, parameters)
34
+ # perform parameter validation
35
+ unless query_builder.instance_of? String
36
+ raise ArgumentError, 'Given value for parameter \"query_builder\" is
37
+ invalid.'
38
+ end
39
+
40
+ # Return if there are no parameters to replace.
41
+ return query_builder if parameters.nil?
42
+
43
+ parameters.each do |key, val|
44
+ if val.nil?
45
+ replace_value = ''
46
+ elsif val['value'].instance_of? Array
47
+ if val['encode'] == true
48
+ val['value'].map! { |element| CGI.escape(element.to_s) }
49
+ else
50
+ val['value'].map!(&:to_s)
51
+ end
52
+ replace_value = val['value'].join('/')
53
+ else
54
+ replace_value = if val['encode'] == true
55
+ CGI.escape(val['value'].to_s)
56
+ else
57
+ val['value'].to_s
58
+ end
59
+ end
60
+
61
+ # Find the template parameter and replace it with its value.
62
+ query_builder = query_builder.gsub("{#{key}}", replace_value)
63
+ end
64
+ query_builder
65
+ end
66
+
67
+ # Appends the given set of parameters to the given query string.
68
+ # @param [String] The query string builder to add the query parameters to.
69
+ # @param [Hash] The parameters to append.
70
+ def self.append_url_with_query_parameters(query_builder, parameters)
71
+ # Perform parameter validation.
72
+ unless query_builder.instance_of? String
73
+ raise ArgumentError, 'Given value for parameter \"query_builder\"
74
+ is invalid.'
75
+ end
76
+
77
+ # Return if there are no parameters to replace.
78
+ return query_builder if parameters.nil?
79
+
80
+ array_serialization = 'indexed'
81
+ parameters = process_complex_types_parameters(parameters, array_serialization)
82
+
83
+ parameters.each do |key, value|
84
+ seperator = query_builder.include?('?') ? '&' : '?'
85
+ unless value.nil?
86
+ if value.instance_of? Array
87
+ value.compact!
88
+ APIHelper.serialize_array(
89
+ key, value, formatting: array_serialization
90
+ ).each do |element|
91
+ seperator = query_builder.include?('?') ? '&' : '?'
92
+ query_builder += "#{seperator}#{element[0]}=#{element[1]}"
93
+ end
94
+ else
95
+ query_builder += "#{seperator}#{key}=#{CGI.escape(value.to_s)}"
96
+ end
97
+ end
98
+ end
99
+ query_builder
100
+ end
101
+
102
+ # Validates and processes the given Url.
103
+ # @param [String] The given Url to process.
104
+ # @return [String] Pre-processed Url as string.
105
+ def self.clean_url(url)
106
+ # Perform parameter validation.
107
+ raise ArgumentError, 'Invalid Url.' unless url.instance_of? String
108
+
109
+ # Ensure that the urls are absolute.
110
+ matches = url.match(%r{^(https?://[^/]+)})
111
+ raise ArgumentError, 'Invalid Url format.' if matches.nil?
112
+
113
+ # Get the http protocol match.
114
+ protocol = matches[1]
115
+
116
+ # Check if parameters exist.
117
+ index = url.index('?')
118
+
119
+ # Remove redundant forward slashes.
120
+ query = url[protocol.length...(!index.nil? ? index : url.length)]
121
+ query.gsub!(%r{//+}, '/')
122
+
123
+ # Get the parameters.
124
+ parameters = !index.nil? ? url[url.index('?')...url.length] : ''
125
+
126
+ # Return processed url.
127
+ protocol + query + parameters
128
+ end
129
+
130
+ # Parses JSON string.
131
+ # @param [String] A JSON string.
132
+ def self.json_deserialize(json)
133
+ JSON.parse(json)
134
+ rescue StandardError
135
+ raise TypeError, 'Server responded with invalid JSON.'
136
+ end
137
+
138
+ # Removes elements with empty values from a hash.
139
+ # @param [Hash] The hash to clean.
140
+ def self.clean_hash(hash)
141
+ hash.delete_if { |_key, value| value.to_s.strip.empty? }
142
+ end
143
+
144
+ # Form encodes a hash of parameters.
145
+ # @param [Hash] The hash of parameters to encode.
146
+ # @return [Hash] A hash with the same parameters form encoded.
147
+ def self.form_encode_parameters(form_parameters)
148
+ array_serialization = 'indexed'
149
+ encoded = {}
150
+ form_parameters.each do |key, value|
151
+ encoded.merge!(APIHelper.form_encode(value, key, formatting:
152
+ array_serialization))
153
+ end
154
+ encoded
155
+ end
156
+
157
+ # Process complex types in query_params.
158
+ # @param [Hash] The hash of query parameters.
159
+ # @return [Hash] A hash with the processed query parameters.
160
+ def self.process_complex_types_parameters(query_parameters, array_serialization)
161
+ processed_params = {}
162
+ query_parameters.each do |key, value|
163
+ processed_params.merge!(APIHelper.form_encode(value, key, formatting:
164
+ array_serialization))
165
+ end
166
+ processed_params
167
+ end
168
+
169
+ def self.custom_merge(a, b)
170
+ x = {}
171
+ a.each do |key, value_a|
172
+ b.each do |k, value_b|
173
+ next unless key == k
174
+
175
+ x[k] = []
176
+ if value_a.instance_of? Array
177
+ value_a.each do |v|
178
+ x[k].push(v)
179
+ end
180
+ else
181
+ x[k].push(value_a)
182
+ end
183
+ if value_b.instance_of? Array
184
+ value_b.each do |v|
185
+ x[k].push(v)
186
+ end
187
+ else
188
+ x[k].push(value_b)
189
+ end
190
+ a.delete(k)
191
+ b.delete(k)
192
+ end
193
+ end
194
+ x.merge!(a)
195
+ x.merge!(b)
196
+ x
197
+ end
198
+
199
+ # Form encodes an object.
200
+ # @param [Dynamic] An object to form encode.
201
+ # @param [String] The name of the object.
202
+ # @return [Hash] A form encoded representation of the object in the form
203
+ # of a hash.
204
+ def self.form_encode(obj, instance_name, formatting: 'indexed')
205
+ retval = {}
206
+
207
+ serializable_types = [String, Numeric, TrueClass,
208
+ FalseClass, Date, DateTime]
209
+
210
+ # If this is a structure, resolve it's field names.
211
+ obj = obj.to_hash if obj.is_a? BaseModel
212
+
213
+ # Create a form encoded hash for this object.
214
+ if obj.nil?
215
+ nil
216
+ elsif obj.instance_of? Array
217
+ if formatting == 'indexed'
218
+ obj.each_with_index do |value, index|
219
+ retval.merge!(APIHelper.form_encode(value, "#{instance_name}[#{index}]"))
220
+ end
221
+ elsif serializable_types.map { |x| obj[0].is_a? x }.any?
222
+ obj.each do |value|
223
+ abc = if formatting == 'unindexed'
224
+ APIHelper.form_encode(value, "#{instance_name}[]",
225
+ formatting: formatting)
226
+ else
227
+ APIHelper.form_encode(value, instance_name,
228
+ formatting: formatting)
229
+ end
230
+ retval = APIHelper.custom_merge(retval, abc)
231
+ end
232
+ else
233
+ obj.each_with_index do |value, index|
234
+ retval.merge!(APIHelper.form_encode(value, "#{instance_name}[#{index}]",
235
+ formatting: formatting))
236
+ end
237
+ end
238
+ elsif obj.instance_of? Hash
239
+ obj.each do |key, value|
240
+ retval.merge!(APIHelper.form_encode(value, "#{instance_name}[#{key}]",
241
+ formatting: formatting))
242
+ end
243
+ elsif obj.instance_of? File
244
+ retval[instance_name] = UploadIO.new(
245
+ obj, 'application/octet-stream', File.basename(obj.path)
246
+ )
247
+ else
248
+ retval[instance_name] = obj
249
+ end
250
+ retval
251
+ end
252
+
253
+ # Retrieves a field from a Hash/Array based on an Array of keys/indexes
254
+ # @param [Hash, Array] The hash to extract data from
255
+ # @param [Array<String, Integer>] The keys/indexes to use
256
+ # @return [Object] The extracted value
257
+ def self.map_response(obj, keys)
258
+ val = obj
259
+ begin
260
+ keys.each do |key|
261
+ val = if val.is_a? Array
262
+ if key.to_i.to_s == key
263
+ val[key.to_i]
264
+ else
265
+ val = nil
266
+ end
267
+ else
268
+ val.fetch(key.to_sym)
269
+ end
270
+ end
271
+ rescue NoMethodError, TypeError, IndexError
272
+ val = nil
273
+ end
274
+ val
275
+ end
276
+ end
277
+ end
@@ -0,0 +1,68 @@
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
+ # whats_app_cloud_api client class.
8
+ class Client
9
+ attr_reader :config
10
+
11
+ # Access to business_profiles controller.
12
+ # @return [BusinessProfilesController] Returns the controller instance.
13
+ def business_profiles
14
+ @business_profiles ||= BusinessProfilesController.new config
15
+ end
16
+
17
+ # Access to messages controller.
18
+ # @return [MessagesController] Returns the controller instance.
19
+ def messages
20
+ @messages ||= MessagesController.new config
21
+ end
22
+
23
+ # Access to media controller.
24
+ # @return [MediaController] Returns the controller instance.
25
+ def media
26
+ @media ||= MediaController.new config
27
+ end
28
+
29
+ # Access to phone_numbers controller.
30
+ # @return [PhoneNumbersController] Returns the controller instance.
31
+ def phone_numbers
32
+ @phone_numbers ||= PhoneNumbersController.new config
33
+ end
34
+
35
+ # Access to registration controller.
36
+ # @return [RegistrationController] Returns the controller instance.
37
+ def registration
38
+ @registration ||= RegistrationController.new config
39
+ end
40
+
41
+ # Access to two_step_verification controller.
42
+ # @return [TwoStepVerificationController] Returns the controller instance.
43
+ def two_step_verification
44
+ @two_step_verification ||= TwoStepVerificationController.new config
45
+ end
46
+
47
+ def initialize(connection: nil, adapter: Faraday.default_adapter,
48
+ timeout: 60, max_retries: 0, retry_interval: 1,
49
+ backoff_factor: 2,
50
+ retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
51
+ retry_methods: %i[get put],
52
+ environment: Environment::PRODUCTION, version: 'v13.0',
53
+ access_token: '', config: nil)
54
+ @config = if config.nil?
55
+ Configuration.new(connection: connection, adapter: adapter,
56
+ timeout: timeout, max_retries: max_retries,
57
+ retry_interval: retry_interval,
58
+ backoff_factor: backoff_factor,
59
+ retry_statuses: retry_statuses,
60
+ retry_methods: retry_methods,
61
+ environment: environment, version: version,
62
+ access_token: access_token)
63
+ else
64
+ config
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,132 @@
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
+ # An enum for SDK environments.
8
+ class Environment
9
+ ENVIRONMENT = [
10
+ PRODUCTION = 'production'.freeze
11
+ ].freeze
12
+ end
13
+
14
+ # An enum for API servers.
15
+ class Server
16
+ SERVER = [
17
+ DEFAULT = 'default'.freeze
18
+ ].freeze
19
+ end
20
+
21
+ # All configuration including auth info and base URI for the API access
22
+ # are configured in this class.
23
+ class Configuration
24
+ # The attribute readers for properties.
25
+ attr_reader :http_client, :connection, :adapter, :timeout, :max_retries, :retry_interval,
26
+ :backoff_factor, :retry_statuses, :retry_methods, :environment, :version,
27
+ :access_token
28
+
29
+ class << self
30
+ attr_reader :environments
31
+ end
32
+
33
+ def initialize(connection: nil, adapter: Faraday.default_adapter,
34
+ timeout: 60, max_retries: 0, retry_interval: 1,
35
+ backoff_factor: 2,
36
+ retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
37
+ retry_methods: %i[get put],
38
+ environment: Environment::PRODUCTION, version: 'v13.0',
39
+ access_token: '')
40
+ # The Faraday connection object passed by the SDK user for making requests
41
+ @connection = connection
42
+
43
+ # The Faraday adapter object passed by the SDK user for performing http requests
44
+ @adapter = adapter
45
+
46
+ # The value to use for connection timeout
47
+ @timeout = timeout
48
+
49
+ # The number of times to retry an endpoint call if it fails
50
+ @max_retries = max_retries
51
+
52
+ # Pause in seconds between retries
53
+ @retry_interval = retry_interval
54
+
55
+ # The amount to multiply each successive retry's interval amount
56
+ # by in order to provide backoff
57
+ @backoff_factor = backoff_factor
58
+
59
+ # A list of HTTP statuses to retry
60
+ @retry_statuses = retry_statuses
61
+
62
+ # A list of HTTP methods to retry
63
+ @retry_methods = retry_methods
64
+
65
+ # Current API environment
66
+ @environment = String(environment)
67
+
68
+ # version value
69
+ @version = version
70
+
71
+ # The OAuth 2.0 Access Token to use for API requests.
72
+ @access_token = access_token
73
+
74
+ # The Http Client to use for making requests.
75
+ @http_client = create_http_client
76
+ end
77
+
78
+ def clone_with(connection: nil, adapter: nil, timeout: nil,
79
+ max_retries: nil, retry_interval: nil, backoff_factor: nil,
80
+ retry_statuses: nil, retry_methods: nil, environment: nil,
81
+ version: nil, access_token: nil)
82
+ connection ||= self.connection
83
+ adapter ||= self.adapter
84
+ timeout ||= self.timeout
85
+ max_retries ||= self.max_retries
86
+ retry_interval ||= self.retry_interval
87
+ backoff_factor ||= self.backoff_factor
88
+ retry_statuses ||= self.retry_statuses
89
+ retry_methods ||= self.retry_methods
90
+ environment ||= self.environment
91
+ version ||= self.version
92
+ access_token ||= self.access_token
93
+
94
+ Configuration.new(connection: connection, adapter: adapter,
95
+ timeout: timeout, max_retries: max_retries,
96
+ retry_interval: retry_interval,
97
+ backoff_factor: backoff_factor,
98
+ retry_statuses: retry_statuses,
99
+ retry_methods: retry_methods, environment: environment,
100
+ version: version, access_token: access_token)
101
+ end
102
+
103
+ def create_http_client
104
+ FaradayClient.new(timeout: timeout, max_retries: max_retries,
105
+ retry_interval: retry_interval,
106
+ backoff_factor: backoff_factor,
107
+ retry_statuses: retry_statuses,
108
+ retry_methods: retry_methods, connection: connection,
109
+ adapter: adapter)
110
+ end
111
+
112
+ # All the environments the SDK can run in.
113
+ ENVIRONMENTS = {
114
+ Environment::PRODUCTION => {
115
+ Server::DEFAULT => 'https://graph.facebook.com/{Version}'
116
+ }
117
+ }.freeze
118
+
119
+ # Generates the appropriate base URI for the environment and the server.
120
+ # @param [Configuration::Server] The server enum for which the base URI is
121
+ # required.
122
+ # @return [String] The base URI.
123
+ def get_base_uri(server = Server::DEFAULT)
124
+ parameters = {
125
+ 'Version' => { 'value' => version, 'encode' => false }
126
+ }
127
+ APIHelper.append_url_with_template_parameters(
128
+ ENVIRONMENTS[environment][server], parameters
129
+ )
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,52 @@
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
+ # BaseController.
8
+ class BaseController
9
+ attr_accessor :config, :http_call_back
10
+
11
+ def initialize(config, http_call_back: nil)
12
+ @config = config
13
+ @http_call_back = http_call_back
14
+
15
+ @global_headers = {
16
+ 'user-agent' => get_user_agent
17
+ }
18
+ end
19
+
20
+ def validate_parameters(args)
21
+ args.each do |_name, value|
22
+ raise ArgumentError, "Required parameter #{_name} cannot be nil." if value.nil?
23
+ end
24
+ end
25
+
26
+ def execute_request(request, binary: false)
27
+ @http_call_back&.on_before_request(request)
28
+
29
+ APIHelper.clean_hash(request.headers)
30
+ request.headers.merge!(@global_headers)
31
+
32
+ response = if binary
33
+ config.http_client.execute_as_binary(request)
34
+ else
35
+ config.http_client.execute_as_string(request)
36
+ end
37
+ @http_call_back&.on_after_response(response)
38
+
39
+ response
40
+ end
41
+
42
+ def validate_response(response)
43
+ raise APIException.new 'HTTP Response Not OK', response unless
44
+ response.status_code.between?(200, 208) # [200,208] = HTTP OK
45
+ end
46
+
47
+ def get_user_agent
48
+ user_agent = 'APIMATIC 3.0'
49
+ user_agent
50
+ end
51
+ end
52
+ end