Class: Raas::CustomersController
- Inherits:
-
BaseController
- Object
- BaseController
- Raas::CustomersController
- Defined in:
- lib/raas/controllers/customers_controller.rb
Overview
CustomersController
Class Attribute Summary collapse
-
.instance ⇒ Object
Returns the value of attribute instance.
Attributes inherited from BaseController
Instance Method Summary collapse
-
#create_customer(body) ⇒ Object
Creates a new customer Body.
-
#get_all_customers ⇒ Object
Retrieves all customers under the platform.
-
#get_customer(customer_identifier) ⇒ Object
Retrieves a single customer Identifier.
- #instance ⇒ Object
Methods inherited from BaseController
#execute_request, #initialize, #validate_parameters, #validate_response
Constructor Details
This class inherits a constructor from Raas::BaseController
Class Attribute Details
.instance ⇒ Object
Returns the value of attribute instance.
10 11 12 |
# File 'lib/raas/controllers/customers_controller.rb', line 10 def instance @instance end |
Instance Method Details
#create_customer(body) ⇒ Object
Creates a new customer Body
21 22 23 24 25 26 27 28 29 30 31 32 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 |
# File 'lib/raas/controllers/customers_controller.rb', line 21 def create_customer(body) begin @logger.info("create_customer called.") # Validate required parameters. @logger.info("Validating required parameters for create_customer.") validate_parameters( 'body' => body ) # Prepare query url. @logger.info("Preparing query URL for create_customer.") _query_builder = Configuration.get_base_uri _query_builder << '/customers' _query_url = APIHelper.clean_url _query_builder # Prepare headers. @logger.info("Preparing headers for create_customer.") _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8' } # Prepare and execute HttpRequest. @logger.info('Preparing and executing HttpRequest for create_customer.') _request = @http_client.post( _query_url, headers: _headers, parameters: body.to_json ) BasicAuth.apply(_request) _context = execute_request(_request, name: 'create_customer') # Validate response against endpoint and global error codes. @logger.info("Validating response for create_customer.") unless _context.response.status_code.between?(200, 208) raise RaasGenericException.new( 'API Error', _context ) end validate_response(_context) # Return appropriate response type. @logger.info("Returning response for create_customer.") decoded = APIHelper.json_deserialize(_context.response.raw_body) CustomerModel.from_hash(decoded) rescue Exception => e @logger.error(e) raise e end end |
#get_all_customers ⇒ Object
Retrieves all customers under the platform
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/raas/controllers/customers_controller.rb', line 75 def get_all_customers begin @logger.info("get_all_customers called.") # Prepare query url. @logger.info("Preparing query URL for get_all_customers.") _query_builder = Configuration.get_base_uri _query_builder << '/customers' _query_url = APIHelper.clean_url _query_builder # Prepare headers. @logger.info("Preparing headers for get_all_customers.") _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. @logger.info('Preparing and executing HttpRequest for get_all_customers.') _request = @http_client.get( _query_url, headers: _headers ) BasicAuth.apply(_request) _context = execute_request(_request, name: 'get_all_customers') # Validate response against endpoint and global error codes. @logger.info("Validating response for get_all_customers.") unless _context.response.status_code.between?(200, 208) raise RaasGenericException.new( 'API Error', _context ) end validate_response(_context) # Return appropriate response type. @logger.info("Returning response for get_all_customers.") decoded = APIHelper.json_deserialize(_context.response.raw_body) decoded.map { |element| CustomerModel.from_hash(element) } rescue Exception => e @logger.error(e) raise e end end |
#get_customer(customer_identifier) ⇒ Object
Retrieves a single customer Identifier
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 169 170 171 172 173 174 175 176 |
# File 'lib/raas/controllers/customers_controller.rb', line 124 def get_customer(customer_identifier) begin @logger.info("get_customer called.") # Validate required parameters. @logger.info("Validating required parameters for get_customer.") validate_parameters( 'customer_identifier' => customer_identifier ) # Prepare query url. @logger.info("Preparing query URL for get_customer.") _query_builder = Configuration.get_base_uri _query_builder << '/customers/{customerIdentifier}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'customerIdentifier' => customer_identifier ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. @logger.info("Preparing headers for get_customer.") _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. @logger.info('Preparing and executing HttpRequest for get_customer.') _request = @http_client.get( _query_url, headers: _headers ) BasicAuth.apply(_request) _context = execute_request(_request, name: 'get_customer') # Validate response against endpoint and global error codes. @logger.info("Validating response for get_customer.") unless _context.response.status_code.between?(200, 208) raise RaasGenericException.new( 'API Error', _context ) end validate_response(_context) # Return appropriate response type. @logger.info("Returning response for get_customer.") decoded = APIHelper.json_deserialize(_context.response.raw_body) CustomerModel.from_hash(decoded) rescue Exception => e @logger.error(e) raise e end end |
#instance ⇒ Object
13 14 15 |
# File 'lib/raas/controllers/customers_controller.rb', line 13 def instance self.class.instance end |