Class: TestPack1::AlertsController

Inherits:
BaseController show all
Defined in:
lib/test_pack_1/controllers/alerts_controller.rb

Overview

AlertsController

Class Attribute Summary collapse

Attributes inherited from BaseController

#http_call_back, #http_client

Instance Method Summary collapse

Methods inherited from BaseController

#execute_request, #initialize, #validate_parameters, #validate_response

Constructor Details

This class inherits a constructor from TestPack1::BaseController

Class Attribute Details

.instanceObject

Returns the value of attribute instance.



12
13
14
# File 'lib/test_pack_1/controllers/alerts_controller.rb', line 12

def instance
  @instance
end

Instance Method Details

#get_active_alarms(device_ids, fields = nil, sort_by = nil, sort_asc = false, page_size = 50, page = 1) ⇒ Object

_This endpoint is deprecated. Please use the new endpoint ‘/activealerts.json` instead._ get alerts for. in the response. Valid fields are those defined in the `AlertItem` 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.

Parameters:

  • device_ids (List of Integer)

    Required parameter: What devices to

  • fields (List of String) (defaults to: nil)

    Optional parameter: Which fields to include

  • sort_by (List of String) (defaults to: nil)

    Optional parameter: Which fields to sort

  • sort_asc (Boolean) (defaults to: false)

    Optional parameter: Whether to sort the items in

  • page_size (Integer) (defaults to: 50)

    Optional parameter: The number of items to

  • page (Integer) (defaults to: 1)

    Optional parameter: Which page to return when the

Returns:

  • List of AlertItem response from the API call



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
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
# File 'lib/test_pack_1/controllers/alerts_controller.rb', line 36

def get_active_alarms(device_ids,
                      fields = nil,
                      sort_by = nil,
                      sort_asc = false,
                      page_size = 50,
                      page = 1)
  # Prepare query url.
  _path_url = '/activealarms.json'
  _query_builder = Configuration.get_base_uri
  _query_builder << _path_url
  _query_builder = APIHelper.append_url_with_query_parameters(
    _query_builder,
    {
      'deviceIds' => device_ids,
      '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| AlertItem.from_hash(element) }
end

#get_active_alerts(device_ids, fields = nil, sort_by = nil, sort_asc = false, page_size = 50, page = 1) ⇒ Object

Gets active alerts for multiple devices. get alerts for. in the response. Valid fields are those defined in the ‘AlertItem` 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.

Parameters:

  • device_ids (List of Integer)

    Required parameter: What devices to

  • fields (List of String) (defaults to: nil)

    Optional parameter: Which fields to include

  • sort_by (List of String) (defaults to: nil)

    Optional parameter: Which fields to sort

  • sort_asc (Boolean) (defaults to: false)

    Optional parameter: Whether to sort the items in

  • page_size (Integer) (defaults to: 50)

    Optional parameter: The number of items to

  • page (Integer) (defaults to: 1)

    Optional parameter: Which page to return when the

Returns:

  • List of AlertItem response from the API call



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
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
# File 'lib/test_pack_1/controllers/alerts_controller.rb', line 122

def get_active_alerts(device_ids,
                      fields = nil,
                      sort_by = nil,
                      sort_asc = false,
                      page_size = 50,
                      page = 1)
  # Prepare query url.
  _path_url = '/activealerts.json'
  _query_builder = Configuration.get_base_uri
  _query_builder << _path_url
  _query_builder = APIHelper.append_url_with_query_parameters(
    _query_builder,
    {
      'deviceIds' => device_ids,
      '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| AlertItem.from_hash(element) }
end

#get_alarms(device_ids, timestamp_start, timestamp_end, fields = nil, sort_by = nil, sort_asc = false, page_size = 50, page = 1) ⇒ Object

_This endpoint is deprecated. Please use the new endpoint ‘/alerts.json` instead._ get alerts for. to get data for. get data for. in the response. Valid fields are those defined in the `AlertItem` 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.

Parameters:

  • device_ids (List of Integer)

    Required parameter: What devices to

  • timestamp_start (DateTime)

    Required parameter: The first timestamp

  • timestamp_end (DateTime)

    Required parameter: The last timestamp to

  • fields (List of String) (defaults to: nil)

    Optional parameter: Which fields to include

  • sort_by (List of String) (defaults to: nil)

    Optional parameter: Which fields to sort

  • sort_asc (Boolean) (defaults to: false)

    Optional parameter: Whether to sort the items in

  • page_size (Integer) (defaults to: 50)

    Optional parameter: The number of items to

  • page (Integer) (defaults to: 1)

    Optional parameter: Which page to return when the

Returns:

  • List of AlertItem response from the API call



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/test_pack_1/controllers/alerts_controller.rb', line 307

def get_alarms(device_ids,
               timestamp_start,
               timestamp_end,
               fields = nil,
               sort_by = nil,
               sort_asc = false,
               page_size = 50,
               page = 1)
  # Prepare query url.
  _path_url = '/alarms.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' => timestamp_start,
      'timestampEnd' => timestamp_end,
      '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| AlertItem.from_hash(element) }
end

#get_alerts(device_ids, timestamp_start, timestamp_end, fields = nil, sort_by = nil, sort_asc = false, page_size = 50, page = 1) ⇒ Object

Gets alerts for multiple devices and the given time period. get alerts for. to get data for. get data for. in the response. Valid fields are those defined in the ‘AlertItem` 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.

Parameters:

  • device_ids (List of Integer)

    Required parameter: What devices to

  • timestamp_start (DateTime)

    Required parameter: The first timestamp

  • timestamp_end (DateTime)

    Required parameter: The last timestamp to

  • fields (List of String) (defaults to: nil)

    Optional parameter: Which fields to include

  • sort_by (List of String) (defaults to: nil)

    Optional parameter: Which fields to sort

  • sort_asc (Boolean) (defaults to: false)

    Optional parameter: Whether to sort the items in

  • page_size (Integer) (defaults to: 50)

    Optional parameter: The number of items to

  • page (Integer) (defaults to: 1)

    Optional parameter: Which page to return when the

Returns:

  • List of AlertItem response from the API call



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/test_pack_1/controllers/alerts_controller.rb', line 212

def get_alerts(device_ids,
               timestamp_start,
               timestamp_end,
               fields = nil,
               sort_by = nil,
               sort_asc = false,
               page_size = 50,
               page = 1)
  # Prepare query url.
  _path_url = '/alerts.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' => timestamp_start,
      'timestampEnd' => timestamp_end,
      '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| AlertItem.from_hash(element) }
end

#instanceObject



15
16
17
# File 'lib/test_pack_1/controllers/alerts_controller.rb', line 15

def instance
  self.class.instance
end