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,29 @@
|
|
1
|
+
# This file was automatically generated for MessageMedia by APIMATIC v2.0
|
2
|
+
# ( https://apimatic.io ).
|
3
|
+
|
4
|
+
module MessageMediaConversations
|
5
|
+
|
6
|
+
Logging.logger.root.appenders = Logging.appenders.stdout
|
7
|
+
Logging.logger.root.level = :info
|
8
|
+
|
9
|
+
# All configuration including auth info and base URI for the API access
|
10
|
+
# are configured in this class.
|
11
|
+
class Configuration
|
12
|
+
# The base Uri for API calls
|
13
|
+
@base_uri = 'https://api.messagemedia.com'
|
14
|
+
|
15
|
+
# The username to use with basic authentication
|
16
|
+
@basic_auth_user_name = 'TODO: Replace'
|
17
|
+
|
18
|
+
# The password to use with basic authentication
|
19
|
+
@basic_auth_password = 'TODO: Replace'
|
20
|
+
|
21
|
+
# The attribute accessors for public properties.
|
22
|
+
class << self
|
23
|
+
attr_accessor :array_serialization
|
24
|
+
attr_accessor :base_uri
|
25
|
+
attr_accessor :basic_auth_user_name
|
26
|
+
attr_accessor :basic_auth_password
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,285 @@
|
|
1
|
+
# This file was automatically generated for MessageMedia by APIMATIC v2.0
|
2
|
+
# ( https://apimatic.io ).
|
3
|
+
|
4
|
+
module MessageMediaConversations
|
5
|
+
# AppUsersController
|
6
|
+
class AppUsersController < BaseController
|
7
|
+
@instance = AppUsersController.new
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_accessor :instance
|
11
|
+
end
|
12
|
+
|
13
|
+
def instance
|
14
|
+
self.class.instance
|
15
|
+
end
|
16
|
+
|
17
|
+
# Sends a message to the App User with the given ID.
|
18
|
+
# You can use this endpoint in conjuction with the app users or app user by
|
19
|
+
# id endpoint where the response from one of the latter endpoints would
|
20
|
+
# display the user id and this can be used with this endpoint to send a
|
21
|
+
# message to that user. A successful response from this endpoint will have
|
22
|
+
# the following structure:
|
23
|
+
# ```
|
24
|
+
# {
|
25
|
+
# "channel": "facebook",
|
26
|
+
# "text": "Thank you for your query we'll be in touch with an answer
|
27
|
+
# shortly."
|
28
|
+
# }
|
29
|
+
# ```
|
30
|
+
# @param [String] app_user_id Required parameter: appUserId
|
31
|
+
# @param [BaseMessageDto] body Required parameter: Example:
|
32
|
+
# @return SendMessageResponse response from the API call
|
33
|
+
def create_send_message(app_user_id,
|
34
|
+
body)
|
35
|
+
begin
|
36
|
+
@logger.info("create_send_message called.")
|
37
|
+
# Prepare query url.
|
38
|
+
@logger.info("Preparing query URL for create_send_message.")
|
39
|
+
_query_builder = Configuration.base_uri.dup
|
40
|
+
_query_builder << '/beta/conversations/users/{appUserId}/messages'
|
41
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
42
|
+
_query_builder,
|
43
|
+
'appUserId' => app_user_id
|
44
|
+
)
|
45
|
+
_query_url = APIHelper.clean_url _query_builder
|
46
|
+
|
47
|
+
# Prepare headers.
|
48
|
+
@logger.info("Preparing headers for create_send_message.")
|
49
|
+
_headers = {
|
50
|
+
'accept' => 'application/json',
|
51
|
+
'content-type' => 'application/json; charset=utf-8'
|
52
|
+
}
|
53
|
+
|
54
|
+
# Prepare and execute HttpRequest.
|
55
|
+
@logger.info('Preparing and executing HttpRequest for create_send_message.')
|
56
|
+
_request = @http_client.post(
|
57
|
+
_query_url,
|
58
|
+
headers: _headers,
|
59
|
+
parameters: body.to_json
|
60
|
+
)
|
61
|
+
BasicAuth.apply(_request)
|
62
|
+
_context = execute_request(_request, name: 'create_send_message')
|
63
|
+
|
64
|
+
# Validate response against endpoint and global error codes.
|
65
|
+
@logger.info("Validating response for create_send_message.")
|
66
|
+
if _context.response.status_code == 400
|
67
|
+
raise APIException.new(
|
68
|
+
'The posted request is invalid or the account is not provisioned.',
|
69
|
+
_context
|
70
|
+
)
|
71
|
+
elsif _context.response.status_code == 404
|
72
|
+
raise APIException.new(
|
73
|
+
'The app user does not exist.',
|
74
|
+
_context
|
75
|
+
)
|
76
|
+
end
|
77
|
+
validate_response(_context)
|
78
|
+
|
79
|
+
# Return appropriate response type.
|
80
|
+
@logger.info("Returning response for create_send_message.")
|
81
|
+
decoded = APIHelper.json_deserialize(_context.response.raw_body)
|
82
|
+
SendMessageResponse.from_hash(decoded)
|
83
|
+
|
84
|
+
rescue Exception => e
|
85
|
+
@logger.error(e)
|
86
|
+
raise e
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Gets the list of messages sent to and received by the App User with the
|
91
|
+
# given ID. A successful response from this endpoint will have the following
|
92
|
+
# structure:
|
93
|
+
# ```
|
94
|
+
# {
|
95
|
+
# "messages": {
|
96
|
+
# "data": [
|
97
|
+
# {
|
98
|
+
# "direction": "RECEIVED",
|
99
|
+
# "text": "Hey, I was just wondering how much shipping would be to
|
100
|
+
# Australia for one of them awesome t-shirts?",
|
101
|
+
# "channel": "FACEBOOK",
|
102
|
+
# "timestamp": "2017-12-12T18:18:40.000Z"
|
103
|
+
# },
|
104
|
+
# {
|
105
|
+
# "direction": "SENT",
|
106
|
+
# "text": "Thank you for your query we'll be in touch with an answer
|
107
|
+
# shortly.",
|
108
|
+
# "channel": "FACEBOOK",
|
109
|
+
# "timestamp": "2017-12-08T10:12:16.000Z"
|
110
|
+
# }
|
111
|
+
# ]
|
112
|
+
# },
|
113
|
+
# "metadata" : {
|
114
|
+
# "user_id": "{id}",
|
115
|
+
# "account_id": "FunGuys007"
|
116
|
+
# }
|
117
|
+
# }
|
118
|
+
# ```
|
119
|
+
# @param [String] app_user_id Required parameter: appUserId
|
120
|
+
# @return GetAppUserMessagesResponse response from the API call
|
121
|
+
def get_app_user_messages(app_user_id)
|
122
|
+
begin
|
123
|
+
@logger.info("get_app_user_messages called.")
|
124
|
+
# Prepare query url.
|
125
|
+
@logger.info("Preparing query URL for get_app_user_messages.")
|
126
|
+
_query_builder = Configuration.base_uri.dup
|
127
|
+
_query_builder << '/beta/conversations/users/{appUserId}/messages'
|
128
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
129
|
+
_query_builder,
|
130
|
+
'appUserId' => app_user_id
|
131
|
+
)
|
132
|
+
_query_url = APIHelper.clean_url _query_builder
|
133
|
+
|
134
|
+
# Prepare headers.
|
135
|
+
@logger.info("Preparing headers for get_app_user_messages.")
|
136
|
+
_headers = {
|
137
|
+
'accept' => 'application/json'
|
138
|
+
}
|
139
|
+
|
140
|
+
# Prepare and execute HttpRequest.
|
141
|
+
@logger.info('Preparing and executing HttpRequest for get_app_user_messages.')
|
142
|
+
_request = @http_client.get(
|
143
|
+
_query_url,
|
144
|
+
headers: _headers
|
145
|
+
)
|
146
|
+
BasicAuth.apply(_request)
|
147
|
+
_context = execute_request(_request, name: 'get_app_user_messages')
|
148
|
+
|
149
|
+
# Validate response against endpoint and global error codes.
|
150
|
+
@logger.info("Validating response for get_app_user_messages.")
|
151
|
+
if _context.response.status_code == 404
|
152
|
+
raise APIException.new(
|
153
|
+
'The app user does not exist.',
|
154
|
+
_context
|
155
|
+
)
|
156
|
+
end
|
157
|
+
validate_response(_context)
|
158
|
+
|
159
|
+
# Return appropriate response type.
|
160
|
+
@logger.info("Returning response for get_app_user_messages.")
|
161
|
+
decoded = APIHelper.json_deserialize(_context.response.raw_body)
|
162
|
+
GetAppUserMessagesResponse.from_hash(decoded)
|
163
|
+
|
164
|
+
rescue Exception => e
|
165
|
+
@logger.error(e)
|
166
|
+
raise e
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
# Gets the App User with the given ID. A successful response from this
|
171
|
+
# endpoint will have the following structure:
|
172
|
+
# ```
|
173
|
+
# {
|
174
|
+
# "id": "3898c5e4-73cc-44f9-812f-3698a4c3bb1d",
|
175
|
+
# "surname": "Sims",
|
176
|
+
# "given_name": "Ben"
|
177
|
+
# }
|
178
|
+
# ```
|
179
|
+
# @param [String] app_user_id Required parameter: appUserId
|
180
|
+
# @return GetAppUserByIdResponse response from the API call
|
181
|
+
def get_app_user_by_id(app_user_id)
|
182
|
+
begin
|
183
|
+
@logger.info("get_app_user_by_id called.")
|
184
|
+
# Prepare query url.
|
185
|
+
@logger.info("Preparing query URL for get_app_user_by_id.")
|
186
|
+
_query_builder = Configuration.base_uri.dup
|
187
|
+
_query_builder << '/beta/conversations/users/{appUserId}'
|
188
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
189
|
+
_query_builder,
|
190
|
+
'appUserId' => app_user_id
|
191
|
+
)
|
192
|
+
_query_url = APIHelper.clean_url _query_builder
|
193
|
+
|
194
|
+
# Prepare headers.
|
195
|
+
@logger.info("Preparing headers for get_app_user_by_id.")
|
196
|
+
_headers = {
|
197
|
+
'accept' => 'application/json'
|
198
|
+
}
|
199
|
+
|
200
|
+
# Prepare and execute HttpRequest.
|
201
|
+
@logger.info('Preparing and executing HttpRequest for get_app_user_by_id.')
|
202
|
+
_request = @http_client.get(
|
203
|
+
_query_url,
|
204
|
+
headers: _headers
|
205
|
+
)
|
206
|
+
BasicAuth.apply(_request)
|
207
|
+
_context = execute_request(_request, name: 'get_app_user_by_id')
|
208
|
+
|
209
|
+
# Validate response against endpoint and global error codes.
|
210
|
+
@logger.info("Validating response for get_app_user_by_id.")
|
211
|
+
if _context.response.status_code == 404
|
212
|
+
raise APIException.new(
|
213
|
+
'The app user does not exist.',
|
214
|
+
_context
|
215
|
+
)
|
216
|
+
end
|
217
|
+
validate_response(_context)
|
218
|
+
|
219
|
+
# Return appropriate response type.
|
220
|
+
@logger.info("Returning response for get_app_user_by_id.")
|
221
|
+
decoded = APIHelper.json_deserialize(_context.response.raw_body)
|
222
|
+
GetAppUserByIdResponse.from_hash(decoded)
|
223
|
+
|
224
|
+
rescue Exception => e
|
225
|
+
@logger.error(e)
|
226
|
+
raise e
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
# Gets a list of App Users that belong to the configured account. A
|
231
|
+
# successful response from this endpoint will have the following structure:
|
232
|
+
# ```
|
233
|
+
# {
|
234
|
+
# "data": [
|
235
|
+
# {
|
236
|
+
# "id": "3898c5e4-73cc-44f9-812f-3698a4c3bb1d",
|
237
|
+
# "surname": "Sims",
|
238
|
+
# "given_name": "Ben"
|
239
|
+
# },
|
240
|
+
# {
|
241
|
+
# "id": "331b1da8-10a5-44c7-91df-1dc14cc2f373",
|
242
|
+
# "surname": "Hood",
|
243
|
+
# "given_name": "Robert"
|
244
|
+
# }
|
245
|
+
# ]
|
246
|
+
# }
|
247
|
+
# ```
|
248
|
+
# @return GetAppUsersResponse response from the API call
|
249
|
+
def get_app_users
|
250
|
+
begin
|
251
|
+
@logger.info("get_app_users called.")
|
252
|
+
# Prepare query url.
|
253
|
+
@logger.info("Preparing query URL for get_app_users.")
|
254
|
+
_query_builder = Configuration.base_uri.dup
|
255
|
+
_query_builder << '/beta/conversations/users'
|
256
|
+
_query_url = APIHelper.clean_url _query_builder
|
257
|
+
|
258
|
+
# Prepare headers.
|
259
|
+
@logger.info("Preparing headers for get_app_users.")
|
260
|
+
_headers = {
|
261
|
+
'accept' => 'application/json'
|
262
|
+
}
|
263
|
+
|
264
|
+
# Prepare and execute HttpRequest.
|
265
|
+
@logger.info('Preparing and executing HttpRequest for get_app_users.')
|
266
|
+
_request = @http_client.get(
|
267
|
+
_query_url,
|
268
|
+
headers: _headers
|
269
|
+
)
|
270
|
+
BasicAuth.apply(_request)
|
271
|
+
_context = execute_request(_request, name: 'get_app_users')
|
272
|
+
validate_response(_context)
|
273
|
+
|
274
|
+
# Return appropriate response type.
|
275
|
+
@logger.info("Returning response for get_app_users.")
|
276
|
+
decoded = APIHelper.json_deserialize(_context.response.raw_body)
|
277
|
+
GetAppUsersResponse.from_hash(decoded)
|
278
|
+
|
279
|
+
rescue Exception => e
|
280
|
+
@logger.error(e)
|
281
|
+
raise e
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# This file was automatically generated for MessageMedia by APIMATIC v2.0
|
2
|
+
# ( https://apimatic.io ).
|
3
|
+
|
4
|
+
module MessageMediaConversations
|
5
|
+
# Base controller.
|
6
|
+
class BaseController
|
7
|
+
attr_accessor :http_client, :http_call_back
|
8
|
+
|
9
|
+
def initialize(http_client: nil, http_call_back: nil)
|
10
|
+
@http_client = http_client || FaradayClient.new
|
11
|
+
@http_call_back = http_call_back
|
12
|
+
|
13
|
+
@global_headers = {
|
14
|
+
'user-agent' => 'messagesmedia-conversations'
|
15
|
+
}
|
16
|
+
@logger = Logging.logger[self]
|
17
|
+
@logger.info("Instantiated controller class.")
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate_parameters(args)
|
21
|
+
args.each do |_name, value|
|
22
|
+
if value.nil?
|
23
|
+
raise ArgumentError, "Required parameter #{_name} cannot be nil."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def execute_request(request, binary: false, name: nil)
|
29
|
+
@logger.info("Calling the on_before_request method of http_call_back for #{name}.") if @http_call_back
|
30
|
+
@http_call_back.on_before_request(request) if @http_call_back
|
31
|
+
|
32
|
+
@logger.info("Merging global headers with endpoint headers for #{name}.")
|
33
|
+
APIHelper.clean_hash(request.headers)
|
34
|
+
request.headers = @global_headers.clone.merge(request.headers)
|
35
|
+
|
36
|
+
@logger.debug("Raw request for #{name} is: #{request.inspect}")
|
37
|
+
response = if binary
|
38
|
+
@http_client.execute_as_binary(request)
|
39
|
+
else
|
40
|
+
@http_client.execute_as_string(request)
|
41
|
+
end
|
42
|
+
@logger.debug("Raw response for #{name} is: #{response.inspect}")
|
43
|
+
@logger.info("Wrapping request and response in a context object for #{name}.")
|
44
|
+
context = HttpContext.new(request, response)
|
45
|
+
|
46
|
+
@logger.info("Calling on_after_response method of http_call_back for #{name}.") if @http_call_back
|
47
|
+
@http_call_back.on_after_response(context) if @http_call_back
|
48
|
+
|
49
|
+
context
|
50
|
+
end
|
51
|
+
|
52
|
+
def validate_response(context)
|
53
|
+
raise APIException.new 'The account is not provisioned.', context if
|
54
|
+
context.response.status_code == 400
|
55
|
+
raise APIException.new 'HTTP Response Not OK', context unless
|
56
|
+
context.response.status_code.between?(200, 208) # [200,208] = HTTP OK
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# This file was automatically generated for MessageMedia by APIMATIC v2.0
|
2
|
+
# ( https://apimatic.io ).
|
3
|
+
|
4
|
+
module MessageMediaConversations
|
5
|
+
# ConfigurationController
|
6
|
+
class ConfigurationController < BaseController
|
7
|
+
@instance = ConfigurationController.new
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_accessor :instance
|
11
|
+
end
|
12
|
+
|
13
|
+
def instance
|
14
|
+
self.class.instance
|
15
|
+
end
|
16
|
+
|
17
|
+
# Configures your existing MessageMedia account to use the Conversations API
|
18
|
+
# by giving it a human readable name (for reference later on), and also by
|
19
|
+
# specifying a callback URL which is where any Inbound Messages and/or
|
20
|
+
# Notifications will be pushed to. The request would have the following
|
21
|
+
# structure:
|
22
|
+
# ```
|
23
|
+
# {
|
24
|
+
# "name": "Rainbow Serpent Festival",
|
25
|
+
# "callback_url": "http://accounts-domain.com/callback"
|
26
|
+
# }
|
27
|
+
# ```
|
28
|
+
# * `name` is a required property and is a customer friendly name to
|
29
|
+
# identify your provisioned account
|
30
|
+
# * `callback_url` is an optional property is the callback URL to forward
|
31
|
+
# inbound messages to.
|
32
|
+
# *Note: We are currently NOT using our Webhooks functionality for this
|
33
|
+
# while it's in beta, when we make this production ready we will look at
|
34
|
+
# switching to having these webhooks managed via the Webhooks Management
|
35
|
+
# API*
|
36
|
+
# @param [ConfigureAccountRequest] body Required parameter: Example:
|
37
|
+
# @return ConfigureAccountResponse response from the API call
|
38
|
+
def create_configure_account(body)
|
39
|
+
begin
|
40
|
+
@logger.info("create_configure_account called.")
|
41
|
+
# Prepare query url.
|
42
|
+
@logger.info("Preparing query URL for create_configure_account.")
|
43
|
+
_query_builder = Configuration.base_uri.dup
|
44
|
+
_query_builder << '/beta/conversations/provision'
|
45
|
+
_query_url = APIHelper.clean_url _query_builder
|
46
|
+
|
47
|
+
# Prepare headers.
|
48
|
+
@logger.info("Preparing headers for create_configure_account.")
|
49
|
+
_headers = {
|
50
|
+
'accept' => 'application/json',
|
51
|
+
'content-type' => 'application/json; charset=utf-8'
|
52
|
+
}
|
53
|
+
|
54
|
+
# Prepare and execute HttpRequest.
|
55
|
+
@logger.info('Preparing and executing HttpRequest for create_configure_account.')
|
56
|
+
_request = @http_client.post(
|
57
|
+
_query_url,
|
58
|
+
headers: _headers,
|
59
|
+
parameters: body.to_json
|
60
|
+
)
|
61
|
+
BasicAuth.apply(_request)
|
62
|
+
_context = execute_request(_request, name: 'create_configure_account')
|
63
|
+
|
64
|
+
# Validate response against endpoint and global error codes.
|
65
|
+
@logger.info("Validating response for create_configure_account.")
|
66
|
+
if _context.response.status_code == 400
|
67
|
+
raise APIException.new(
|
68
|
+
'Not a valid request body.',
|
69
|
+
_context
|
70
|
+
)
|
71
|
+
elsif _context.response.status_code == 409
|
72
|
+
raise APIException.new(
|
73
|
+
'The account has already been provisioned.',
|
74
|
+
_context
|
75
|
+
)
|
76
|
+
end
|
77
|
+
validate_response(_context)
|
78
|
+
|
79
|
+
# Return appropriate response type.
|
80
|
+
@logger.info("Returning response for create_configure_account.")
|
81
|
+
decoded = APIHelper.json_deserialize(_context.response.raw_body)
|
82
|
+
ConfigureAccountResponse.from_hash(decoded)
|
83
|
+
|
84
|
+
rescue Exception => e
|
85
|
+
@logger.error(e)
|
86
|
+
raise e
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|