Class: ERPC::CloudCreditClient

Inherits:
Object
  • Object
show all
Defined in:
lib/erpc_sdk/rest.rb

Constant Summary collapse

ALERT_LEVELS =
%w[critical normal suspended warning].freeze

Instance Method Summary collapse

Constructor Details

#initialize(transport) ⇒ CloudCreditClient

Returns a new instance of CloudCreditClient.



273
274
275
# File 'lib/erpc_sdk/rest.rb', line 273

def initialize(transport)
  @transport = transport
end

Instance Method Details

#getObject



277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/erpc_sdk/rest.rb', line 277

def get
  envelope = Validation.mapping(@transport.get("/v4/cloud/credit"))
  raise InvalidResponseError unless envelope["success"] == true

  credit = Validation.mapping(envelope["message"])
  raise InvalidResponseError unless ALERT_LEVELS.include?(credit["alertLevel"])
  Validation.number(credit["balanceCents"], integer: true)
  Validation.number(credit["burnRateCentsPerHour"], integer: true, nonnegative: true)
  Validation.number(credit["timeToZeroHours"], nonnegative: true) unless credit["timeToZeroHours"].nil?
  Validation.datetime(credit["quoteTimestamp"])
  Validation.datetime(credit["quoteExpiresAt"])
  credit
rescue InvalidResponseError
  raise InvalidResponseError, "ERPC returned an invalid Cloud credit snapshot"
end