Class: Raas::CustomersController
- Inherits:
-
BaseController
- Object
- BaseController
- Raas::CustomersController
- Defined in:
- lib/raas/controllers/customers_controller.rb
Constant Summary collapse
- @@instance =
CustomersController.new
Instance Attribute Summary
Attributes inherited from BaseController
Class Method Summary collapse
-
.instance ⇒ Object
Singleton instance of the controller class.
Instance Method Summary collapse
-
#create_customer(body) ⇒ Object
Create a new customer.
-
#get_all_customers ⇒ Object
Gets all customers under the platform.
-
#get_customer(customer_identifier) ⇒ Object
Get a customer.
Methods inherited from BaseController
#execute_request, #initialize, #validate_parameters, #validate_response
Constructor Details
This class inherits a constructor from Raas::BaseController
Class Method Details
.instance ⇒ Object
Singleton instance of the controller class
7 8 9 |
# File 'lib/raas/controllers/customers_controller.rb', line 7 def self.instance @@instance end |
Instance Method Details
#create_customer(body) ⇒ Object
Create a new customer
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 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/raas/controllers/customers_controller.rb', line 60 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(_context) # return appropriate response type @logger.info("Returning response for create_customer.") decoded = APIHelper.json_deserialize(_context.response.raw_body) return CustomerModel.from_hash(decoded) rescue Exception => e @logger.error(e) raise e end end |
#get_all_customers ⇒ Object
Gets all customers under the platform
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/raas/controllers/customers_controller.rb', line 103 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(_context) # return appropriate response type @logger.info("Returning response for get_all_customers.") decoded = APIHelper.json_deserialize(_context.response.raw_body) return decoded.map{|element| CustomerModel.from_hash(element)} rescue Exception => e @logger.error(e) raise e end end |
#get_customer(customer_identifier) ⇒ Object
Get a customer
14 15 16 17 18 19 20 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 |
# File 'lib/raas/controllers/customers_controller.rb', line 14 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(_context) # return appropriate response type @logger.info("Returning response for get_customer.") decoded = APIHelper.json_deserialize(_context.response.raw_body) return CustomerModel.from_hash(decoded) rescue Exception => e @logger.error(e) raise e end end |