messagemedia_conversations_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.
- checksums.yaml +7 -0
- data/LICENSE +201 -0
- data/README.md +149 -0
- data/lib/message_media_conversations.rb +63 -0
- data/lib/message_media_conversations/api_helper.rb +273 -0
- data/lib/message_media_conversations/configuration.rb +29 -0
- data/lib/message_media_conversations/controllers/app_users_controller.rb +285 -0
- data/lib/message_media_conversations/controllers/base_controller.rb +59 -0
- data/lib/message_media_conversations/controllers/configuration_controller.rb +90 -0
- data/lib/message_media_conversations/controllers/facebook_controller.rb +192 -0
- data/lib/message_media_conversations/exceptions/api_exception.rb +18 -0
- data/lib/message_media_conversations/http/auth/basic_auth.rb +20 -0
- data/lib/message_media_conversations/http/faraday_client.rb +55 -0
- data/lib/message_media_conversations/http/http_call_back.rb +22 -0
- data/lib/message_media_conversations/http/http_client.rb +102 -0
- data/lib/message_media_conversations/http/http_context.rb +18 -0
- data/lib/message_media_conversations/http/http_method_enum.rb +11 -0
- data/lib/message_media_conversations/http/http_request.rb +48 -0
- data/lib/message_media_conversations/http/http_response.rb +21 -0
- data/lib/message_media_conversations/message_media_conversations_client.rb +39 -0
- data/lib/message_media_conversations/models/app_user_dto.rb +51 -0
- data/lib/message_media_conversations/models/app_users_dto.rb +40 -0
- data/lib/message_media_conversations/models/base_message_dto.rb +42 -0
- data/lib/message_media_conversations/models/base_model.rb +34 -0
- data/lib/message_media_conversations/models/configure_account_request.rb +42 -0
- data/lib/message_media_conversations/models/configure_account_response.rb +42 -0
- data/lib/message_media_conversations/models/facebook_authorisation_response.rb +33 -0
- data/lib/message_media_conversations/models/facebook_page_dto.rb +42 -0
- data/lib/message_media_conversations/models/facebook_pages_dto.rb +40 -0
- data/lib/message_media_conversations/models/get_app_user_by_id_response.rb +51 -0
- data/lib/message_media_conversations/models/get_app_user_messages_response.rb +33 -0
- data/lib/message_media_conversations/models/get_app_users_response.rb +33 -0
- data/lib/message_media_conversations/models/get_facebook_authorisation_url_response.rb +33 -0
- data/lib/message_media_conversations/models/get_facebook_pages_response.rb +33 -0
- data/lib/message_media_conversations/models/message_dto.rb +60 -0
- data/lib/message_media_conversations/models/messages_dto.rb +40 -0
- data/lib/message_media_conversations/models/provision_account_request.rb +42 -0
- data/lib/message_media_conversations/models/send_message_response.rb +42 -0
- metadata +169 -0
@@ -0,0 +1,192 @@
|
|
1
|
+
# This file was automatically generated for MessageMedia by APIMATIC v2.0
|
2
|
+
# ( https://apimatic.io ).
|
3
|
+
|
4
|
+
module MessageMediaConversations
|
5
|
+
# FacebookController
|
6
|
+
class FacebookController < BaseController
|
7
|
+
@instance = FacebookController.new
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_accessor :instance
|
11
|
+
end
|
12
|
+
|
13
|
+
def instance
|
14
|
+
self.class.instance
|
15
|
+
end
|
16
|
+
|
17
|
+
# Integrates the Facebook page with the given ID with the configured
|
18
|
+
# account.
|
19
|
+
# @param [String] facebook_page_id Required parameter: facebookPageId
|
20
|
+
# @return String response from the API call
|
21
|
+
def create_integrate_facebook_page(facebook_page_id)
|
22
|
+
begin
|
23
|
+
@logger.info("create_integrate_facebook_page called.")
|
24
|
+
# Prepare query url.
|
25
|
+
@logger.info("Preparing query URL for create_integrate_facebook_page.")
|
26
|
+
_query_builder = Configuration.base_uri.dup
|
27
|
+
_query_builder << '/beta/conversations/facebook/pages/{facebookPageId}/integrate'
|
28
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
29
|
+
_query_builder,
|
30
|
+
'facebookPageId' => facebook_page_id
|
31
|
+
)
|
32
|
+
_query_url = APIHelper.clean_url _query_builder
|
33
|
+
|
34
|
+
# Prepare and execute HttpRequest.
|
35
|
+
@logger.info('Preparing and executing HttpRequest for create_integrate_facebook_page.')
|
36
|
+
_request = @http_client.post(
|
37
|
+
_query_url
|
38
|
+
)
|
39
|
+
BasicAuth.apply(_request)
|
40
|
+
_context = execute_request(_request, name: 'create_integrate_facebook_page')
|
41
|
+
|
42
|
+
# Validate response against endpoint and global error codes.
|
43
|
+
@logger.info("Validating response for create_integrate_facebook_page.")
|
44
|
+
if _context.response.status_code == 400
|
45
|
+
raise APIException.new(
|
46
|
+
'The account is not provisioned or the Facebook user isn\'t' \
|
47
|
+
' authenticated or the facebookPageId is invalid.',
|
48
|
+
_context
|
49
|
+
)
|
50
|
+
end
|
51
|
+
validate_response(_context)
|
52
|
+
|
53
|
+
# Return appropriate response type.
|
54
|
+
@logger.info("Returning response for create_integrate_facebook_page.")
|
55
|
+
_context.response.raw_body
|
56
|
+
|
57
|
+
rescue Exception => e
|
58
|
+
@logger.error(e)
|
59
|
+
raise e
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Gets a list of Facebook pages belonging to the provisioned and Facebook
|
64
|
+
# authorised account. A successful response from this endpoint will have the
|
65
|
+
# following structure:
|
66
|
+
# ```
|
67
|
+
# {
|
68
|
+
# "data": [
|
69
|
+
# {
|
70
|
+
# "id": "1573307926039629",
|
71
|
+
# "name": "Rainbow Serpent Festival"
|
72
|
+
# },
|
73
|
+
# {
|
74
|
+
# "id": "373479609790958",
|
75
|
+
# "name": "Fans of Doing Live Demos"
|
76
|
+
# }
|
77
|
+
# ]
|
78
|
+
# }
|
79
|
+
# ```
|
80
|
+
# @return GetFacebookPagesResponse response from the API call
|
81
|
+
def get_facebook_pages
|
82
|
+
begin
|
83
|
+
@logger.info("get_facebook_pages called.")
|
84
|
+
# Prepare query url.
|
85
|
+
@logger.info("Preparing query URL for get_facebook_pages.")
|
86
|
+
_query_builder = Configuration.base_uri.dup
|
87
|
+
_query_builder << '/beta/conversations/facebook/pages'
|
88
|
+
_query_url = APIHelper.clean_url _query_builder
|
89
|
+
|
90
|
+
# Prepare headers.
|
91
|
+
@logger.info("Preparing headers for get_facebook_pages.")
|
92
|
+
_headers = {
|
93
|
+
'accept' => 'application/json'
|
94
|
+
}
|
95
|
+
|
96
|
+
# Prepare and execute HttpRequest.
|
97
|
+
@logger.info('Preparing and executing HttpRequest for get_facebook_pages.')
|
98
|
+
_request = @http_client.get(
|
99
|
+
_query_url,
|
100
|
+
headers: _headers
|
101
|
+
)
|
102
|
+
BasicAuth.apply(_request)
|
103
|
+
_context = execute_request(_request, name: 'get_facebook_pages')
|
104
|
+
|
105
|
+
# Validate response against endpoint and global error codes.
|
106
|
+
@logger.info("Validating response for get_facebook_pages.")
|
107
|
+
if _context.response.status_code == 400
|
108
|
+
raise APIException.new(
|
109
|
+
'The account is not provisioned or the Facebook user isn\'t' \
|
110
|
+
' authenticated.',
|
111
|
+
_context
|
112
|
+
)
|
113
|
+
end
|
114
|
+
validate_response(_context)
|
115
|
+
|
116
|
+
# Return appropriate response type.
|
117
|
+
@logger.info("Returning response for get_facebook_pages.")
|
118
|
+
decoded = APIHelper.json_deserialize(_context.response.raw_body)
|
119
|
+
GetFacebookPagesResponse.from_hash(decoded)
|
120
|
+
|
121
|
+
rescue Exception => e
|
122
|
+
@logger.error(e)
|
123
|
+
raise e
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Before you can start integrating Facebook pages on your Facebook account,
|
128
|
+
# MessageMedia's messaging platform needs access to that page via what
|
129
|
+
# Facebook call a page access token. To get the page access token you first
|
130
|
+
# need to provide MessageMedia limited access to your Facebook account.
|
131
|
+
# Calling this endpoint will get the Facebook authorisation URL which you
|
132
|
+
# are required to go through before you can call the integration endpoints.
|
133
|
+
# A successful response from this endpoint will have the following
|
134
|
+
# structure:
|
135
|
+
# ```
|
136
|
+
# {
|
137
|
+
# "authorisation_url":
|
138
|
+
# "https://www.facebook.com/v2.12/dialog/oauth?client_id={facebookAppId}&
|
139
|
+
# ;redirect_uri={apiUrl}/beta/integration/authenticated&state={provision
|
140
|
+
# edAccountUUID}&response_type=token&scope=email,manage_pages,pages_
|
141
|
+
# messaging"
|
142
|
+
# }
|
143
|
+
# ```
|
144
|
+
# *Note: Granting MessageMedia access will only see allow us to see your
|
145
|
+
# basic details and the list of pages you have*
|
146
|
+
# @return GetFacebookAuthorisationURLResponse response from the API call
|
147
|
+
def get_facebook_authorisation_url
|
148
|
+
begin
|
149
|
+
@logger.info("get_facebook_authorisation_url called.")
|
150
|
+
# Prepare query url.
|
151
|
+
@logger.info("Preparing query URL for get_facebook_authorisation_url.")
|
152
|
+
_query_builder = Configuration.base_uri.dup
|
153
|
+
_query_builder << '/beta/conversations/facebook/authorise'
|
154
|
+
_query_url = APIHelper.clean_url _query_builder
|
155
|
+
|
156
|
+
# Prepare headers.
|
157
|
+
@logger.info("Preparing headers for get_facebook_authorisation_url.")
|
158
|
+
_headers = {
|
159
|
+
'accept' => 'application/json'
|
160
|
+
}
|
161
|
+
|
162
|
+
# Prepare and execute HttpRequest.
|
163
|
+
@logger.info('Preparing and executing HttpRequest for get_facebook_authorisation_url.')
|
164
|
+
_request = @http_client.get(
|
165
|
+
_query_url,
|
166
|
+
headers: _headers
|
167
|
+
)
|
168
|
+
BasicAuth.apply(_request)
|
169
|
+
_context = execute_request(_request, name: 'get_facebook_authorisation_url')
|
170
|
+
|
171
|
+
# Validate response against endpoint and global error codes.
|
172
|
+
@logger.info("Validating response for get_facebook_authorisation_url.")
|
173
|
+
if _context.response.status_code == 400
|
174
|
+
raise APIException.new(
|
175
|
+
'The account is not provisioned',
|
176
|
+
_context
|
177
|
+
)
|
178
|
+
end
|
179
|
+
validate_response(_context)
|
180
|
+
|
181
|
+
# Return appropriate response type.
|
182
|
+
@logger.info("Returning response for get_facebook_authorisation_url.")
|
183
|
+
decoded = APIHelper.json_deserialize(_context.response.raw_body)
|
184
|
+
GetFacebookAuthorisationURLResponse.from_hash(decoded)
|
185
|
+
|
186
|
+
rescue Exception => e
|
187
|
+
@logger.error(e)
|
188
|
+
raise e
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# This file was automatically generated for MessageMedia by APIMATIC v2.0
|
2
|
+
# ( https://apimatic.io ).
|
3
|
+
|
4
|
+
module MessageMediaConversations
|
5
|
+
# Class for exceptions when there is a network error, status code error, etc.
|
6
|
+
class APIException < StandardError
|
7
|
+
attr_reader :context, :response_code
|
8
|
+
|
9
|
+
# The constructor.
|
10
|
+
# @param [String] The reason for raising an exception.
|
11
|
+
# @param [HttpContext] The HttpContext of the API call.
|
12
|
+
def initialize(reason, context)
|
13
|
+
super(reason)
|
14
|
+
@context = context
|
15
|
+
@response_code = context.response.status_code
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file was automatically generated for MessageMedia by APIMATIC v2.0
|
2
|
+
# ( https://apimatic.io ).
|
3
|
+
|
4
|
+
require 'base64'
|
5
|
+
|
6
|
+
module MessageMediaConversations
|
7
|
+
# Utility class for basic authorization.
|
8
|
+
class BasicAuth
|
9
|
+
# Add basic authentication to the request.
|
10
|
+
# @param [HttpRequest] The HttpRequest object to which authentication will
|
11
|
+
# be added.
|
12
|
+
def self.apply(http_request)
|
13
|
+
username = Configuration.basic_auth_user_name
|
14
|
+
password = Configuration.basic_auth_password
|
15
|
+
value = Base64.strict_encode64("#{username}:#{password}")
|
16
|
+
header_value = "Basic #{value}"
|
17
|
+
http_request.headers['Authorization'] = header_value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# This file was automatically generated for MessageMedia by APIMATIC v2.0
|
2
|
+
# ( https://apimatic.io ).
|
3
|
+
require 'faraday/http_cache'
|
4
|
+
|
5
|
+
module MessageMediaConversations
|
6
|
+
# An implementation of HttpClient.
|
7
|
+
class FaradayClient < HttpClient
|
8
|
+
# The constructor.
|
9
|
+
def initialize(timeout: nil, cache: false,
|
10
|
+
max_retries: nil, retry_interval: nil)
|
11
|
+
@connection = Faraday.new do |faraday|
|
12
|
+
faraday.use Faraday::HttpCache, serializer: Marshal if cache
|
13
|
+
faraday.request :multipart
|
14
|
+
faraday.request :url_encoded
|
15
|
+
faraday.ssl[:ca_file] = Certifi.where
|
16
|
+
faraday.adapter Faraday.default_adapter
|
17
|
+
faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
|
18
|
+
faraday.options[:open_timeout] = timeout if timeout
|
19
|
+
faraday.request :retry, max: max_retries, interval: if max_retries &&
|
20
|
+
retry_interval
|
21
|
+
retry_interval
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Method overridden from HttpClient.
|
27
|
+
def execute_as_string(http_request)
|
28
|
+
response = @connection.send(
|
29
|
+
http_request.http_method.downcase,
|
30
|
+
http_request.query_url
|
31
|
+
) do |request|
|
32
|
+
request.headers = http_request.headers
|
33
|
+
request.body = http_request.parameters
|
34
|
+
end
|
35
|
+
convert_response(response)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Method overridden from HttpClient.
|
39
|
+
def execute_as_binary(http_request)
|
40
|
+
response = @connection.send(
|
41
|
+
http_request.http_method.downcase,
|
42
|
+
http_request.query_url
|
43
|
+
) do |request|
|
44
|
+
request.headers = http_request.headers
|
45
|
+
request.body = http_request.parameters
|
46
|
+
end
|
47
|
+
convert_response(response)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Method overridden from HttpClient.
|
51
|
+
def convert_response(response)
|
52
|
+
HttpResponse.new(response.status, response.headers, response.body)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# This file was automatically generated for MessageMedia by APIMATIC v2.0
|
2
|
+
# ( https://apimatic.io ).
|
3
|
+
|
4
|
+
module MessageMediaConversations
|
5
|
+
# HttpCallBack allows defining callables for pre and post API calls.
|
6
|
+
class HttpCallBack
|
7
|
+
# A controller will call this method before making an HTTP Request.
|
8
|
+
# @param [HttpRequest] The HttpRequest object which the HttpClient
|
9
|
+
# will execute.
|
10
|
+
def on_before_request(_http_request)
|
11
|
+
raise NotImplementedError, 'This method needs
|
12
|
+
to be implemented in a child class.'
|
13
|
+
end
|
14
|
+
|
15
|
+
# A controller will call this method after making an HTTP Request.
|
16
|
+
# @param [HttpContext] The HttpContext of the API call.
|
17
|
+
def on_after_response(_http_context)
|
18
|
+
raise NotImplementedError, 'This method needs
|
19
|
+
to be implemented in a child class.'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# This file was automatically generated for MessageMedia by APIMATIC v2.0
|
2
|
+
# ( https://apimatic.io ).
|
3
|
+
|
4
|
+
module MessageMediaConversations
|
5
|
+
# An interface for the methods that an HTTP Client must implement.
|
6
|
+
#
|
7
|
+
# This class should not be instantiated but should be used as a base class
|
8
|
+
# for HTTP Client classes.
|
9
|
+
class HttpClient
|
10
|
+
# Execute an HttpRequest when the response is expected to be a string.
|
11
|
+
# @param [HttpRequest] The HttpRequest to be executed.
|
12
|
+
def execute_as_string(_http_request)
|
13
|
+
raise NotImplementedError, 'This method needs
|
14
|
+
to be implemented in a child class.'
|
15
|
+
end
|
16
|
+
|
17
|
+
# Execute an HttpRequest when the response is expected to be binary.
|
18
|
+
# @param [HttpRequest] The HttpRequest to be executed.
|
19
|
+
def execute_as_binary(_http_request)
|
20
|
+
raise NotImplementedError, 'This method needs
|
21
|
+
to be implemented in a child class.'
|
22
|
+
end
|
23
|
+
|
24
|
+
# Converts the HTTP Response from the client to an HttpResponse object.
|
25
|
+
# @param [Dynamic] The response object received from the client.
|
26
|
+
def convert_response(_response)
|
27
|
+
raise NotImplementedError, 'This method needs
|
28
|
+
to be implemented in a child class.'
|
29
|
+
end
|
30
|
+
|
31
|
+
# Get a GET HttpRequest object.
|
32
|
+
# @param [String] The URL to send the request to.
|
33
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
34
|
+
def get(query_url,
|
35
|
+
headers: {})
|
36
|
+
HttpRequest.new(HttpMethodEnum::GET,
|
37
|
+
query_url,
|
38
|
+
headers: headers)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Get a HEAD HttpRequest object.
|
42
|
+
# @param [String] The URL to send the request to.
|
43
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
44
|
+
def head(query_url,
|
45
|
+
headers: {})
|
46
|
+
HttpRequest.new(HttpMethodEnum::HEAD,
|
47
|
+
query_url,
|
48
|
+
headers: headers)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Get a POST HttpRequest object.
|
52
|
+
# @param [String] The URL to send the request to.
|
53
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
54
|
+
# @param [Hash, Optional] The parameters for the HTTP Request.
|
55
|
+
def post(query_url,
|
56
|
+
headers: {},
|
57
|
+
parameters: {})
|
58
|
+
HttpRequest.new(HttpMethodEnum::POST,
|
59
|
+
query_url,
|
60
|
+
headers: headers,
|
61
|
+
parameters: parameters)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Get a PUT HttpRequest object.
|
65
|
+
# @param [String] The URL to send the request to.
|
66
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
67
|
+
# @param [Hash, Optional] The parameters for the HTTP Request.
|
68
|
+
def put(query_url,
|
69
|
+
headers: {},
|
70
|
+
parameters: {})
|
71
|
+
HttpRequest.new(HttpMethodEnum::PUT,
|
72
|
+
query_url,
|
73
|
+
headers: headers,
|
74
|
+
parameters: parameters)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Get a PATCH HttpRequest object.
|
78
|
+
# @param [String] The URL to send the request to.
|
79
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
80
|
+
# @param [Hash, Optional] The parameters for the HTTP Request.
|
81
|
+
def patch(query_url,
|
82
|
+
headers: {},
|
83
|
+
parameters: {})
|
84
|
+
HttpRequest.new(HttpMethodEnum::PATCH,
|
85
|
+
query_url,
|
86
|
+
headers: headers,
|
87
|
+
parameters: parameters)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Get a DELETE HttpRequest object.
|
91
|
+
# @param [String] The URL to send the request to.
|
92
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
93
|
+
def delete(query_url,
|
94
|
+
headers: {},
|
95
|
+
parameters: {})
|
96
|
+
HttpRequest.new(HttpMethodEnum::DELETE,
|
97
|
+
query_url,
|
98
|
+
headers: headers,
|
99
|
+
parameters: parameters)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# This file was automatically generated for MessageMedia by APIMATIC v2.0
|
2
|
+
# ( https://apimatic.io ).
|
3
|
+
|
4
|
+
module MessageMediaConversations
|
5
|
+
# Represents an Http call in context.
|
6
|
+
class HttpContext
|
7
|
+
attr_accessor :request, :response
|
8
|
+
|
9
|
+
# The constructor.
|
10
|
+
# @param [HttpRequest] An HttpRequest object representing the HTTP request.
|
11
|
+
# @param [HttpResponse] An HttpResponse object representing the HTTP
|
12
|
+
# response.
|
13
|
+
def initialize(request, response)
|
14
|
+
@request = request
|
15
|
+
@response = response
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# This file was automatically generated for MessageMedia by APIMATIC v2.0
|
2
|
+
# ( https://apimatic.io ).
|
3
|
+
|
4
|
+
module MessageMediaConversations
|
5
|
+
# HTTP Methods Enumeration.
|
6
|
+
class HttpMethodEnum
|
7
|
+
HTTPMETHODENUM = [GET = 'GET'.freeze, POST = 'POST'.freeze,
|
8
|
+
PUT = 'PUT'.freeze, PATCH = 'PATCH'.freeze,
|
9
|
+
DELETE = 'DELETE'.freeze, HEAD = 'HEAD'.freeze].freeze
|
10
|
+
end
|
11
|
+
end
|