Class: MessageMediaConversations::AppUsersController
- Inherits:
-
BaseController
- Object
- BaseController
- MessageMediaConversations::AppUsersController
- Defined in:
- lib/message_media_conversations/controllers/app_users_controller.rb
Overview
AppUsersController
Class Attribute Summary collapse
-
.instance ⇒ Object
Returns the value of attribute instance.
Attributes inherited from BaseController
Instance Method Summary collapse
-
#create_send_message(app_user_id, body) ⇒ Object
Sends a message to the App User with the given ID.
-
#get_app_user_by_id(app_user_id) ⇒ Object
Gets the App User with the given ID.
-
#get_app_user_messages(app_user_id) ⇒ Object
Gets the list of messages sent to and received by the App User with the given ID.
-
#get_app_users ⇒ Object
Gets a list of App Users that belong to the configured account.
- #instance ⇒ Object
Methods inherited from BaseController
#execute_request, #initialize, #validate_parameters, #validate_response
Constructor Details
This class inherits a constructor from MessageMediaConversations::BaseController
Class Attribute Details
.instance ⇒ Object
Returns the value of attribute instance.
10 11 12 |
# File 'lib/message_media_conversations/controllers/app_users_controller.rb', line 10 def instance @instance end |
Instance Method Details
#create_send_message(app_user_id, body) ⇒ Object
Sends a message to the App User with the given ID. You can use this endpoint in conjuction with the app users or app user by id endpoint where the response from one of the latter endpoints would display the user id and this can be used with this endpoint to send a message to that user. A successful response from this endpoint will have the following structure: “‘ {
"channel": "facebook",
"text": "Thank you for your query we'll be in touch with an answer
shortly.“ } “‘
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/message_media_conversations/controllers/app_users_controller.rb', line 33 def (app_user_id, body) begin @logger.info("create_send_message called.") # Prepare query url. @logger.info("Preparing query URL for create_send_message.") _query_builder = Configuration.base_uri.dup _query_builder << '/beta/conversations/users/{appUserId}/messages' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'appUserId' => app_user_id ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. @logger.info("Preparing headers for create_send_message.") _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8' } # Prepare and execute HttpRequest. @logger.info('Preparing and executing HttpRequest for create_send_message.') _request = @http_client.post( _query_url, headers: _headers, parameters: body.to_json ) BasicAuth.apply(_request) _context = execute_request(_request, name: 'create_send_message') # Validate response against endpoint and global error codes. @logger.info("Validating response for create_send_message.") if _context.response.status_code == 400 raise APIException.new( 'The posted request is invalid or the account is not provisioned.', _context ) elsif _context.response.status_code == 404 raise APIException.new( 'The app user does not exist.', _context ) end validate_response(_context) # Return appropriate response type. @logger.info("Returning response for create_send_message.") decoded = APIHelper.json_deserialize(_context.response.raw_body) SendMessageResponse.from_hash(decoded) rescue Exception => e @logger.error(e) raise e end end |
#get_app_user_by_id(app_user_id) ⇒ Object
Gets the App User with the given ID. A successful response from this endpoint will have the following structure: “‘
"id": "3898c5e4-73cc-44f9-812f-3698a4c3bb1d",
"surname": "Sims",
"given_name": "Ben"
“‘
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/message_media_conversations/controllers/app_users_controller.rb', line 181 def get_app_user_by_id(app_user_id) begin @logger.info("get_app_user_by_id called.") # Prepare query url. @logger.info("Preparing query URL for get_app_user_by_id.") _query_builder = Configuration.base_uri.dup _query_builder << '/beta/conversations/users/{appUserId}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'appUserId' => app_user_id ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. @logger.info("Preparing headers for get_app_user_by_id.") _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. @logger.info('Preparing and executing HttpRequest for get_app_user_by_id.') _request = @http_client.get( _query_url, headers: _headers ) BasicAuth.apply(_request) _context = execute_request(_request, name: 'get_app_user_by_id') # Validate response against endpoint and global error codes. @logger.info("Validating response for get_app_user_by_id.") if _context.response.status_code == 404 raise APIException.new( 'The app user does not exist.', _context ) end validate_response(_context) # Return appropriate response type. @logger.info("Returning response for get_app_user_by_id.") decoded = APIHelper.json_deserialize(_context.response.raw_body) GetAppUserByIdResponse.from_hash(decoded) rescue Exception => e @logger.error(e) raise e end end |
#get_app_user_messages(app_user_id) ⇒ Object
Gets the list of messages sent to and received by the App User with the given ID. A successful response from this endpoint will have the following structure: “‘ {
"messages": {
"data": [
{
"direction": "RECEIVED",
"text": "Hey, I was just wondering how much shipping would be to
Australia for one of them awesome t-shirts?“,
"channel": "FACEBOOK",
"timestamp": "2017-12-12T18:18:40.000Z"
},
{
"direction": "SENT",
"text": "Thank you for your query we'll be in touch with an answer
shortly.“,
"channel": "FACEBOOK",
"timestamp": "2017-12-08T10:12:16.000Z"
}
]
},
"metadata" : {
"user_id": "{id}",
"account_id": "FunGuys007"
}
} “‘
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/message_media_conversations/controllers/app_users_controller.rb', line 121 def (app_user_id) begin @logger.info("get_app_user_messages called.") # Prepare query url. @logger.info("Preparing query URL for get_app_user_messages.") _query_builder = Configuration.base_uri.dup _query_builder << '/beta/conversations/users/{appUserId}/messages' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'appUserId' => app_user_id ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. @logger.info("Preparing headers for get_app_user_messages.") _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. @logger.info('Preparing and executing HttpRequest for get_app_user_messages.') _request = @http_client.get( _query_url, headers: _headers ) BasicAuth.apply(_request) _context = execute_request(_request, name: 'get_app_user_messages') # Validate response against endpoint and global error codes. @logger.info("Validating response for get_app_user_messages.") if _context.response.status_code == 404 raise APIException.new( 'The app user does not exist.', _context ) end validate_response(_context) # Return appropriate response type. @logger.info("Returning response for get_app_user_messages.") decoded = APIHelper.json_deserialize(_context.response.raw_body) GetAppUserMessagesResponse.from_hash(decoded) rescue Exception => e @logger.error(e) raise e end end |
#get_app_users ⇒ Object
Gets a list of App Users that belong to the configured account. A successful response from this endpoint will have the following structure: “‘ {
"data": [
{
"id": "3898c5e4-73cc-44f9-812f-3698a4c3bb1d",
"surname": "Sims",
"given_name": "Ben"
},
{
"id": "331b1da8-10a5-44c7-91df-1dc14cc2f373",
"surname": "Hood",
"given_name": "Robert"
}
]
} “‘
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/message_media_conversations/controllers/app_users_controller.rb', line 249 def get_app_users begin @logger.info("get_app_users called.") # Prepare query url. @logger.info("Preparing query URL for get_app_users.") _query_builder = Configuration.base_uri.dup _query_builder << '/beta/conversations/users' _query_url = APIHelper.clean_url _query_builder # Prepare headers. @logger.info("Preparing headers for get_app_users.") _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. @logger.info('Preparing and executing HttpRequest for get_app_users.') _request = @http_client.get( _query_url, headers: _headers ) BasicAuth.apply(_request) _context = execute_request(_request, name: 'get_app_users') validate_response(_context) # Return appropriate response type. @logger.info("Returning response for get_app_users.") decoded = APIHelper.json_deserialize(_context.response.raw_body) GetAppUsersResponse.from_hash(decoded) rescue Exception => e @logger.error(e) raise e end end |
#instance ⇒ Object
13 14 15 |
# File 'lib/message_media_conversations/controllers/app_users_controller.rb', line 13 def instance self.class.instance end |