Class: TestPack1::ConfigurationDataController
- Inherits:
-
BaseController
- Object
- BaseController
- TestPack1::ConfigurationDataController
- Defined in:
- lib/test_pack_1/controllers/configuration_data_controller.rb
Overview
ConfigurationDataController
Class Attribute Summary collapse
-
.instance ⇒ Object
Returns the value of attribute instance.
Attributes inherited from BaseController
Instance Method Summary collapse
-
#get_configuration ⇒ Object
Gets your system-wide configuration data.
- #instance ⇒ Object
Methods inherited from BaseController
#execute_request, #initialize, #validate_parameters, #validate_response
Constructor Details
This class inherits a constructor from TestPack1::BaseController
Class Attribute Details
.instance ⇒ Object
Returns the value of attribute instance.
12 13 14 |
# File 'lib/test_pack_1/controllers/configuration_data_controller.rb', line 12 def instance @instance end |
Instance Method Details
#get_configuration ⇒ Object
Gets your system-wide configuration data. This request can also be made using the POST method, with a JSON request body instead of query parameters.
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 72 73 74 |
# File 'lib/test_pack_1/controllers/configuration_data_controller.rb', line 23 def get_configuration # Prepare query url. _path_url = '/configuration.json' _query_builder = Configuration.get_base_uri _query_builder << _path_url _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = @http_client.get( _query_url, headers: _headers ) CustomQueryAuth.apply(_request) _context = execute_request(_request) # Validate response against endpoint and global error codes. if _context.response.status_code == 400 raise APIException.new( 'The request cannot be fulfilled due to bad syntax.', _context ) elsif _context.response.status_code == 401 raise APIException.new( 'One of the following: * The request is missing a valid API key. *' \ ' The API key does not authorize access the requested' \ ' data. Devices or data signals can be limited. ', _context ) elsif _context.response.status_code == 405 raise APIException.new( 'The HTTP method is not allowed for the endpoint.', _context ) elsif _context.response.status_code == 429 raise APIException.new( 'The API key has been used in too many requests in a given amount' \ ' of time. The following headers will be set in the' \ ' response: * X-Rate-Limit-Limit - The total number of' \ ' allowed requests for this period. *' \ ' X-Rate-Limit-Remaining - The remaining number of' \ ' requests for this period. * X-Rate-Limit-Reset - The' \ ' number of seconds left until the end of this period. ', _context ) end validate_response(_context) # Return appropriate response type. decoded = APIHelper.json_deserialize(_context.response.raw_body) decoded.map { |element| ConfigurationItem.from_hash(element) } end |
#instance ⇒ Object
15 16 17 |
# File 'lib/test_pack_1/controllers/configuration_data_controller.rb', line 15 def instance self.class.instance end |