class ChangeHealthcare::ProfessionalClaims::Wrapper
Wrapper
module, wraps the auto-generated swagger code in a slightly nicer-to-use format.
This is a semi-stateful, thread-safe wrapper. It will get auth tokens for you when needed.
Constants
- AuthToken
Struct used to store auth tokens so we don't need to fetch one every request.
Public Class Methods
# File lib/change_healthcare/professional_claims/wrapper.rb, line 15 def initialize(client_id:, client_secret:) @client_id = client_id @client_secret = client_secret @api = SwaggerClient::ProfessionalClaimsApi.new # fake auth token that is expired @auth_token = AuthToken.new('', Time.at(0)) @mutex = Mutex.new end
Public Instance Methods
Obtain a valid authentication token. This method may request a new token if the in-use token is expired. It will do this in a thread-safe manner.
@raise [ChangeHealthcare::ProfessionalClaims::Wrapper::BadAuthRequestError] if we couldn't auth due to a bug @raise [ChangeHealthcare::ProfessionalClaims::Wrapper::BadAuthorizationError] if we couldn't auth due to bad creds @raise [ChangeHealthcare::ProfessionalClaims::Wrapper::UnknownAuthError] if something really weird happens
# File lib/change_healthcare/professional_claims/wrapper.rb, line 84 def auth_token @mutex.synchronize do fetch_new_token! unless @auth_token.valid? @auth_token end end
Check health of the API
@return [ChangeHealthcare::ProfessionalClaims::SwaggerClient::HealthCheck]
# File lib/change_healthcare/professional_claims/wrapper.rb, line 58 def health_check @api.health_check_using_get(auth_token.auth) end
Submits a claim to the payer.
@param request [ChangeHealthcare::ProfessionalClaims::SwaggerClient::ClaimSubmissionRequest] the request to send @param opts [Hash] client options
@raise [ChangeHealthcare::ProfessionalClaims::Wrapper::BadAuthRequestError] if we couldn't auth due to a bug @raise [ChangeHealthcare::ProfessionalClaims::Wrapper::BadAuthorizationError] if we couldn't auth due to bad creds @raise [ChangeHealthcare::ProfessionalClaims::Wrapper::UnknownAuthError] if something really weird happens
@return [ChangeHealthcare::ProfessionalClaims::SwaggerClient::Response] the response from change
# File lib/change_healthcare/professional_claims/wrapper.rb, line 35 def process_claim(request, opts = {}) @api.process_claim_using_post(auth_token.auth, request, opts) end
Validate the syntax of a claim without submitting it to the payor.
@param request [ChangeHealthcare::ProfessionalClaims::SwaggerClient::ClaimSubmissionRequest] the request to send @param opts [Hash] client options
@raise [ChangeHealthcare::ProfessionalClaims::Wrapper::BadAuthRequestError] if we couldn't auth due to a bug @raise [ChangeHealthcare::ProfessionalClaims::Wrapper::BadAuthorizationError] if we couldn't auth due to bad creds @raise [ChangeHealthcare::ProfessionalClaims::Wrapper::UnknownAuthError] if something really weird happens
@return [ChangeHealthcare::ProfessionalClaims::SwaggerClient::Response] the response from change
# File lib/change_healthcare/professional_claims/wrapper.rb, line 50 def validate_claim(request, opts = {}) @api.validate_claim_using_post(auth_token.auth, request, opts) end
Private Instance Methods
# File lib/change_healthcare/professional_claims/wrapper.rb, line 136 def api_config @api.api_client.config end
# File lib/change_healthcare/professional_claims/wrapper.rb, line 110 def fetch_new_token! path = "https://#{api_config.host}/apip/auth/v2/token" uri = URI(path) res = Net::HTTP.post_form( uri, 'client_id' => @client_id, 'client_secret' => @client_secret, 'grant_type' => 'client_credentials' ) body = JSON.parse(res.body) handle_auth(body, res.code) end
# File lib/change_healthcare/professional_claims/wrapper.rb, line 123 def handle_auth(body, code) case code when '200' @auth_token = AuthToken.new(body['access_token'], Time.new + body['expires_in']) when '400' raise BadAuthorizationError, "bad authorization request (#{body['error_description']})" when '401' raise BadAuthRequestError, "bad auth request: (#{body['error_description']})" else raise UnknownAuthError, "internal problem (auth request had status #{code})" end end