Class: TestPack1::StatusesController
- Inherits:
-
BaseController
- Object
- BaseController
- TestPack1::StatusesController
- Defined in:
- lib/test_pack_1/controllers/statuses_controller.rb
Overview
StatusesController
Class Attribute Summary collapse
-
.instance ⇒ Object
Returns the value of attribute instance.
Attributes inherited from BaseController
Instance Method Summary collapse
-
#get_active_statuses(device_ids, category = nil, fields = nil, sort_by = nil, sort_asc = false, page_size = 50, page = 1) ⇒ Object
Gets active statuses for multiple devices.
-
#get_statuses(device_ids, timestamp_start, timestamp_end, category = nil, fields = nil, sort_by = nil, sort_asc = false, page_size = 50, page = 1) ⇒ Object
Gets statuses for multiple devices during the given time period.
- #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/statuses_controller.rb', line 12 def instance @instance end |
Instance Method Details
#get_active_statuses(device_ids, category = nil, fields = nil, sort_by = nil, sort_asc = false, page_size = 50, page = 1) ⇒ Object
Gets active statuses for multiple devices. This request can also be made using the POST method, with a JSON request body instead of query parameters. get statuses for. status categories to get statuses for. in the response. Valid fields are those defined in the ‘StatusItem` schema. By default all fields are included. the response items by. By default the items are sorted by timestampStart. ascending order. return per page. number of items exceed the page size.
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/test_pack_1/controllers/statuses_controller.rb', line 39 def get_active_statuses(device_ids, category = nil, fields = nil, sort_by = nil, sort_asc = false, page_size = 50, page = 1) # Prepare query url. _path_url = '/activestatus.json' _query_builder = Configuration.get_base_uri _query_builder << _path_url _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, { 'deviceIds' => device_ids, 'category' => category, 'fields' => fields, 'sortBy' => sort_by, 'sortAsc' => sort_asc, 'pageSize' => page_size, 'page' => page }, array_serialization: Configuration.array_serialization ) _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| StatusItem.from_hash(element) } end |
#get_statuses(device_ids, timestamp_start, timestamp_end, category = nil, fields = nil, sort_by = nil, sort_asc = false, page_size = 50, page = 1) ⇒ Object
Gets statuses for multiple devices during the given time period. This request can also be made using the POST method, with a JSON request body instead of query parameters. get statuses for. to get data for. Timestamps ending with ‘Z’ are treated as UTC. Other timestamps are treated as local time in your system-configured time zone. get data for. Timestamps ending with ‘Z’ are treated as UTC. Other timestamps are treated as local time in your system-configured time zone. status categories to get statuses for. in the response. Valid fields are those defined in the ‘StatusItem` schema. By default all fields are included. the response items by. By default the items are sorted by timestampStart. ascending order. return per page. number of items exceed the page size.
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 177 178 179 180 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 |
# File 'lib/test_pack_1/controllers/statuses_controller.rb', line 139 def get_statuses(device_ids, , , category = nil, fields = nil, sort_by = nil, sort_asc = false, page_size = 50, page = 1) # Prepare query url. _path_url = '/status.json' _query_builder = Configuration.get_base_uri _query_builder << _path_url _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, { 'deviceIds' => device_ids, 'timestampStart' => , 'timestampEnd' => , 'category' => category, 'fields' => fields, 'sortBy' => sort_by, 'sortAsc' => sort_asc, 'pageSize' => page_size, 'page' => page }, array_serialization: Configuration.array_serialization ) _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| StatusItem.from_hash(element) } end |
#instance ⇒ Object
15 16 17 |
# File 'lib/test_pack_1/controllers/statuses_controller.rb', line 15 def instance self.class.instance end |