Class: TestPack1::AssetsController
- Inherits:
-
BaseController
- Object
- BaseController
- TestPack1::AssetsController
- Defined in:
- lib/test_pack_1/controllers/assets_controller.rb
Overview
AssetsController
Class Attribute Summary collapse
-
.instance ⇒ Object
Returns the value of attribute instance.
Attributes inherited from BaseController
Instance Method Summary collapse
-
#get_devices(device_type_ids = nil, site_ids = nil, parent_ids = nil, fields = nil, page_size = 50, page = 1) ⇒ Object
Gets a list of devices that the API key has permissions for.
-
#get_power_curves(device_ids, timestamp = nil, learned = false) ⇒ Object
Gets the default or learned power curves for wind turbines.
-
#get_sites(fields = nil, page_size = 50, page = 1) ⇒ Object
Gets a list of sites that the API key has permissions for.
- #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/assets_controller.rb', line 12 def instance @instance end |
Instance Method Details
#get_devices(device_type_ids = nil, site_ids = nil, parent_ids = nil, fields = nil, page_size = 50, page = 1) ⇒ Object
Gets a list of devices that the API key has permissions for. This request can also be made using the POST method, with a JSON request body instead of query parameters. types to get. Examples: * 1 - Wind turbine * 2 - Production meter * 3 - Met mast * 4 - Inverter * 10 - Device group * 11 - Grid meter * 12 - Combiner box * 23 - String at these sites. devices with these parent devices. in the response. Valid fields are those defined in the ‘Device` schema. By default all fields are included. return per page. number of items exceed the page size.
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/test_pack_1/controllers/assets_controller.rb', line 38 def get_devices(device_type_ids = nil, site_ids = nil, parent_ids = nil, fields = nil, page_size = 50, page = 1) # Prepare query url. _path_url = '/devices.json' _query_builder = Configuration.get_base_uri _query_builder << _path_url _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, { 'deviceTypeIds' => device_type_ids, 'siteIds' => site_ids, 'parentIds' => parent_ids, 'fields' => fields, '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| Device.from_hash(element) } end |
#get_power_curves(device_ids, timestamp = nil, learned = false) ⇒ Object
Gets the default or learned power curves for wind turbines. Other device types are not supported. This request can also be made using the POST method, with a JSON request body instead of query parameters. get power curves for. Only wind turbines are supported. power curves. The default is the current date. curves instead of default power curves.
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 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/test_pack_1/controllers/assets_controller.rb', line 163 def get_power_curves(device_ids, = nil, learned = false) # Prepare query url. _path_url = '/powercurves.json' _query_builder = Configuration.get_base_uri _query_builder << _path_url _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, { 'deviceIds' => device_ids, 'timestamp' => , 'learned' => learned }, 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| PowerCurve.from_hash(element) } end |
#get_sites(fields = nil, page_size = 50, page = 1) ⇒ Object
Gets a list of sites that the API key has permissions for. This request can also be made using the POST method, with a JSON request body instead of query parameters. in the response. Valid fields are those defined in the ‘SiteWithData` schema. By default all fields are included. return per page. number of items exceed the page size.
119 120 121 122 123 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 |
# File 'lib/test_pack_1/controllers/assets_controller.rb', line 119 def get_sites(fields = nil, page_size = 50, page = 1) # Prepare query url. _path_url = '/sites.json' _query_builder = Configuration.get_base_uri _query_builder << _path_url _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, { 'fields' => fields, '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(_context) # Return appropriate response type. decoded = APIHelper.json_deserialize(_context.response.raw_body) decoded.map { |element| SiteWithData.from_hash(element) } end |
#instance ⇒ Object
15 16 17 |
# File 'lib/test_pack_1/controllers/assets_controller.rb', line 15 def instance self.class.instance end |