test-pack-1 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +28 -0
  3. data/README.md +872 -0
  4. data/lib/test_pack_1.rb +63 -0
  5. data/lib/test_pack_1/api_helper.rb +275 -0
  6. data/lib/test_pack_1/configuration.rb +63 -0
  7. data/lib/test_pack_1/controllers/alerts_controller.rb +381 -0
  8. data/lib/test_pack_1/controllers/assets_controller.rb +227 -0
  9. data/lib/test_pack_1/controllers/base_controller.rb +51 -0
  10. data/lib/test_pack_1/controllers/configuration_data_controller.rb +76 -0
  11. data/lib/test_pack_1/controllers/data_controller.rb +349 -0
  12. data/lib/test_pack_1/controllers/statuses_controller.rb +215 -0
  13. data/lib/test_pack_1/exceptions/api_exception.rb +20 -0
  14. data/lib/test_pack_1/http/auth/custom_query_auth.rb +16 -0
  15. data/lib/test_pack_1/http/faraday_client.rb +64 -0
  16. data/lib/test_pack_1/http/http_call_back.rb +24 -0
  17. data/lib/test_pack_1/http/http_client.rb +104 -0
  18. data/lib/test_pack_1/http/http_context.rb +20 -0
  19. data/lib/test_pack_1/http/http_method_enum.rb +13 -0
  20. data/lib/test_pack_1/http/http_request.rb +50 -0
  21. data/lib/test_pack_1/http/http_response.rb +23 -0
  22. data/lib/test_pack_1/models/aggregate_mode_enum.rb +23 -0
  23. data/lib/test_pack_1/models/alert_item.rb +104 -0
  24. data/lib/test_pack_1/models/base_model.rb +36 -0
  25. data/lib/test_pack_1/models/calculation_mode_enum.rb +20 -0
  26. data/lib/test_pack_1/models/client_configuration.rb +62 -0
  27. data/lib/test_pack_1/models/configuration_item.rb +55 -0
  28. data/lib/test_pack_1/models/data_item.rb +92 -0
  29. data/lib/test_pack_1/models/data_per_category_item.rb +82 -0
  30. data/lib/test_pack_1/models/data_per_category_response.rb +63 -0
  31. data/lib/test_pack_1/models/data_real_time_item.rb +83 -0
  32. data/lib/test_pack_1/models/data_signal.rb +53 -0
  33. data/lib/test_pack_1/models/data_signal_configuration.rb +66 -0
  34. data/lib/test_pack_1/models/data_signal_item.rb +62 -0
  35. data/lib/test_pack_1/models/device.rb +208 -0
  36. data/lib/test_pack_1/models/device_model.rb +53 -0
  37. data/lib/test_pack_1/models/metadata_field.rb +44 -0
  38. data/lib/test_pack_1/models/power_curve.rb +60 -0
  39. data/lib/test_pack_1/models/power_curve_value.rb +44 -0
  40. data/lib/test_pack_1/models/resolution_enum.rb +41 -0
  41. data/lib/test_pack_1/models/site.rb +44 -0
  42. data/lib/test_pack_1/models/site_with_data.rb +78 -0
  43. data/lib/test_pack_1/models/status_category_enum.rb +26 -0
  44. data/lib/test_pack_1/models/status_item.rb +161 -0
  45. data/lib/test_pack_1/models/time_zone_configuration.rb +76 -0
  46. data/lib/test_pack_1/models/turbine_type.rb +89 -0
  47. data/lib/test_pack_1/test_pack1_client.rb +51 -0
  48. data/test/controllers/controller_test_base.rb +33 -0
  49. data/test/controllers/test_assets_controller.rb +46 -0
  50. data/test/controllers/test_configuration_data_controller.rb +44 -0
  51. data/test/http_response_catcher.rb +20 -0
  52. data/test/test_helper.rb +99 -0
  53. metadata +219 -0
