test-pack-1 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,63 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ require 'date'
7
+ require 'json'
8
+ require 'faraday'
9
+ require 'certifi'
10
+ require 'logging'
11
+
12
+ require_relative 'test_pack1/api_helper.rb'
13
+ require_relative 'test_pack1/test_pack1_client.rb'
14
+
15
+ # Http
16
+ require_relative 'test_pack1/http/http_call_back.rb'
17
+ require_relative 'test_pack1/http/http_client.rb'
18
+ require_relative 'test_pack1/http/http_method_enum.rb'
19
+ require_relative 'test_pack1/http/http_request.rb'
20
+ require_relative 'test_pack1/http/http_response.rb'
21
+ require_relative 'test_pack1/http/http_context.rb'
22
+ require_relative 'test_pack1/http/faraday_client.rb'
23
+ require_relative 'test_pack1/http/auth/custom_query_auth.rb'
24
+
25
+ # Models
26
+ require_relative 'test_pack1/models/base_model.rb'
27
+ require_relative 'test_pack1/models/data_per_category_response.rb'
28
+ require_relative 'test_pack1/models/device_model.rb'
29
+ require_relative 'test_pack1/models/power_curve_value.rb'
30
+ require_relative 'test_pack1/models/device.rb'
31
+ require_relative 'test_pack1/models/data_real_time_item.rb'
32
+ require_relative 'test_pack1/models/data_signal.rb'
33
+ require_relative 'test_pack1/models/data_item.rb'
34
+ require_relative 'test_pack1/models/status_item.rb'
35
+ require_relative 'test_pack1/models/metadata_field.rb'
36
+ require_relative 'test_pack1/models/site.rb'
37
+ require_relative 'test_pack1/models/configuration_item.rb'
38
+ require_relative 'test_pack1/models/turbine_type.rb'
39
+ require_relative 'test_pack1/models/power_curve.rb'
40
+ require_relative 'test_pack1/models/site_with_data.rb'
41
+ require_relative 'test_pack1/models/data_signal_item.rb'
42
+ require_relative 'test_pack1/models/data_signal_configuration.rb'
43
+ require_relative 'test_pack1/models/data_per_category_item.rb'
44
+ require_relative 'test_pack1/models/client_configuration.rb'
45
+ require_relative 'test_pack1/models/time_zone_configuration.rb'
46
+ require_relative 'test_pack1/models/alert_item.rb'
47
+ require_relative 'test_pack1/models/status_category_enum.rb'
48
+ require_relative 'test_pack1/models/calculation_mode_enum.rb'
49
+ require_relative 'test_pack1/models/aggregate_mode_enum.rb'
50
+ require_relative 'test_pack1/models/resolution_enum.rb'
51
+
52
+ # Exceptions
53
+ require_relative 'test_pack1/exceptions/api_exception.rb'
54
+
55
+ require_relative 'test_pack1/configuration.rb'
56
+
57
+ # Controllers
58
+ require_relative 'test_pack1/controllers/base_controller.rb'
59
+ require_relative 'test_pack1/controllers/statuses_controller.rb'
60
+ require_relative 'test_pack1/controllers/data_controller.rb'
61
+ require_relative 'test_pack1/controllers/alerts_controller.rb'
62
+ require_relative 'test_pack1/controllers/configuration_data_controller.rb'
63
+ require_relative 'test_pack1/controllers/assets_controller.rb'
@@ -0,0 +1,275 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module TestPack1
7
+ # API utility class
8
+ class APIHelper
9
+ # Serializes an array parameter (creates key value pairs).
10
+ # @param [String] The name of the parameter.
11
+ # @param [Array] The value of the parameter.
12
+ # @param [String] The format of the serialization.
13
+ def self.serialize_array(key, array, formatting: 'indexed')
14
+ tuples = []
15
+
16
+ if formatting == 'unindexed'
17
+ tuples += array.map { |element| ["#{key}[]", element] }
18
+ elsif formatting == 'indexed'
19
+ tuples += array.map.with_index do |element, index|
20
+ ["#{key}[#{index}]", element]
21
+ end
22
+ elsif formatting == 'plain'
23
+ tuples += array.map { |element| [key, element] }
24
+ else
25
+ raise ArgumentError, 'Invalid format provided.'
26
+ end
27
+ tuples
28
+ end
29
+
30
+ # Replaces template parameters in the given url.
31
+ # @param [String] The query string builder to replace the template
32
+ # parameters.
33
+ # @param [Hash] The parameters to replace in the url.
34
+ def self.append_url_with_template_parameters(query_builder, parameters)
35
+ # perform parameter validation
36
+ unless query_builder.instance_of? String
37
+ raise ArgumentError, 'Given value for parameter \"query_builder\" is
38
+ invalid.'
39
+ end
40
+
41
+ # Return if there are no parameters to replace.
42
+ return query_builder if parameters.nil?
43
+
44
+ # Iterate and append parameters.
45
+ parameters.each do |key, value|
46
+ replace_value = ''
47
+
48
+ if value.nil?
49
+ replace_value = ''
50
+ elsif value.instance_of? Array
51
+ value.map! { |element| CGI.escape(element.to_s) }
52
+ replace_value = value.join('/')
53
+ else
54
+ replace_value = CGI.escape(value.to_s)
55
+ end
56
+
57
+ # Find the template parameter and replace it with its value.
58
+ query_builder = query_builder.gsub('{' + key.to_s + '}', replace_value)
59
+ end
60
+ query_builder
61
+ end
62
+
63
+ # Appends the given set of parameters to the given query string.
64
+ # @param [String] The query string builder to add the query parameters to.
65
+ # @param [Hash] The parameters to append.
66
+ # @param [String] The format of array parameter serialization.
67
+ def self.append_url_with_query_parameters(query_builder, parameters,
68
+ array_serialization: 'indexed')
69
+ # Perform parameter validation.
70
+ unless query_builder.instance_of? String
71
+ raise ArgumentError, 'Given value for parameter \"query_builder\"
72
+ is invalid.'
73
+ end
74
+
75
+ # Return if there are no parameters to replace.
76
+ return query_builder if parameters.nil?
77
+
78
+ parameters.each do |key, value|
79
+ seperator = query_builder.include?('?') ? '&' : '?'
80
+ unless value.nil?
81
+ if value.instance_of? Array
82
+ value.compact!
83
+ query_builder += if array_serialization == 'csv'
84
+ "#{seperator}#{key}=#{value.map do |element|
85
+ CGI.escape(element.to_s)
86
+ end.join(',')}"
87
+ elsif array_serialization == 'psv'
88
+ "#{seperator}#{key}=#{value.map do |element|
89
+ CGI.escape(element.to_s)
90
+ end.join('|')}"
91
+ elsif array_serialization == 'tsv'
92
+ "#{seperator}#{key}=#{value.map do |element|
93
+ CGI.escape(element.to_s)
94
+ end.join("\t")}"
95
+ else
96
+ "#{seperator}#{APIHelper.serialize_array(
97
+ key, value, formatting: array_serialization
98
+ ).map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }
99
+ .join('&')}"
100
+ end
101
+ else
102
+ query_builder += "#{seperator}#{key}=#{CGI.escape(value.to_s)}"
103
+ end
104
+ end
105
+ end
106
+ query_builder
107
+ end
108
+
109
+ # Validates and processes the given Url.
110
+ # @param [String] The given Url to process.
111
+ # @return [String] Pre-processed Url as string.
112
+ def self.clean_url(url)
113
+ # Perform parameter validation.
114
+ raise ArgumentError, 'Invalid Url.' unless url.instance_of? String
115
+
116
+ # Ensure that the urls are absolute.
117
+ matches = url.match(%r{^(https?:\/\/[^\/]+)})
118
+ raise ArgumentError, 'Invalid Url format.' if matches.nil?
119
+
120
+ # Get the http protocol match.
121
+ protocol = matches[1]
122
+
123
+ # Check if parameters exist.
124
+ index = url.index('?')
125
+
126
+ # Remove redundant forward slashes.
127
+ query = url[protocol.length...(!index.nil? ? index : url.length)]
128
+ query.gsub!(%r{\/\/+}, '/')
129
+
130
+ # Get the parameters.
131
+ parameters = !index.nil? ? url[url.index('?')...url.length] : ''
132
+
133
+ # Return processed url.
134
+ protocol + query + parameters
135
+ end
136
+
137
+ # Parses JSON string.
138
+ # @param [String] A JSON string.
139
+ def self.json_deserialize(json)
140
+ return JSON.parse(json)
141
+ rescue StandardError
142
+ raise TypeError, 'Server responded with invalid JSON.'
143
+ end
144
+
145
+ # Removes elements with empty values from a hash.
146
+ # @param [Hash] The hash to clean.
147
+ def self.clean_hash(hash)
148
+ hash.delete_if { |_key, value| value.to_s.strip.empty? }
149
+ end
150
+
151
+ # Form encodes a hash of parameters.
152
+ # @param [Hash] The hash of parameters to encode.
153
+ # @return [Hash] A hash with the same parameters form encoded.
154
+ def self.form_encode_parameters(form_parameters)
155
+ encoded = {}
156
+ form_parameters.each do |key, value|
157
+ encoded.merge!(APIHelper.form_encode(value, key, formatting:
158
+ Configuration.array_serialization))
159
+ end
160
+ encoded
161
+ end
162
+
163
+ def self.custom_merge(a, b)
164
+ x = {}
165
+ a.each do |key, value_a|
166
+ b.each do |k, value_b|
167
+ next unless key == k
168
+ x[k] = []
169
+ if value_a.instance_of? Array
170
+ value_a.each do |v|
171
+ x[k].push(v)
172
+ end
173
+ else
174
+ x[k].push(value_a)
175
+ end
176
+ if value_b.instance_of? Array
177
+ value_b.each do |v|
178
+ x[k].push(v)
179
+ end
180
+ else
181
+ x[k].push(value_b)
182
+ end
183
+ a.delete(k)
184
+ b.delete(k)
185
+ end
186
+ end
187
+ x.merge!(a)
188
+ x.merge!(b)
189
+ x
190
+ end
191
+
192
+ # Form encodes an object.
193
+ # @param [Dynamic] An object to form encode.
194
+ # @param [String] The name of the object.
195
+ # @return [Hash] A form encoded representation of the object in the form
196
+ # of a hash.
197
+ def self.form_encode(obj, instance_name, formatting: 'indexed')
198
+ retval = {}
199
+
200
+ serializable_types = [String, Numeric, TrueClass,
201
+ FalseClass, Date, DateTime]
202
+
203
+ # If this is a structure, resolve it's field names.
204
+ obj = obj.to_hash if obj.is_a? BaseModel
205
+
206
+ # Create a form encoded hash for this object.
207
+ if obj.nil?
208
+ nil
209
+ elsif obj.instance_of? Array
210
+ if formatting == 'indexed'
211
+ obj.each_with_index do |value, index|
212
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
213
+ index.to_s + ']'))
214
+ end
215
+ elsif serializable_types.map { |x| obj[0].is_a? x }.any?
216
+ obj.each do |value|
217
+ abc = if formatting == 'unindexed'
218
+ APIHelper.form_encode(value, instance_name + '[]',
219
+ formatting: formatting)
220
+ else
221
+ APIHelper.form_encode(value, instance_name,
222
+ formatting: formatting)
223
+ end
224
+ retval = APIHelper.custom_merge(retval, abc)
225
+ # print retval
226
+ end
227
+ else
228
+ obj.each_with_index do |value, index|
229
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
230
+ index.to_s + ']', formatting: formatting))
231
+ end
232
+ end
233
+ elsif obj.instance_of? Hash
234
+ obj.each do |key, value|
235
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
236
+ key + ']', formatting: formatting))
237
+ end
238
+ else
239
+ retval[instance_name] = obj
240
+ end
241
+ retval
242
+ end
243
+
244
+ # Safely converts a string into an rfc3339 DateTime object
245
+ # @param [String] The datetime string
246
+ # @return [DateTime] A DateTime object of rfc3339 format
247
+ def self.rfc3339(date_time)
248
+ # missing timezone information
249
+ if date_time.end_with?('Z') || date_time.index('+')
250
+ DateTime.rfc3339(date_time)
251
+ else
252
+ DateTime.rfc3339(date_time + 'Z')
253
+ end
254
+ end
255
+ end
256
+ end
257
+
258
+ # Extend types to support to_bool.
259
+ module ToBoolean
260
+ def to_bool
261
+ return true if self == true || to_s.strip =~ /^(true|yes|y|1)$/i
262
+ false
263
+ end
264
+ end
265
+
266
+ # Extend NilClass type to support to_bool.
267
+ class NilClass; include ToBoolean; end
268
+ # Extend TrueClass type to support to_bool.
269
+ class TrueClass; include ToBoolean; end
270
+ # Extend FalseClass type to support to_bool.
271
+ class FalseClass; include ToBoolean; end
272
+ # Extend Numeric type to support to_bool.
273
+ class Numeric; include ToBoolean; end
274
+ # Extend String type to support to_bool.
275
+ class String; include ToBoolean; end
@@ -0,0 +1,63 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ # CohesityManagementSdk
7
+ module TestPack1
8
+ # All configuration including auth info and base URI for the API access
9
+ # are configured in this class.
10
+ class Configuration
11
+ # Set the array parameter serialization method.
12
+ # (allowed: indexed, unindexed, plain, csv, tsv, psv)
13
+ @array_serialization = 'indexed'
14
+
15
+ # An enum for SDK environments.
16
+ class Environment
17
+ #PRODUCTION: The Greenbyte API for a specific customer
18
+ ENVIRONMENT = [PRODUCTION = 0].freeze
19
+ end
20
+
21
+ # An enum for API servers.
22
+ class Server
23
+ SERVER = [DEFAULT = 0].freeze
24
+ end
25
+
26
+ # The environment in which the SDK is running.
27
+ @environment = Environment::PRODUCTION
28
+
29
+ # TODO: Set an appropriate value.
30
+ @customer = 'intro'
31
+
32
+ @api_token = 'TODO: Replace'
33
+
34
+ # All the environments the SDK can run in.
35
+ @environments = {
36
+ Environment::PRODUCTION => {
37
+ Server::DEFAULT => 'https://{customer}.greenbyte.cloud/api/2.0'
38
+ }
39
+ }
40
+
41
+ # Generates the appropriate base URI for the environment and the server.
42
+ # @param [Configuration::Server] The server enum for which the base URI is
43
+ # required.
44
+ # @return [String] The base URI.
45
+ def self.get_base_uri(server = Server::DEFAULT)
46
+ parameters = {
47
+ 'customer' => customer
48
+ }
49
+ APIHelper.append_url_with_template_parameters(
50
+ environments[environment][server], parameters
51
+ )
52
+ end
53
+
54
+ # The attribute accessors for public properties.
55
+ class << self
56
+ attr_accessor :array_serialization
57
+ attr_accessor :environment
58
+ attr_accessor :environments
59
+ attr_accessor :customer
60
+ attr_accessor :api_token
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,381 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module TestPack1
7
+ # AlertsController
8
+ class AlertsController < BaseController
9
+ @instance = AlertsController.new
10
+
11
+ class << self
12
+ attr_accessor :instance
13
+ end
14
+
15
+ def instance
16
+ self.class.instance
17
+ end
18
+
19
+ # _This endpoint is deprecated. Please use the new endpoint
20
+ # `/activealerts.json` instead._
21
+ # @param [List of Integer] device_ids Required parameter: What devices to
22
+ # get alerts for.
23
+ # @param [List of String] fields Optional parameter: Which fields to include
24
+ # in the response. Valid fields are those defined in the `AlertItem` schema.
25
+ # By default all fields are included.
26
+ # @param [List of String] sort_by Optional parameter: Which fields to sort
27
+ # the response items by. By default the items are sorted by
28
+ # timestampStart.
29
+ # @param [Boolean] sort_asc Optional parameter: Whether to sort the items in
30
+ # ascending order.
31
+ # @param [Integer] page_size Optional parameter: The number of items to
32
+ # return per page.
33
+ # @param [Integer] page Optional parameter: Which page to return when the
34
+ # number of items exceed the page size.
35
+ # @return List of AlertItem response from the API call
36
+ def get_active_alarms(device_ids,
37
+ fields = nil,
38
+ sort_by = nil,
39
+ sort_asc = false,
40
+ page_size = 50,
41
+ page = 1)
42
+ # Prepare query url.
43
+ _path_url = '/activealarms.json'
44
+ _query_builder = Configuration.get_base_uri
45
+ _query_builder << _path_url
46
+ _query_builder = APIHelper.append_url_with_query_parameters(
47
+ _query_builder,
48
+ {
49
+ 'deviceIds' => device_ids,
50
+ 'fields' => fields,
51
+ 'sortBy' => sort_by,
52
+ 'sortAsc' => sort_asc,
53
+ 'pageSize' => page_size,
54
+ 'page' => page
55
+ },
56
+ array_serialization: Configuration.array_serialization
57
+ )
58
+ _query_url = APIHelper.clean_url _query_builder
59
+ # Prepare headers.
60
+ _headers = {
61
+ 'accept' => 'application/json'
62
+ }
63
+ # Prepare and execute HttpRequest.
64
+ _request = @http_client.get(
65
+ _query_url,
66
+ headers: _headers
67
+ )
68
+ CustomQueryAuth.apply(_request)
69
+ _context = execute_request(_request)
70
+ # Validate response against endpoint and global error codes.
71
+ if _context.response.status_code == 400
72
+ raise APIException.new(
73
+ 'The request cannot be fulfilled due to bad syntax.',
74
+ _context
75
+ )
76
+ elsif _context.response.status_code == 401
77
+ raise APIException.new(
78
+ 'One of the following: * The request is missing a valid API key. *' \
79
+ ' The API key does not authorize access the requested' \
80
+ ' data. Devices or data signals can be limited. ',
81
+ _context
82
+ )
83
+ elsif _context.response.status_code == 405
84
+ raise APIException.new(
85
+ 'The HTTP method is not allowed for the endpoint.',
86
+ _context
87
+ )
88
+ elsif _context.response.status_code == 429
89
+ raise APIException.new(
90
+ 'The API key has been used in too many requests in a given amount' \
91
+ ' of time. The following headers will be set in the' \
92
+ ' response: * X-Rate-Limit-Limit - The total number of' \
93
+ ' allowed requests for this period. *' \
94
+ ' X-Rate-Limit-Remaining - The remaining number of' \
95
+ ' requests for this period. * X-Rate-Limit-Reset - The' \
96
+ ' number of seconds left until the end of this period. ',
97
+ _context
98
+ )
99
+ end
100
+ validate_response(_context)
101
+ # Return appropriate response type.
102
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
103
+ decoded.map { |element| AlertItem.from_hash(element) }
104
+ end
105
+
106
+ # Gets active alerts for multiple devices.
107
+ # @param [List of Integer] device_ids Required parameter: What devices to
108
+ # get alerts for.
109
+ # @param [List of String] fields Optional parameter: Which fields to include
110
+ # in the response. Valid fields are those defined in the `AlertItem` schema.
111
+ # By default all fields are included.
112
+ # @param [List of String] sort_by Optional parameter: Which fields to sort
113
+ # the response items by. By default the items are sorted by
114
+ # timestampStart.
115
+ # @param [Boolean] sort_asc Optional parameter: Whether to sort the items in
116
+ # ascending order.
117
+ # @param [Integer] page_size Optional parameter: The number of items to
118
+ # return per page.
119
+ # @param [Integer] page Optional parameter: Which page to return when the
120
+ # number of items exceed the page size.
121
+ # @return List of AlertItem response from the API call
122
+ def get_active_alerts(device_ids,
123
+ fields = nil,
124
+ sort_by = nil,
125
+ sort_asc = false,
126
+ page_size = 50,
127
+ page = 1)
128
+ # Prepare query url.
129
+ _path_url = '/activealerts.json'
130
+ _query_builder = Configuration.get_base_uri
131
+ _query_builder << _path_url
132
+ _query_builder = APIHelper.append_url_with_query_parameters(
133
+ _query_builder,
134
+ {
135
+ 'deviceIds' => device_ids,
136
+ 'fields' => fields,
137
+ 'sortBy' => sort_by,
138
+ 'sortAsc' => sort_asc,
139
+ 'pageSize' => page_size,
140
+ 'page' => page
141
+ },
142
+ array_serialization: Configuration.array_serialization
143
+ )
144
+ _query_url = APIHelper.clean_url _query_builder
145
+ # Prepare headers.
146
+ _headers = {
147
+ 'accept' => 'application/json'
148
+ }
149
+ # Prepare and execute HttpRequest.
150
+ _request = @http_client.get(
151
+ _query_url,
152
+ headers: _headers
153
+ )
154
+ CustomQueryAuth.apply(_request)
155
+ _context = execute_request(_request)
156
+ # Validate response against endpoint and global error codes.
157
+ if _context.response.status_code == 400
158
+ raise APIException.new(
159
+ 'The request cannot be fulfilled due to bad syntax.',
160
+ _context
161
+ )
162
+ elsif _context.response.status_code == 401
163
+ raise APIException.new(
164
+ 'One of the following: * The request is missing a valid API key. *' \
165
+ ' The API key does not authorize access the requested' \
166
+ ' data. Devices or data signals can be limited. ',
167
+ _context
168
+ )
169
+ elsif _context.response.status_code == 405
170
+ raise APIException.new(
171
+ 'The HTTP method is not allowed for the endpoint.',
172
+ _context
173
+ )
174
+ elsif _context.response.status_code == 429
175
+ raise APIException.new(
176
+ 'The API key has been used in too many requests in a given amount' \
177
+ ' of time. The following headers will be set in the' \
178
+ ' response: * X-Rate-Limit-Limit - The total number of' \
179
+ ' allowed requests for this period. *' \
180
+ ' X-Rate-Limit-Remaining - The remaining number of' \
181
+ ' requests for this period. * X-Rate-Limit-Reset - The' \
182
+ ' number of seconds left until the end of this period. ',
183
+ _context
184
+ )
185
+ end
186
+ validate_response(_context)
187
+ # Return appropriate response type.
188
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
189
+ decoded.map { |element| AlertItem.from_hash(element) }
190
+ end
191
+
192
+ # Gets alerts for multiple devices and the given time period.
193
+ # @param [List of Integer] device_ids Required parameter: What devices to
194
+ # get alerts for.
195
+ # @param [DateTime] timestamp_start Required parameter: The first timestamp
196
+ # to get data for.
197
+ # @param [DateTime] timestamp_end Required parameter: The last timestamp to
198
+ # get data for.
199
+ # @param [List of String] fields Optional parameter: Which fields to include
200
+ # in the response. Valid fields are those defined in the `AlertItem` schema.
201
+ # By default all fields are included.
202
+ # @param [List of String] sort_by Optional parameter: Which fields to sort
203
+ # the response items by. By default the items are sorted by
204
+ # timestampStart.
205
+ # @param [Boolean] sort_asc Optional parameter: Whether to sort the items in
206
+ # ascending order.
207
+ # @param [Integer] page_size Optional parameter: The number of items to
208
+ # return per page.
209
+ # @param [Integer] page Optional parameter: Which page to return when the
210
+ # number of items exceed the page size.
211
+ # @return List of AlertItem response from the API call
212
+ def get_alerts(device_ids,
213
+ timestamp_start,
214
+ timestamp_end,
215
+ fields = nil,
216
+ sort_by = nil,
217
+ sort_asc = false,
218
+ page_size = 50,
219
+ page = 1)
220
+ # Prepare query url.
221
+ _path_url = '/alerts.json'
222
+ _query_builder = Configuration.get_base_uri
223
+ _query_builder << _path_url
224
+ _query_builder = APIHelper.append_url_with_query_parameters(
225
+ _query_builder,
226
+ {
227
+ 'deviceIds' => device_ids,
228
+ 'timestampStart' => timestamp_start,
229
+ 'timestampEnd' => timestamp_end,
230
+ 'fields' => fields,
231
+ 'sortBy' => sort_by,
232
+ 'sortAsc' => sort_asc,
233
+ 'pageSize' => page_size,
234
+ 'page' => page
235
+ },
236
+ array_serialization: Configuration.array_serialization
237
+ )
238
+ _query_url = APIHelper.clean_url _query_builder
239
+ # Prepare headers.
240
+ _headers = {
241
+ 'accept' => 'application/json'
242
+ }
243
+ # Prepare and execute HttpRequest.
244
+ _request = @http_client.get(
245
+ _query_url,
246
+ headers: _headers
247
+ )
248
+ CustomQueryAuth.apply(_request)
249
+ _context = execute_request(_request)
250
+ # Validate response against endpoint and global error codes.
251
+ if _context.response.status_code == 400
252
+ raise APIException.new(
253
+ 'The request cannot be fulfilled due to bad syntax.',
254
+ _context
255
+ )
256
+ elsif _context.response.status_code == 401
257
+ raise APIException.new(
258
+ 'One of the following: * The request is missing a valid API key. *' \
259
+ ' The API key does not authorize access the requested' \
260
+ ' data. Devices or data signals can be limited. ',
261
+ _context
262
+ )
263
+ elsif _context.response.status_code == 405
264
+ raise APIException.new(
265
+ 'The HTTP method is not allowed for the endpoint.',
266
+ _context
267
+ )
268
+ elsif _context.response.status_code == 429
269
+ raise APIException.new(
270
+ 'The API key has been used in too many requests in a given amount' \
271
+ ' of time. The following headers will be set in the' \
272
+ ' response: * X-Rate-Limit-Limit - The total number of' \
273
+ ' allowed requests for this period. *' \
274
+ ' X-Rate-Limit-Remaining - The remaining number of' \
275
+ ' requests for this period. * X-Rate-Limit-Reset - The' \
276
+ ' number of seconds left until the end of this period. ',
277
+ _context
278
+ )
279
+ end
280
+ validate_response(_context)
281
+ # Return appropriate response type.
282
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
283
+ decoded.map { |element| AlertItem.from_hash(element) }
284
+ end
285
+
286
+ # _This endpoint is deprecated. Please use the new endpoint `/alerts.json`
287
+ # instead._
288
+ # @param [List of Integer] device_ids Required parameter: What devices to
289
+ # get alerts for.
290
+ # @param [DateTime] timestamp_start Required parameter: The first timestamp
291
+ # to get data for.
292
+ # @param [DateTime] timestamp_end Required parameter: The last timestamp to
293
+ # get data for.
294
+ # @param [List of String] fields Optional parameter: Which fields to include
295
+ # in the response. Valid fields are those defined in the `AlertItem` schema.
296
+ # By default all fields are included.
297
+ # @param [List of String] sort_by Optional parameter: Which fields to sort
298
+ # the response items by. By default the items are sorted by
299
+ # timestampStart.
300
+ # @param [Boolean] sort_asc Optional parameter: Whether to sort the items in
301
+ # ascending order.
302
+ # @param [Integer] page_size Optional parameter: The number of items to
303
+ # return per page.
304
+ # @param [Integer] page Optional parameter: Which page to return when the
305
+ # number of items exceed the page size.
306
+ # @return List of AlertItem response from the API call
307
+ def get_alarms(device_ids,
308
+ timestamp_start,
309
+ timestamp_end,
310
+ fields = nil,
311
+ sort_by = nil,
312
+ sort_asc = false,
313
+ page_size = 50,
314
+ page = 1)
315
+ # Prepare query url.
316
+ _path_url = '/alarms.json'
317
+ _query_builder = Configuration.get_base_uri
318
+ _query_builder << _path_url
319
+ _query_builder = APIHelper.append_url_with_query_parameters(
320
+ _query_builder,
321
+ {
322
+ 'deviceIds' => device_ids,
323
+ 'timestampStart' => timestamp_start,
324
+ 'timestampEnd' => timestamp_end,
325
+ 'fields' => fields,
326
+ 'sortBy' => sort_by,
327
+ 'sortAsc' => sort_asc,
328
+ 'pageSize' => page_size,
329
+ 'page' => page
330
+ },
331
+ array_serialization: Configuration.array_serialization
332
+ )
333
+ _query_url = APIHelper.clean_url _query_builder
334
+ # Prepare headers.
335
+ _headers = {
336
+ 'accept' => 'application/json'
337
+ }
338
+ # Prepare and execute HttpRequest.
339
+ _request = @http_client.get(
340
+ _query_url,
341
+ headers: _headers
342
+ )
343
+ CustomQueryAuth.apply(_request)
344
+ _context = execute_request(_request)
345
+ # Validate response against endpoint and global error codes.
346
+ if _context.response.status_code == 400
347
+ raise APIException.new(
348
+ 'The request cannot be fulfilled due to bad syntax.',
349
+ _context
350
+ )
351
+ elsif _context.response.status_code == 401
352
+ raise APIException.new(
353
+ 'One of the following: * The request is missing a valid API key. *' \
354
+ ' The API key does not authorize access the requested' \
355
+ ' data. Devices or data signals can be limited. ',
356
+ _context
357
+ )
358
+ elsif _context.response.status_code == 405
359
+ raise APIException.new(
360
+ 'The HTTP method is not allowed for the endpoint.',
361
+ _context
362
+ )
363
+ elsif _context.response.status_code == 429
364
+ raise APIException.new(
365
+ 'The API key has been used in too many requests in a given amount' \
366
+ ' of time. The following headers will be set in the' \
367
+ ' response: * X-Rate-Limit-Limit - The total number of' \
368
+ ' allowed requests for this period. *' \
369
+ ' X-Rate-Limit-Remaining - The remaining number of' \
370
+ ' requests for this period. * X-Rate-Limit-Reset - The' \
371
+ ' number of seconds left until the end of this period. ',
372
+ _context
373
+ )
374
+ end
375
+ validate_response(_context)
376
+ # Return appropriate response type.
377
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
378
+ decoded.map { |element| AlertItem.from_hash(element) }
379
+ end
380
+ end
381
+ end