Skip to content

Commit

Permalink
Added in get_service_history method and refactored the get_rated_disa…
Browse files Browse the repository at this point in the history
…bilities to use common methods to eliminate redundancy
  • Loading branch information
micahaspyr committed Apr 22, 2024
1 parent 776ceca commit eeeb3a8
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions lib/lighthouse/veteran_verification/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,31 @@ class Service < Common::Client::Base
# @option options [string] :aud_claim_url option to override the aud_claim_url for LH Veteran Verification APIs
# @option options [hash] :auth_params a hash to send in auth params to create the access token
# @option options [string] :host a base host for the Lighthouse API call
def get_rated_disabilities(icn, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, options = {})
endpoint = 'disability_rating'
config
.get(
"#{endpoint}/#{icn}",
def get_rated_disabilities(icn, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, options = {})
process_request('disability_rating', icn, lighthouse_client_id, lighthouse_rsa_key_path, options)
rescue => e
handle_error(e, lighthouse_client_id, 'disability_rating')
end

def get_service_history(icn, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, options = {})
process_request('service_history', icn, lighthouse_client_id, lighthouse_rsa_key_path, options)
rescue => e
handle_error(e, lighthouse_client_id, 'service_history')
end

private

def process_request(endpoint, icn, lighthouse_client_id, lighthouse_rsa_key_path, options)
config.get(endpoint + '/' + icn.to_s, lighthouse_client_id, lighthouse_rsa_key_path, options).body
end

def handle_error(error, lighthouse_client_id, endpoint)
Lighthouse::ServiceException.send_error(
error,
self.class.to_s.underscore,
lighthouse_client_id,
lighthouse_rsa_key_path,
options
"#{config.base_api_path}/#{endpoint}"
)
.body
rescue => e
handle_error(e, lighthouse_client_id, endpoint)
end

def handle_error(error, lighthouse_client_id, endpoint)
Lighthouse::ServiceException.send_error(
error,
self.class.to_s.underscore,
lighthouse_client_id,
"#{config.base_api_path}/#{endpoint}"
)
end
end
end
end

0 comments on commit eeeb3a8

Please sign in to comment.