whatsapp-ruby-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -0,0 +1,97 @@
1
+ # whats_app_cloud_api
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ require 'faraday/http_cache'
7
+ require 'faraday/retry'
8
+ require 'faraday/multipart'
9
+ require 'faraday/follow_redirects'
10
+ require 'faraday/gzip'
11
+
12
+ module WhatsAppCloudApi
13
+ # An implementation of HttpClient.
14
+ class FaradayClient < HttpClient
15
+ # The attribute readers for properties.
16
+ attr_reader :connection
17
+
18
+ # The constructor.
19
+ def initialize(timeout:, max_retries:, retry_interval:,
20
+ backoff_factor:, retry_statuses:, retry_methods:,
21
+ connection:, adapter:, cache: false, verify: true)
22
+ @connection = if connection.nil?
23
+ create_connection(timeout: timeout, max_retries: max_retries,
24
+ retry_interval: retry_interval, backoff_factor: backoff_factor,
25
+ retry_statuses: retry_statuses, retry_methods: retry_methods,
26
+ adapter: adapter, cache: cache, verify: verify)
27
+ else
28
+ connection
29
+ end
30
+ end
31
+
32
+ # Method to initialize connection.
33
+ def create_connection(timeout:, max_retries:, retry_interval:,
34
+ backoff_factor:, retry_statuses:, retry_methods:,
35
+ adapter:, cache: false, verify: true)
36
+ Faraday.new do |faraday|
37
+ faraday.use Faraday::HttpCache, serializer: Marshal if cache
38
+ faraday.use Faraday::FollowRedirects::Middleware
39
+ faraday.request :gzip
40
+ faraday.request :multipart
41
+ faraday.request :url_encoded
42
+ faraday.ssl[:ca_file] = Certifi.where
43
+ faraday.ssl[:verify] = verify
44
+ faraday.request :retry, max: max_retries, interval: retry_interval,
45
+ backoff_factor: backoff_factor,
46
+ retry_statuses: retry_statuses,
47
+ methods: retry_methods,
48
+ retry_if: proc { |env, _exc|
49
+ env.request.context['forced_retry'] ||= false
50
+ }
51
+ faraday.adapter adapter
52
+ faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
53
+ faraday.options[:timeout] = timeout if timeout.positive?
54
+ end
55
+ end
56
+
57
+ # Method overridden from HttpClient.
58
+ def execute_as_string(http_request)
59
+ response = @connection.send(
60
+ http_request.http_method.downcase,
61
+ http_request.query_url
62
+ ) do |request|
63
+ request.headers = http_request.headers.map { |k, v| [k.to_s, v.to_s] }
64
+ request.options.context ||= {}
65
+ request.options.context.merge!(http_request.context)
66
+ unless http_request.http_method == HttpMethodEnum::GET &&
67
+ http_request.parameters.empty?
68
+ request.body = http_request.parameters
69
+ end
70
+ end
71
+ convert_response(response, http_request)
72
+ end
73
+
74
+ # Method overridden from HttpClient.
75
+ def execute_as_binary(http_request)
76
+ response = @connection.send(
77
+ http_request.http_method.downcase,
78
+ http_request.query_url
79
+ ) do |request|
80
+ request.headers = http_request.headers
81
+ request.options.context ||= {}
82
+ request.options.context.merge!(http_request.context)
83
+ unless http_request.http_method == HttpMethodEnum::GET &&
84
+ http_request.parameters.empty?
85
+ request.body = http_request.parameters
86
+ end
87
+ end
88
+ convert_response(response, http_request)
89
+ end
90
+
91
+ # Method overridden from HttpClient.
92
+ def convert_response(response, http_request)
93
+ HttpResponse.new(response.status, response.reason_phrase,
94
+ response.headers, response.body, http_request)
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,24 @@
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
+ # HttpCallBack allows defining callables for pre and post API calls.
8
+ class HttpCallBack
9
+ # A controller will call this method before making an HTTP Request.
10
+ # @param [HttpRequest] The HttpRequest object which the HttpClient
11
+ # will execute.
12
+ def on_before_request(_http_request)
13
+ raise NotImplementedError, 'This method needs
14
+ to be implemented in a child class.'
15
+ end
16
+
17
+ # A controller will call this method after making an HTTP Request.
18
+ # @param [HttpResponse] The HttpReponse of the API call.
19
+ def on_after_response(_http_response)
20
+ raise NotImplementedError, 'This method needs
21
+ to be implemented in a child class.'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,123 @@
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 interface for the methods that an HTTP Client must implement.
8
+ #
9
+ # This class should not be instantiated but should be used as a base class
10
+ # for HTTP Client classes.
11
+ class HttpClient
12
+ # Execute an HttpRequest when the response is expected to be a string.
13
+ # @param [HttpRequest] The HttpRequest to be executed.
14
+ def execute_as_string(_http_request)
15
+ raise NotImplementedError, 'This method needs
16
+ to be implemented in a child class.'
17
+ end
18
+
19
+ # Execute an HttpRequest when the response is expected to be binary.
20
+ # @param [HttpRequest] The HttpRequest to be executed.
21
+ def execute_as_binary(_http_request)
22
+ raise NotImplementedError, 'This method needs
23
+ to be implemented in a child class.'
24
+ end
25
+
26
+ # Converts the HTTP Response from the client to an HttpResponse object.
27
+ # @param [Dynamic] The response object received from the client.
28
+ def convert_response(_response)
29
+ raise NotImplementedError, 'This method needs
30
+ to be implemented in a child class.'
31
+ end
32
+
33
+ # Get a GET HttpRequest object.
34
+ # @param [String] The URL to send the request to.
35
+ # @param [Hash, Optional] The headers for the HTTP Request.
36
+ # @param [Hash, Optional] The context for the HTTP Request.
37
+ def get(query_url,
38
+ headers: {},
39
+ context: {})
40
+ HttpRequest.new(HttpMethodEnum::GET,
41
+ query_url,
42
+ headers: headers,
43
+ context: context)
44
+ end
45
+
46
+ # Get a HEAD HttpRequest object.
47
+ # @param [String] The URL to send the request to.
48
+ # @param [Hash, Optional] The headers for the HTTP Request.
49
+ # @param [Hash, Optional] The context for the HTTP Request.
50
+ def head(query_url,
51
+ headers: {},
52
+ context: {})
53
+ HttpRequest.new(HttpMethodEnum::HEAD,
54
+ query_url,
55
+ headers: headers,
56
+ context: context)
57
+ end
58
+
59
+ # Get a POST HttpRequest object.
60
+ # @param [String] The URL to send the request to.
61
+ # @param [Hash, Optional] The headers for the HTTP Request.
62
+ # @param [Hash, Optional] The parameters for the HTTP Request.
63
+ # @param [Hash, Optional] The context for the HTTP Request.
64
+ def post(query_url,
65
+ headers: {},
66
+ parameters: {},
67
+ context: {})
68
+ HttpRequest.new(HttpMethodEnum::POST,
69
+ query_url,
70
+ headers: headers,
71
+ parameters: parameters,
72
+ context: context)
73
+ end
74
+
75
+ # Get a PUT HttpRequest object.
76
+ # @param [String] The URL to send the request to.
77
+ # @param [Hash, Optional] The headers for the HTTP Request.
78
+ # @param [Hash, Optional] The parameters for the HTTP Request.
79
+ # @param [Hash, Optional] The context for the HTTP Request.
80
+ def put(query_url,
81
+ headers: {},
82
+ parameters: {},
83
+ context: {})
84
+ HttpRequest.new(HttpMethodEnum::PUT,
85
+ query_url,
86
+ headers: headers,
87
+ parameters: parameters,
88
+ context: context)
89
+ end
90
+
91
+ # Get a PATCH HttpRequest object.
92
+ # @param [String] The URL to send the request to.
93
+ # @param [Hash, Optional] The headers for the HTTP Request.
94
+ # @param [Hash, Optional] The parameters for the HTTP Request.
95
+ # @param [Hash, Optional] The context for the HTTP Request.
96
+ def patch(query_url,
97
+ headers: {},
98
+ parameters: {},
99
+ context: {})
100
+ HttpRequest.new(HttpMethodEnum::PATCH,
101
+ query_url,
102
+ headers: headers,
103
+ parameters: parameters,
104
+ context: context)
105
+ end
106
+
107
+ # Get a DELETE HttpRequest object.
108
+ # @param [String] The URL to send the request to.
109
+ # @param [Hash, Optional] The headers for the HTTP Request.
110
+ # @param [Hash, Optional] The parameters for the HTTP Request.
111
+ # @param [Hash, Optional] The context for the HTTP Request.
112
+ def delete(query_url,
113
+ headers: {},
114
+ parameters: {},
115
+ context: {})
116
+ HttpRequest.new(HttpMethodEnum::DELETE,
117
+ query_url,
118
+ headers: headers,
119
+ parameters: parameters,
120
+ context: context)
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,13 @@
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
+ # HTTP Methods Enumeration.
8
+ class HttpMethodEnum
9
+ HTTPMETHODENUM = [GET = 'GET'.freeze, POST = 'POST'.freeze,
10
+ PUT = 'PUT'.freeze, PATCH = 'PATCH'.freeze,
11
+ DELETE = 'DELETE'.freeze, HEAD = 'HEAD'.freeze].freeze
12
+ end
13
+ end
@@ -0,0 +1,54 @@
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
+ # Represents a single Http Request.
8
+ class HttpRequest
9
+ attr_accessor :http_method, :query_url, :headers,
10
+ :parameters, :username, :password,
11
+ :context
12
+
13
+ # The constructor.
14
+ # @param [HttpMethodEnum] The HTTP method.
15
+ # @param [String] The URL to send the request to.
16
+ # @param [Hash, Optional] The headers for the HTTP Request.
17
+ # @param [Hash, Optional] The parameters for the HTTP Request.
18
+ # @param [Hash, Optional] The context for the HTTP Request.
19
+ def initialize(http_method,
20
+ query_url,
21
+ headers: {},
22
+ parameters: {},
23
+ context: {})
24
+ @http_method = http_method
25
+ @query_url = query_url
26
+ @headers = headers
27
+ @parameters = parameters
28
+ @context = context
29
+ end
30
+
31
+ # Add a header to the HttpRequest.
32
+ # @param [String] The name of the header.
33
+ # @param [String] The value of the header.
34
+ def add_header(name, value)
35
+ @headers[name] = value
36
+ end
37
+
38
+ # Add a parameter to the HttpRequest.
39
+ # @param [String] The name of the parameter.
40
+ # @param [String] The value of the parameter.
41
+ def add_parameter(name, value)
42
+ @parameters[name] = value
43
+ end
44
+
45
+ # Add a query parameter to the HttpRequest.
46
+ # @param [String] The name of the query parameter.
47
+ # @param [String] The value of the query parameter.
48
+ def add_query_parameter(name, value)
49
+ @query_url = APIHelper.append_url_with_query_parameters(@query_url,
50
+ name => value)
51
+ @query_url = APIHelper.clean_url(@query_url)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,29 @@
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
+ # Http response received.
8
+ class HttpResponse
9
+ attr_reader :status_code, :reason_phrase, :headers, :raw_body, :request
10
+
11
+ # The constructor
12
+ # @param [Integer] The status code returned by the server.
13
+ # @param [String] The reason phrase returned by the server.
14
+ # @param [Hash] The headers sent by the server in the response.
15
+ # @param [String] The raw body of the response.
16
+ # @param [HttpRequest] The request that resulted in this response.
17
+ def initialize(status_code,
18
+ reason_phrase,
19
+ headers,
20
+ raw_body,
21
+ request)
22
+ @status_code = status_code
23
+ @reason_phrase = reason_phrase
24
+ @headers = headers
25
+ @raw_body = raw_body
26
+ @request = request
27
+ end
28
+ end
29
+ 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
+ # Action Model.
8
+ class Action < BaseModel
9
+ SKIP = Object.new
10
+ private_constant :SKIP
11
+
12
+ # Required for List Messages. Button content. It cannot be an empty string
13
+ # and must be unique within the message. Emojis are supported, markdown is
14
+ # not.
15
+ # @return [String]
16
+ attr_accessor :button
17
+
18
+ # Required for Reply Buttons. You can have up to 3 buttons. You cannot have
19
+ # leading or trailing spaces when setting the ID.
20
+ # @return [List of Button]
21
+ attr_accessor :buttons
22
+
23
+ # Required for List Messages.
24
+ # @return [List of Section]
25
+ attr_accessor :sections
26
+
27
+ # A mapping from model property names to API property names.
28
+ def self.names
29
+ @_hash = {} if @_hash.nil?
30
+ @_hash['button'] = 'button'
31
+ @_hash['buttons'] = 'buttons'
32
+ @_hash['sections'] = 'sections'
33
+ @_hash
34
+ end
35
+
36
+ # An array for optional fields
37
+ def optionals
38
+ %w[
39
+ button
40
+ buttons
41
+ sections
42
+ ]
43
+ end
44
+
45
+ # An array for nullable fields
46
+ def nullables
47
+ []
48
+ end
49
+
50
+ def initialize(button = nil,
51
+ buttons = nil,
52
+ sections = nil)
53
+ @button = button unless button == SKIP
54
+ @buttons = buttons unless buttons == SKIP
55
+ @sections = sections unless sections == SKIP
56
+ end
57
+
58
+ # Creates an instance of the object from a hash.
59
+ def self.from_hash(hash)
60
+ return nil unless hash
61
+
62
+ # Extract variables from the hash.
63
+ button = hash.key?('button') ? hash['button'] : SKIP
64
+ # Parameter is an array, so we need to iterate through it
65
+ buttons = nil
66
+ unless hash['buttons'].nil?
67
+ buttons = []
68
+ hash['buttons'].each do |structure|
69
+ buttons << (Button.from_hash(structure) if structure)
70
+ end
71
+ end
72
+
73
+ buttons = SKIP unless hash.key?('buttons')
74
+ # Parameter is an array, so we need to iterate through it
75
+ sections = nil
76
+ unless hash['sections'].nil?
77
+ sections = []
78
+ hash['sections'].each do |structure|
79
+ sections << (Section.from_hash(structure) if structure)
80
+ end
81
+ end
82
+
83
+ sections = SKIP unless hash.key?('sections')
84
+
85
+ # Create object from extracted values.
86
+ Action.new(button,
87
+ buttons,
88
+ sections)
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,110 @@
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
+ # Address Model.
8
+ class Address < BaseModel
9
+ SKIP = Object.new
10
+ private_constant :SKIP
11
+
12
+ # Street number and name
13
+ # @return [String]
14
+ attr_accessor :street
15
+
16
+ # City name.
17
+ # @return [String]
18
+ attr_accessor :city
19
+
20
+ # State abbreviation.
21
+ # @return [String]
22
+ attr_accessor :state
23
+
24
+ # ZIP code.
25
+ # @return [String]
26
+ attr_accessor :zip
27
+
28
+ # Full country name.
29
+ # @return [String]
30
+ attr_accessor :country
31
+
32
+ # Two-letter country abbreviation.
33
+ # @return [String]
34
+ attr_accessor :country_code
35
+
36
+ # Two-letter country abbreviation.
37
+ # @return [PersonalInformationTypeEnum]
38
+ attr_accessor :type
39
+
40
+ # A mapping from model property names to API property names.
41
+ def self.names
42
+ @_hash = {} if @_hash.nil?
43
+ @_hash['street'] = 'street'
44
+ @_hash['city'] = 'city'
45
+ @_hash['state'] = 'state'
46
+ @_hash['zip'] = 'zip'
47
+ @_hash['country'] = 'country'
48
+ @_hash['country_code'] = 'country_code'
49
+ @_hash['type'] = 'type'
50
+ @_hash
51
+ end
52
+
53
+ # An array for optional fields
54
+ def optionals
55
+ %w[
56
+ street
57
+ city
58
+ state
59
+ zip
60
+ country
61
+ country_code
62
+ type
63
+ ]
64
+ end
65
+
66
+ # An array for nullable fields
67
+ def nullables
68
+ []
69
+ end
70
+
71
+ def initialize(street = nil,
72
+ city = nil,
73
+ state = nil,
74
+ zip = nil,
75
+ country = nil,
76
+ country_code = nil,
77
+ type = nil)
78
+ @street = street unless street == SKIP
79
+ @city = city unless city == SKIP
80
+ @state = state unless state == SKIP
81
+ @zip = zip unless zip == SKIP
82
+ @country = country unless country == SKIP
83
+ @country_code = country_code unless country_code == SKIP
84
+ @type = type unless type == SKIP
85
+ end
86
+
87
+ # Creates an instance of the object from a hash.
88
+ def self.from_hash(hash)
89
+ return nil unless hash
90
+
91
+ # Extract variables from the hash.
92
+ street = hash.key?('street') ? hash['street'] : SKIP
93
+ city = hash.key?('city') ? hash['city'] : SKIP
94
+ state = hash.key?('state') ? hash['state'] : SKIP
95
+ zip = hash.key?('zip') ? hash['zip'] : SKIP
96
+ country = hash.key?('country') ? hash['country'] : SKIP
97
+ country_code = hash.key?('country_code') ? hash['country_code'] : SKIP
98
+ type = hash.key?('type') ? hash['type'] : SKIP
99
+
100
+ # Create object from extracted values.
101
+ Address.new(street,
102
+ city,
103
+ state,
104
+ zip,
105
+ country,
106
+ country_code,
107
+ type)
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,61 @@
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
+ # Audio Model.
8
+ class Audio < BaseModel
9
+ SKIP = Object.new
10
+ private_constant :SKIP
11
+
12
+ # The media object ID. Required when you are not using a link.
13
+ # @return [String]
14
+ attr_accessor :id
15
+
16
+ # The protocol and URL of the media to be sent. Use only with HTTP/HTTPS
17
+ # URLs. Required when you are not using an uploaded media ID.
18
+ # @return [String]
19
+ attr_accessor :link
20
+
21
+ # A mapping from model property names to API property names.
22
+ def self.names
23
+ @_hash = {} if @_hash.nil?
24
+ @_hash['id'] = 'id'
25
+ @_hash['link'] = 'link'
26
+ @_hash
27
+ end
28
+
29
+ # An array for optional fields
30
+ def optionals
31
+ %w[
32
+ id
33
+ link
34
+ ]
35
+ end
36
+
37
+ # An array for nullable fields
38
+ def nullables
39
+ []
40
+ end
41
+
42
+ def initialize(id = nil,
43
+ link = nil)
44
+ @id = id unless id == SKIP
45
+ @link = link unless link == SKIP
46
+ end
47
+
48
+ # Creates an instance of the object from a hash.
49
+ def self.from_hash(hash)
50
+ return nil unless hash
51
+
52
+ # Extract variables from the hash.
53
+ id = hash.key?('id') ? hash['id'] : SKIP
54
+ link = hash.key?('link') ? hash['link'] : SKIP
55
+
56
+ # Create object from extracted values.
57
+ Audio.new(id,
58
+ link)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,58 @@
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
+ # Base model.
8
+ class BaseModel
9
+ # Returns a Hash representation of the current object.
10
+ def to_hash
11
+ hash = {}
12
+ instance_variables.each do |name|
13
+ value = instance_variable_get(name)
14
+ name = name[1..]
15
+ key = self.class.names.key?(name) ? self.class.names[name] : name
16
+
17
+ optional_fields = optionals if respond_to? 'optionals'
18
+ nullable_fields = nullables if respond_to? 'nullables'
19
+ if value.nil?
20
+ next unless nullable_fields.include?(name)
21
+
22
+ if !optional_fields.include?(name) && !nullable_fields.include?(name)
23
+ raise ArgumentError,
24
+ "`#{name}` cannot be nil in `#{self.class}`. Please specify a valid value."
25
+ end
26
+ end
27
+
28
+ hash[key] = nil
29
+ unless value.nil?
30
+ if respond_to?("to_#{name}")
31
+ if (value.instance_of? Array) || (value.instance_of? Hash)
32
+ params = [hash, key]
33
+ hash[key] = send("to_#{name}", *params)
34
+ else
35
+ hash[key] = send("to_#{name}")
36
+ end
37
+ elsif value.instance_of? Array
38
+ hash[key] = value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
39
+ elsif value.instance_of? Hash
40
+ hash[key] = {}
41
+ value.each do |k, v|
42
+ hash[key][k] = v.is_a?(BaseModel) ? v.to_hash : v
43
+ end
44
+ else
45
+ hash[key] = value.is_a?(BaseModel) ? value.to_hash : value
46
+ end
47
+ end
48
+ end
49
+ hash
50
+ end
51
+
52
+ # Returns a JSON representation of the curent object.
53
+ def to_json(options = {})
54
+ hash = to_hash
55
+ hash.to_json(options)
56
+ end
57
+ end
58
+ end