@@ -0,0 +1,227 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module TestPack1
7
+ # AssetsController
8
+ class AssetsController < BaseController
9
+ @instance = AssetsController.new
10
+
11
+ class << self
12
+ attr_accessor :instance
13
+ end
14
+
15
+ def instance
16
+ self.class.instance
17
+ end
18
+
19
+ # Gets a list of devices that the API key has permissions for. This request
20
+ # can also be made using the POST method, with a JSON request body instead
21
+ # of query parameters.
22
+ # @param [List of Integer] device_type_ids Optional parameter: Which device
23
+ # types to get. Examples: * 1 - Wind turbine * 2 - Production meter * 3 -
24
+ # Met mast * 4 - Inverter * 10 - Device group * 11 - Grid meter * 12 -
25
+ # Combiner box * 23 - String
26
+ # @param [List of Integer] site_ids Optional parameter: Only include devices
27
+ # at these sites.
28
+ # @param [List of Integer] parent_ids Optional parameter: Only include
29
+ # devices with these parent devices.
30
+ # @param [List of String] fields Optional parameter: Which fields to include
31
+ # in the response. Valid fields are those defined in the `Device` schema. By
32
+ # default all fields are included.
33
+ # @param [Integer] page_size Optional parameter: The number of items to
34
+ # return per page.
35
+ # @param [Integer] page Optional parameter: Which page to return when the
36
+ # number of items exceed the page size.
37
+ # @return List of Device response from the API call
38
+ def get_devices(device_type_ids = nil,
39
+ site_ids = nil,
40
+ parent_ids = nil,
41
+ fields = nil,
42
+ page_size = 50,
43
+ page = 1)
44
+ # Prepare query url.
45
+ _path_url = '/devices.json'
46
+ _query_builder = Configuration.get_base_uri
47
+ _query_builder << _path_url
48
+ _query_builder = APIHelper.append_url_with_query_parameters(
49
+ _query_builder,
50
+ {
51
+ 'deviceTypeIds' => device_type_ids,
52
+ 'siteIds' => site_ids,
53
+ 'parentIds' => parent_ids,
54
+ 'fields' => fields,
55
+ 'pageSize' => page_size,
56
+ 'page' => page
57
+ },
58
+ array_serialization: Configuration.array_serialization
59
+ )
60
+ _query_url = APIHelper.clean_url _query_builder
61
+ # Prepare headers.
62
+ _headers = {
63
+ 'accept' => 'application/json'
64
+ }
65
+ # Prepare and execute HttpRequest.
66
+ _request = @http_client.get(
67
+ _query_url,
68
+ headers: _headers
69
+ )
70
+ CustomQueryAuth.apply(_request)
71
+ _context = execute_request(_request)
72
+ # Validate response against endpoint and global error codes.
73
+ if _context.response.status_code == 400
74
+ raise APIException.new(
75
+ 'The request cannot be fulfilled due to bad syntax.',
76
+ _context
77
+ )
78
+ elsif _context.response.status_code == 401
79
+ raise APIException.new(
80
+ 'One of the following: * The request is missing a valid API key. *' \
81
+ ' The API key does not authorize access the requested' \
82
+ ' data. Devices or data signals can be limited. ',
83
+ _context
84
+ )
85
+ elsif _context.response.status_code == 405
86
+ raise APIException.new(
87
+ 'The HTTP method is not allowed for the endpoint.',
88
+ _context
89
+ )
90
+ elsif _context.response.status_code == 429
91
+ raise APIException.new(
92
+ 'The API key has been used in too many requests in a given amount' \
93
+ ' of time. The following headers will be set in the' \
94
+ ' response: * X-Rate-Limit-Limit - The total number of' \
95
+ ' allowed requests for this period. *' \
96
+ ' X-Rate-Limit-Remaining - The remaining number of' \
97
+ ' requests for this period. * X-Rate-Limit-Reset - The' \
98
+ ' number of seconds left until the end of this period. ',
99
+ _context
100
+ )
101
+ end
102
+ validate_response(_context)
103
+ # Return appropriate response type.
104
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
105
+ decoded.map { |element| Device.from_hash(element) }
106
+ end
107
+
108
+ # Gets a list of sites that the API key has permissions for. This request
109
+ # can also be made using the POST method, with a JSON request body instead
110
+ # of query parameters.
111
+ # @param [List of String] fields Optional parameter: Which fields to include
112
+ # in the response. Valid fields are those defined in the `SiteWithData`
113
+ # schema. By default all fields are included.
114
+ # @param [Integer] page_size Optional parameter: The number of items to
115
+ # return per page.
116
+ # @param [Integer] page Optional parameter: Which page to return when the
117
+ # number of items exceed the page size.
118
+ # @return List of SiteWithData response from the API call
119
+ def get_sites(fields = nil,
120
+ page_size = 50,
121
+ page = 1)
122
+ # Prepare query url.
123
+ _path_url = '/sites.json'
124
+ _query_builder = Configuration.get_base_uri
125
+ _query_builder << _path_url
126
+ _query_builder = APIHelper.append_url_with_query_parameters(
127
+ _query_builder,
128
+ {
129
+ 'fields' => fields,
130
+ 'pageSize' => page_size,
131
+ 'page' => page
132
+ },
133
+ array_serialization: Configuration.array_serialization
134
+ )
135
+ _query_url = APIHelper.clean_url _query_builder
136
+ # Prepare headers.
137
+ _headers = {
138
+ 'accept' => 'application/json'
139
+ }
140
+ # Prepare and execute HttpRequest.
141
+ _request = @http_client.get(
142
+ _query_url,
143
+ headers: _headers
144
+ )
145
+ CustomQueryAuth.apply(_request)
146
+ _context = execute_request(_request)
147
+ validate_response(_context)
148
+ # Return appropriate response type.
149
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
150
+ decoded.map { |element| SiteWithData.from_hash(element) }
151
+ end
152
+
153
+ # Gets the default or learned power curves for wind turbines. Other device
154
+ # types are not supported. This request can also be made using the POST
155
+ # method, with a JSON request body instead of query parameters.
156
+ # @param [List of Integer] device_ids Required parameter: What devices to
157
+ # get power curves for. Only wind turbines are supported.
158
+ # @param [Date] timestamp Optional parameter: The date for which to get
159
+ # power curves. The default is the current date.
160
+ # @param [Boolean] learned Optional parameter: Whether to get learned power
161
+ # curves instead of default power curves.
162
+ # @return List of PowerCurve response from the API call
163
+ def get_power_curves(device_ids,
164
+ timestamp = nil,
165
+ learned = false)
166
+ # Prepare query url.
167
+ _path_url = '/powercurves.json'
168
+ _query_builder = Configuration.get_base_uri
169
+ _query_builder << _path_url
170
+ _query_builder = APIHelper.append_url_with_query_parameters(
171
+ _query_builder,
172
+ {
173
+ 'deviceIds' => device_ids,
174
+ 'timestamp' => timestamp,
175
+ 'learned' => learned
176
+ },
177
+ array_serialization: Configuration.array_serialization
178
+ )
179
+ _query_url = APIHelper.clean_url _query_builder
180
+ # Prepare headers.
181
+ _headers = {
182
+ 'accept' => 'application/json'
183
+ }
184
+ # Prepare and execute HttpRequest.
185
+ _request = @http_client.get(
186
+ _query_url,
187
+ headers: _headers
188
+ )
189
+ CustomQueryAuth.apply(_request)
190
+ _context = execute_request(_request)
191
+ # Validate response against endpoint and global error codes.
192
+ if _context.response.status_code == 400
193
+ raise APIException.new(
194
+ 'The request cannot be fulfilled due to bad syntax.',
195
+ _context
196
+ )
197
+ elsif _context.response.status_code == 401
198
+ raise APIException.new(
199
+ 'One of the following: * The request is missing a valid API key. *' \
200
+ ' The API key does not authorize access the requested' \
201
+ ' data. Devices or data signals can be limited. ',
202
+ _context
203
+ )
204
+ elsif _context.response.status_code == 405
205
+ raise APIException.new(
206
+ 'The HTTP method is not allowed for the endpoint.',
207
+ _context
208
+ )
209
+ elsif _context.response.status_code == 429
210
+ raise APIException.new(
211
+ 'The API key has been used in too many requests in a given amount' \
212
+ ' of time. The following headers will be set in the' \
213
+ ' response: * X-Rate-Limit-Limit - The total number of' \
214
+ ' allowed requests for this period. *' \
215
+ ' X-Rate-Limit-Remaining - The remaining number of' \
216
+ ' requests for this period. * X-Rate-Limit-Reset - The' \
217
+ ' number of seconds left until the end of this period. ',
218
+ _context
219
+ )
220
+ end
221
+ validate_response(_context)
222
+ # Return appropriate response type.
223
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
224
+ decoded.map { |element| PowerCurve.from_hash(element) }
225
+ end
226
+ end
227
+ end
@@ -0,0 +1,51 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module TestPack1
7
+ # Base controller.
8
+ class BaseController
9
+ attr_accessor :http_client, :http_call_back
10
+
11
+ def initialize(http_client: nil, http_call_back: nil)
12
+ @http_client = http_client || FaradayClient.new
13
+ @http_call_back = http_call_back
14
+
15
+ @global_headers = {
16
+ 'user-agent' => 'APIMATIC 2.0'
17
+ }
18
+ end
19
+
20
+ def validate_parameters(args)
21
+ args.each do |_name, value|
22
+ if value.nil?
23
+ raise ArgumentError, "Required parameter #{_name} cannot be nil."
24
+ end
25
+ end
26
+ end
27
+
28
+ def execute_request(request, binary: false)
29
+ @http_call_back.on_before_request(request) if @http_call_back
30
+
31
+ APIHelper.clean_hash(request.headers)
32
+ request.headers = @global_headers.clone.merge(request.headers)
33
+
34
+ response = if binary
35
+ @http_client.execute_as_binary(request)
36
+ else
37
+ @http_client.execute_as_string(request)
38
+ end
39
+ context = HttpContext.new(request, response)
40
+
41
+ @http_call_back.on_after_response(context) if @http_call_back
42
+
43
+ context
44
+ end
45
+
46
+ def validate_response(context)
47
+ raise APIException.new 'HTTP Response Not OK', context unless
48
+ context.response.status_code.between?(200, 208) # [200,208] = HTTP OK
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,76 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module TestPack1
7
+ # ConfigurationDataController
8
+ class ConfigurationDataController < BaseController
9
+ @instance = ConfigurationDataController.new
10
+
11
+ class << self
12
+ attr_accessor :instance
13
+ end
14
+
15
+ def instance
16
+ self.class.instance
17
+ end
18
+
19
+ # Gets your system-wide configuration data. This request can also be made
20
+ # using the POST method, with a JSON request body instead of query
21
+ # parameters.
22
+ # @return List of ConfigurationItem response from the API call
23
+ def get_configuration
24
+ # Prepare query url.
25
+ _path_url = '/configuration.json'
26
+ _query_builder = Configuration.get_base_uri
27
+ _query_builder << _path_url
28
+ _query_url = APIHelper.clean_url _query_builder
29
+ # Prepare headers.
30
+ _headers = {
31
+ 'accept' => 'application/json'
32
+ }
33
+ # Prepare and execute HttpRequest.
34
+ _request = @http_client.get(
35
+ _query_url,
36
+ headers: _headers
37
+ )
38
+ CustomQueryAuth.apply(_request)
39
+ _context = execute_request(_request)
40
+ # Validate response against endpoint and global error codes.
41
+ if _context.response.status_code == 400
42
+ raise APIException.new(
43
+ 'The request cannot be fulfilled due to bad syntax.',
44
+ _context
45
+ )
46
+ elsif _context.response.status_code == 401
47
+ raise APIException.new(
48
+ 'One of the following: * The request is missing a valid API key. *' \
49
+ ' The API key does not authorize access the requested' \
50
+ ' data. Devices or data signals can be limited. ',
51
+ _context
52
+ )
53
+ elsif _context.response.status_code == 405
54
+ raise APIException.new(
55
+ 'The HTTP method is not allowed for the endpoint.',
56
+ _context
57
+ )
58
+ elsif _context.response.status_code == 429
59
+ raise APIException.new(
60
+ 'The API key has been used in too many requests in a given amount' \
61
+ ' of time. The following headers will be set in the' \
62
+ ' response: * X-Rate-Limit-Limit - The total number of' \
63
+ ' allowed requests for this period. *' \
64
+ ' X-Rate-Limit-Remaining - The remaining number of' \
65
+ ' requests for this period. * X-Rate-Limit-Reset - The' \
66
+ ' number of seconds left until the end of this period. ',
67
+ _context
68
+ )
69
+ end
70
+ validate_response(_context)
71
+ # Return appropriate response type.
72
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
73
+ decoded.map { |element| ConfigurationItem.from_hash(element) }
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,349 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module TestPack1
7
+ # DataController
8
+ class DataController < BaseController
9
+ @instance = DataController.new
10
+
11
+ class << self
12
+ attr_accessor :instance
13
+ end
14
+
15
+ def instance
16
+ self.class.instance
17
+ end
18
+
19
+ # Gets authorized data signals for one or more devices. This request can
20
+ # also be made using the POST method, with a JSON request body instead of
21
+ # query parameters.
22
+ # @param [List of Integer] device_ids Required parameter: What devices to
23
+ # get data signals for.
24
+ # @return List of DataSignalItem response from the API call
25
+ def get_data_signals(device_ids)
26
+ # Prepare query url.
27
+ _path_url = '/datasignals.json'
28
+ _query_builder = Configuration.get_base_uri
29
+ _query_builder << _path_url
30
+ _query_builder = APIHelper.append_url_with_query_parameters(
31
+ _query_builder,
32
+ {
33
+ 'deviceIds' => device_ids
34
+ },
35
+ array_serialization: Configuration.array_serialization
36
+ )
37
+ _query_url = APIHelper.clean_url _query_builder
38
+ # Prepare headers.
39
+ _headers = {
40
+ 'accept' => 'application/json'
41
+ }
42
+ # Prepare and execute HttpRequest.
43
+ _request = @http_client.get(
44
+ _query_url,
45
+ headers: _headers
46
+ )
47
+ CustomQueryAuth.apply(_request)
48
+ _context = execute_request(_request)
49
+ # Validate response against endpoint and global error codes.
50
+ if _context.response.status_code == 400
51
+ raise APIException.new(
52
+ 'The request cannot be fulfilled due to bad syntax.',
53
+ _context
54
+ )
55
+ elsif _context.response.status_code == 401
56
+ raise APIException.new(
57
+ 'One of the following: * The request is missing a valid API key. *' \
58
+ ' The API key does not authorize access the requested' \
59
+ ' data. Devices or data signals can be limited. ',
60
+ _context
61
+ )
62
+ elsif _context.response.status_code == 405
63
+ raise APIException.new(
64
+ 'The HTTP method is not allowed for the endpoint.',
65
+ _context
66
+ )
67
+ elsif _context.response.status_code == 429
68
+ raise APIException.new(
69
+ 'The API key has been used in too many requests in a given amount' \
70
+ ' of time. The following headers will be set in the' \
71
+ ' response: * X-Rate-Limit-Limit - The total number of' \
72
+ ' allowed requests for this period. *' \
73
+ ' X-Rate-Limit-Remaining - The remaining number of' \
74
+ ' requests for this period. * X-Rate-Limit-Reset - The' \
75
+ ' number of seconds left until the end of this period. ',
76
+ _context
77
+ )
78
+ end
79
+ validate_response(_context)
80
+ # Return appropriate response type.
81
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
82
+ decoded.map { |element| DataSignalItem.from_hash(element) }
83
+ end
84
+
85
+ # Gets data for multiple devices and data signals in the given resolution.
86
+ # This request can also be made using the POST method, with a JSON request
87
+ # body instead of query parameters.
88
+ # @param [List of Integer] device_ids Required parameter: Which devices to
89
+ # get data for.
90
+ # @param [List of Integer] data_signal_ids Required parameter: Which data
91
+ # signals to get data for.
92
+ # @param [DateTime] timestamp_start Required parameter: The first timestamp
93
+ # to get data for. Timestamps ending with 'Z' are treated as UTC. Other
94
+ # timestamps are treated as local time in your system-configured time
95
+ # zone.
96
+ # @param [DateTime] timestamp_end Required parameter: The last timestamp to
97
+ # get data for. Timestamps ending with 'Z' are treated as UTC. Other
98
+ # timestamps are treated as local time in your system-configured time
99
+ # zone.
100
+ # @param [ResolutionEnum] resolution Optional parameter: The desired data
101
+ # resolution.
102
+ # @param [AggregateModeEnum] aggregate Optional parameter: How the data
103
+ # should be aggregated with regards to device(s) or site(s).
104
+ # @param [CalculationModeEnum] calculation Optional parameter: The
105
+ # calculation used when aggregating data, both over time and across devices.
106
+ # The default is the data signal default.
107
+ # @return List of DataItem response from the API call
108
+ def get_data(device_ids,
109
+ data_signal_ids,
110
+ timestamp_start,
111
+ timestamp_end,
112
+ resolution = nil,
113
+ aggregate = nil,
114
+ calculation = nil)
115
+ # Prepare query url.
116
+ _path_url = '/data.json'
117
+ _query_builder = Configuration.get_base_uri
118
+ _query_builder << _path_url
119
+ _query_builder = APIHelper.append_url_with_query_parameters(
120
+ _query_builder,
121
+ {
122
+ 'deviceIds' => device_ids,
123
+ 'dataSignalIds' => data_signal_ids,
124
+ 'timestampStart' => timestamp_start,
125
+ 'timestampEnd' => timestamp_end,
126
+ 'resolution' => resolution,
127
+ 'aggregate' => aggregate,
128
+ 'calculation' => calculation
129
+ },
130
+ array_serialization: Configuration.array_serialization
131
+ )
132
+ _query_url = APIHelper.clean_url _query_builder
133
+ # Prepare headers.
134
+ _headers = {
135
+ 'accept' => 'application/json'
136
+ }
137
+ # Prepare and execute HttpRequest.
138
+ _request = @http_client.get(
139
+ _query_url,
140
+ headers: _headers
141
+ )
142
+ CustomQueryAuth.apply(_request)
143
+ _context = execute_request(_request)
144
+ # Validate response against endpoint and global error codes.
145
+ if _context.response.status_code == 400
146
+ raise APIException.new(
147
+ 'The request cannot be fulfilled due to bad syntax.',
148
+ _context
149
+ )
150
+ elsif _context.response.status_code == 401
151
+ raise APIException.new(
152
+ 'One of the following: * The request is missing a valid API key. *' \
153
+ ' The API key does not authorize access the requested' \
154
+ ' data. Devices or data signals can be limited. ',
155
+ _context
156
+ )
157
+ elsif _context.response.status_code == 405
158
+ raise APIException.new(
159
+ 'The HTTP method is not allowed for the endpoint.',
160
+ _context
161
+ )
162
+ elsif _context.response.status_code == 429
163
+ raise APIException.new(
164
+ 'The API key has been used in too many requests in a given amount' \
165
+ ' of time. The following headers will be set in the' \
166
+ ' response: * X-Rate-Limit-Limit - The total number of' \
167
+ ' allowed requests for this period. *' \
168
+ ' X-Rate-Limit-Remaining - The remaining number of' \
169
+ ' requests for this period. * X-Rate-Limit-Reset - The' \
170
+ ' number of seconds left until the end of this period. ',
171
+ _context
172
+ )
173
+ end
174
+ validate_response(_context)
175
+ # Return appropriate response type.
176
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
177
+ decoded.map { |element| DataItem.from_hash(element) }
178
+ end
179
+
180
+ # Gets the most recent high-resolution data point for each specified device
181
+ # and data signal. This request can also be made using the POST method, with
182
+ # a JSON request body instead of query parameters.
183
+ # @param [List of Integer] device_ids Required parameter: Which devices to
184
+ # get data for.
185
+ # @param [List of Integer] data_signal_ids Required parameter: Which data
186
+ # signals to get data for.
187
+ # @param [AggregateModeEnum] aggregate Optional parameter: How the data
188
+ # should be aggregated with regards to device(s) or site(s).
189
+ # @param [CalculationModeEnum] calculation Optional parameter: The
190
+ # calculation used when aggregating data, both over time and across devices.
191
+ # The default is the data signal default.
192
+ # @return List of DataRealTimeItem response from the API call
193
+ def get_real_time_data(device_ids,
194
+ data_signal_ids,
195
+ aggregate = nil,
196
+ calculation = nil)
197
+ # Prepare query url.
198
+ _path_url = '/realtimedata.json'
199
+ _query_builder = Configuration.get_base_uri
200
+ _query_builder << _path_url
201
+ _query_builder = APIHelper.append_url_with_query_parameters(
202
+ _query_builder,
203
+ {
204
+ 'deviceIds' => device_ids,
205
+ 'dataSignalIds' => data_signal_ids,
206
+ 'aggregate' => aggregate,
207
+ 'calculation' => calculation
208
+ },
209
+ array_serialization: Configuration.array_serialization
210
+ )
211
+ _query_url = APIHelper.clean_url _query_builder
212
+ # Prepare headers.
213
+ _headers = {
214
+ 'accept' => 'application/json'
215
+ }
216
+ # Prepare and execute HttpRequest.
217
+ _request = @http_client.get(
218
+ _query_url,
219
+ headers: _headers
220
+ )
221
+ CustomQueryAuth.apply(_request)
222
+ _context = execute_request(_request)
223
+ # Validate response against endpoint and global error codes.
224
+ if _context.response.status_code == 400
225
+ raise APIException.new(
226
+ 'The request cannot be fulfilled due to bad syntax.',
227
+ _context
228
+ )
229
+ elsif _context.response.status_code == 401
230
+ raise APIException.new(
231
+ 'One of the following: * The request is missing a valid API key. *' \
232
+ ' The API key does not authorize access the requested' \
233
+ ' data. Devices or data signals can be limited. ',
234
+ _context
235
+ )
236
+ elsif _context.response.status_code == 405
237
+ raise APIException.new(
238
+ 'The HTTP method is not allowed for the endpoint.',
239
+ _context
240
+ )
241
+ elsif _context.response.status_code == 429
242
+ raise APIException.new(
243
+ 'The API key has been used in too many requests in a given amount' \
244
+ ' of time. The following headers will be set in the' \
245
+ ' response: * X-Rate-Limit-Limit - The total number of' \
246
+ ' allowed requests for this period. *' \
247
+ ' X-Rate-Limit-Remaining - The remaining number of' \
248
+ ' requests for this period. * X-Rate-Limit-Reset - The' \
249
+ ' number of seconds left until the end of this period. ',
250
+ _context
251
+ )
252
+ end
253
+ validate_response(_context)
254
+ # Return appropriate response type.
255
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
256
+ decoded.map { |element| DataRealTimeItem.from_hash(element) }
257
+ end
258
+
259
+ # Gets signal data aggregated per availability contract category. This
260
+ # request can also be made using the POST method, with a JSON request body
261
+ # instead of query parameters.
262
+ # @param [List of Integer] device_ids Required parameter: Which devices to
263
+ # get data for.
264
+ # @param [Integer] data_signal_id Required parameter: Which signal to get
265
+ # data for; only Lost Production signals are supported at the moment.
266
+ # @param [DateTime] timestamp_start Required parameter: The first timestamp
267
+ # to get data for. Timestamps ending with 'Z' are treated as UTC. Other
268
+ # timestamps are treated as local time in your system-configured time
269
+ # zone.
270
+ # @param [DateTime] timestamp_end Required parameter: The last timestamp to
271
+ # get data for. Timestamps ending with 'Z' are treated as UTC. Other
272
+ # timestamps are treated as local time in your system-configured time
273
+ # zone.
274
+ # @param [AggregateModeEnum] aggregate Optional parameter: How the data
275
+ # should be aggregated with regards to device(s) or site(s).
276
+ # @param [List of StatusCategoryEnum] category Optional parameter: Which
277
+ # status categories to include. By default all categories are included.
278
+ # @return DataPerCategoryResponse response from the API call
279
+ def get_data_per_category(device_ids,
280
+ data_signal_id,
281
+ timestamp_start,
282
+ timestamp_end,
283
+ aggregate = nil,
284
+ category = nil)
285
+ # Prepare query url.
286
+ _path_url = '/datapercategory.json'
287
+ _query_builder = Configuration.get_base_uri
288
+ _query_builder << _path_url
289
+ _query_builder = APIHelper.append_url_with_query_parameters(
290
+ _query_builder,
291
+ {
292
+ 'deviceIds' => device_ids,
293
+ 'dataSignalId' => data_signal_id,
294
+ 'timestampStart' => timestamp_start,
295
+ 'timestampEnd' => timestamp_end,
296
+ 'aggregate' => aggregate,
297
+ 'category' => category
298
+ },
299
+ array_serialization: Configuration.array_serialization
300
+ )
301
+ _query_url = APIHelper.clean_url _query_builder
302
+ # Prepare headers.
303
+ _headers = {
304
+ 'accept' => 'application/json'
305
+ }
306
+ # Prepare and execute HttpRequest.
307
+ _request = @http_client.get(
308
+ _query_url,
309
+ headers: _headers
310
+ )
311
+ CustomQueryAuth.apply(_request)
312
+ _context = execute_request(_request)
313
+ # Validate response against endpoint and global error codes.
314
+ if _context.response.status_code == 400
315
+ raise APIException.new(
316
+ 'The request cannot be fulfilled due to bad syntax.',
317
+ _context
318
+ )
319
+ elsif _context.response.status_code == 401
320
+ raise APIException.new(
321
+ 'One of the following: * The request is missing a valid API key. *' \
322
+ ' The API key does not authorize access the requested' \
323
+ ' data. Devices or data signals can be limited. ',
324
+ _context
325
+ )
326
+ elsif _context.response.status_code == 405
327
+ raise APIException.new(
328
+ 'The HTTP method is not allowed for the endpoint.',
329
+ _context
330
+ )
331
+ elsif _context.response.status_code == 429
332
+ raise APIException.new(
333
+ 'The API key has been used in too many requests in a given amount' \
334
+ ' of time. The following headers will be set in the' \
335
+ ' response: * X-Rate-Limit-Limit - The total number of' \
336
+ ' allowed requests for this period. *' \
337
+ ' X-Rate-Limit-Remaining - The remaining number of' \
338
+ ' requests for this period. * X-Rate-Limit-Reset - The' \
339
+ ' number of seconds left until the end of this period. ',
340
+ _context
341
+ )
342
+ end
343
+ validate_response(_context)
344
+ # Return appropriate response type.
345
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
346
+ DataPerCategoryResponse.from_hash(decoded)
347
+ end
348
+ end
349
+ end