Class: ChangeHealthcare::Eligibility::Wrapper
- Inherits:
-
Object
- Object
- ChangeHealthcare::Eligibility::Wrapper
- 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
-
#auth_token ⇒ Object
Obtain a valid authentication token.
-
#eligibility(request, opts = {}) ⇒ ChangeHealthcare::Eligibility::SwaggerClient::Response
Check eligibility.
-
#health_check ⇒ ChangeHealthcare::Eligibility::SwaggerClient::HealthCheck
Check health of the API.
-
#initialize(client_id:, client_secret:) ⇒ Wrapper
constructor
A new instance of Wrapper.
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_token ⇒ Object
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.
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).
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_check ⇒ ChangeHealthcare::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 |