Class: OkComputer::NexmoCheck

Inherits:
Check
  • Object
show all
Defined in:
lib/ok_computer/checks/nexmo_check.rb

Constant Summary collapse

AccountError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client: nil, api_key: nil, api_secret: nil, signature_secret: nil) ⇒ NexmoCheck

rubocop:disable Lint/MissingSuper



11
12
13
14
15
16
17
18
19
# File 'lib/ok_computer/checks/nexmo_check.rb', line 11

def initialize(client: nil, api_key: nil, api_secret: nil, signature_secret: nil) # rubocop:disable Lint/MissingSuper
  client ||= Nexmo::Client.new(
    api_key: api_key,
    api_secret: api_secret,
    signature_secret: signature_secret,
  )

  self.client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



9
10
11
# File 'lib/ok_computer/checks/nexmo_check.rb', line 9

def client
  @client
end

Instance Method Details

#checkObject

Public: Return the status of the Account Balance check



22
23
24
25
26
27
28
29
30
# File 'lib/ok_computer/checks/nexmo_check.rb', line 22

def check
  response = perform_request
  return mark_failure unless response.http_response.code.to_i == 200

  mark_message("Balance #{response.value} check successful")
rescue StandardError => e
  mark_message("Error: '#{e}'")
  mark_failure
end

#perform_requestObject



32
33
34
35
36
# File 'lib/ok_computer/checks/nexmo_check.rb', line 32

def perform_request
  client..balance
rescue StandardError => e
  raise(AccountError, e)
end