Class: MessageMediaConversations::ConfigurationController
- Inherits:
-
BaseController
- Object
- BaseController
- MessageMediaConversations::ConfigurationController
- Defined in:
- lib/message_media_conversations/controllers/configuration_controller.rb
Overview
ConfigurationController
Class Attribute Summary collapse
-
.instance ⇒ Object
Returns the value of attribute instance.
Attributes inherited from BaseController
Instance Method Summary collapse
-
#create_configure_account(body) ⇒ Object
Configures your existing MessageMedia account to use the Conversations API by giving it a human readable name (for reference later on), and also by specifying a callback URL which is where any Inbound Messages and/or Notifications will be pushed to.
- #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/configuration_controller.rb', line 10 def instance @instance end |
Instance Method Details
#create_configure_account(body) ⇒ Object
Configures your existing MessageMedia account to use the Conversations API by giving it a human readable name (for reference later on), and also by specifying a callback URL which is where any Inbound Messages and/or Notifications will be pushed to. The request would have the following structure: “‘
"name": "Rainbow Serpent Festival",
"callback_url": "http://accounts-domain.com/callback"
“‘
-
‘name` is a required property and is a customer friendly name to
identify your provisioned account
-
‘callback_url` is an optional property is the callback URL to forward
inbound messages to. *Note: We are currently NOT using our Webhooks functionality for this while it’s in beta, when we make this production ready we will look at switching to having these webhooks managed via the Webhooks Management API*
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/configuration_controller.rb', line 38 def create_configure_account(body) begin @logger.info("create_configure_account called.") # Prepare query url. @logger.info("Preparing query URL for create_configure_account.") _query_builder = Configuration.base_uri.dup _query_builder << '/beta/conversations/provision' _query_url = APIHelper.clean_url _query_builder # Prepare headers. @logger.info("Preparing headers for create_configure_account.") _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8' } # Prepare and execute HttpRequest. @logger.info('Preparing and executing HttpRequest for create_configure_account.') _request = @http_client.post( _query_url, headers: _headers, parameters: body.to_json ) BasicAuth.apply(_request) _context = execute_request(_request, name: 'create_configure_account') # Validate response against endpoint and global error codes. @logger.info("Validating response for create_configure_account.") if _context.response.status_code == 400 raise APIException.new( 'Not a valid request body.', _context ) elsif _context.response.status_code == 409 raise APIException.new( 'The account has already been provisioned.', _context ) end validate_response(_context) # Return appropriate response type. @logger.info("Returning response for create_configure_account.") decoded = APIHelper.json_deserialize(_context.response.raw_body) ConfigureAccountResponse.from_hash(decoded) rescue Exception => e @logger.error(e) raise e end end |
#instance ⇒ Object
13 14 15 |
# File 'lib/message_media_conversations/controllers/configuration_controller.rb', line 13 def instance self.class.instance end |