Class: ChangeHealthcare::Eligibility::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/change_healthcare/eligibility/wrapper.rb

Overview

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.

Defined Under Namespace

Classes: AuthToken, BadAuthRequestError, BadAuthorizationError, UnknownAuthError

Instance Method Summary collapse

Constructor Details

#initialize(client_id:, client_secret:) ⇒ Wrapper

Returns a new instance of Wrapper.



13
14
15
16
17
18
19
20
# File 'lib/change_healthcare/eligibility/wrapper.rb', line 13

def initialize(client_id:, client_secret:)
  @client_id = client_id
  @client_secret = client_secret
  @api = SwaggerClient::EligibilityApi.new
  # fake auth token that is expired
  @auth_token = AuthToken.new('', Time.at(0))
  @mutex = Mutex.new
end

Instance Method Details

#auth_tokenObject

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.

Raises:



67
68
69
70
71
72
73
# File 'lib/change_healthcare/eligibility/wrapper.rb', line 67

def auth_token
  @mutex.synchronize do
    fetch_new_token! unless @auth_token.valid?

    @auth_token
  end
end

#eligibility(request, opts = {}) ⇒ ChangeHealthcare::Eligibility::SwaggerClient::Response

Check eligibility.

Will refresh auth token if needed (holding a lock while it does so for thread-safety).

Parameters:

Returns:

Raises:



35
36
37
# File 'lib/change_healthcare/eligibility/wrapper.rb', line 35

def eligibility(request, opts = {})
  @api.eligibility(auth_token.auth, request, opts)
end

#health_checkChangeHealthcare::Eligibility::SwaggerClient::HealthCheck

Check health of the API



43
44
45
# File 'lib/change_healthcare/eligibility/wrapper.rb', line 43

def health_check
  @api.health_check_using_get(auth_token.auth)
end