Class: Alula::DeviceCellularHistoryProc

Inherits:
RpcResource show all
Defined in:
lib/alula/procedures/device_cellular_history_proc.rb

Defined Under Namespace

Classes: Response

Constant Summary collapse

ONE_DAY =
86_400

Class Method Summary collapse

Methods inherited from RpcResource

ok?, request, wrap_payload

Class Method Details

.call(device_id:, start_at: nil, stop_at: nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/alula/procedures/device_cellular_history_proc.rb', line 14

def self.call(device_id:, start_at: nil, stop_at: nil)
  # Helpers to set start/stop if only one is passed
  seven_days_in_seconds = Alula::DeviceCellularHistoryProc::ONE_DAY * 7

  stop_at = start_at + seven_days_in_seconds if stop_at.nil?
  start_at = stop_at - seven_days_in_seconds if start_at.nil?

  request(
    http_method: :post,
    path: '/rpc/v1/devices/cellular/history/get',
    payload: {
      deviceId: device_id,
      startAt: start_at.utc.iso8601,
      stopAt: stop_at.utc.iso8601
    },
    handler: Response
  )
end