Class: DirectDeposit::Client

Inherits:
Common::Client::Base show all
Defined in:
lib/lighthouse/direct_deposit/client.rb

Constant Summary collapse

STATSD_KEY_PREFIX =
'api.direct_deposit'

Instance Method Summary collapse

Methods inherited from Common::Client::Base

#config, configuration, #connection, #delete, #get, #perform, #post, #put, #raise_backend_exception, #raise_not_authenticated, #request, #sanitize_headers!, #service_name

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata

Constructor Details

#initialize(icn) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


13
14
15
16
17
18
# File 'lib/lighthouse/direct_deposit/client.rb', line 13

def initialize(icn)
  @icn = icn
  raise ArgumentError, 'no ICN passed in for Lighthouse API request.' if icn.blank?

  super()
end

Instance Method Details

#build_request_body(payment_account) ⇒ Object (private)



55
56
57
58
59
60
61
62
63
64
# File 'lib/lighthouse/direct_deposit/client.rb', line 55

def build_request_body()
  {
    'paymentAccount' =>
    {
      'accountNumber' => .,
      'accountType' => .,
      'financialInstitutionRoutingNumber' => .routing_number
    }
  }.to_json
end

#get_payment_infoObject



20
21
22
23
24
25
26
27
# File 'lib/lighthouse/direct_deposit/client.rb', line 20

def get_payment_info
  response = config.get("?icn=#{@icn}")
  handle_response(response)
rescue Timeout::Error, Faraday::TimeoutError => e
  raise Common::Exceptions::GatewayTimeout, e.class.name
rescue Faraday::ClientError, Faraday::ServerError => e
  handle_error(e, config.settings.client_id, config.base_path)
end

#handle_error(error, lighthouse_client_id, base_path) ⇒ Object (private)



46
47
48
49
50
51
52
53
# File 'lib/lighthouse/direct_deposit/client.rb', line 46

def handle_error(error, lighthouse_client_id, base_path)
  Lighthouse::ServiceException.send_error(
    error,
    self.class.to_s.underscore,
    lighthouse_client_id,
    base_path
  )
end

#handle_response(response) ⇒ Object (private)



42
43
44
# File 'lib/lighthouse/direct_deposit/client.rb', line 42

def handle_response(response)
  Lighthouse::DirectDeposit::PaymentInfoParser.parse(response)
end

#update_payment_info(params) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/lighthouse/direct_deposit/client.rb', line 29

def update_payment_info(params)
  body = build_request_body(params)

  response = config.put("?icn=#{@icn}", body)
  handle_response(response)
rescue Timeout::Error, Faraday::TimeoutError => e
  raise Common::Exceptions::GatewayTimeout, e.class.name
rescue Faraday::ClientError, Faraday::ServerError => e
  handle_error(e, config.settings.client_id, config.base_path)
end