Module: Eligible
- Defined in:
- lib/eligible.rb,
lib/eligible/icd.rb,
lib/eligible/ocr.rb,
lib/eligible/x12.rb,
lib/eligible/json.rb,
lib/eligible/util.rb,
lib/eligible/claim.rb,
lib/eligible/payer.rb,
lib/eligible/ticket.rb,
lib/eligible/lockbox.rb,
lib/eligible/payment.rb,
lib/eligible/precert.rb,
lib/eligible/version.rb,
lib/eligible/coverage.rb,
lib/eligible/customer.rb,
lib/eligible/medicare.rb,
lib/eligible/referral.rb,
lib/eligible/v1_0/fee.rb,
lib/eligible/encryptor.rb,
lib/eligible/v1_0/file.rb,
lib/eligible/v1_0/rule.rb,
lib/eligible/enrollment.rb,
lib/eligible/public_key.rb,
lib/eligible/v1_0/claim.rb,
lib/eligible/visit_type.rb,
lib/eligible/demographic.rb,
lib/eligible/oauth_token.rb,
lib/eligible/v1_0/action.rb,
lib/eligible/v1_0/charge.rb,
lib/eligible/v1_0/device.rb,
lib/eligible/v1_0/refund.rb,
lib/eligible/v1_0/remark.rb,
lib/eligible/api_resource.rb,
lib/eligible/received_pdf.rb,
lib/eligible/v1_0/product.rb,
lib/eligible/v1_0/session.rb,
lib/eligible/payer_mapping.rb,
lib/eligible/session_token.rb,
lib/eligible/v1_0/contract.rb,
lib/eligible/v1_0/discount.rb,
lib/eligible/v1_0/estimate.rb,
lib/eligible/v1_0/provider.rb,
lib/eligible/provider_model.rb,
lib/eligible/v1_0/attribute.rb,
lib/eligible/v1_0/file_link.rb,
lib/eligible/v1_0/treatment.rb,
lib/eligible/eligible_object.rb,
lib/eligible/risk_assessment.rb,
lib/eligible/v1_0/enrollment.rb,
lib/eligible/v1_0/fee_refund.rb,
lib/eligible/v1_0/value_list.rb,
lib/eligible/errors/api_error.rb,
lib/eligible/preauth_resource.rb,
lib/eligible/v1_0/transaction.rb,
lib/eligible/coverage_resource.rb,
lib/eligible/v1_0/verification.rb,
lib/eligible/v1_0/rest_api_base.rb,
lib/eligible/v1_0/patient_record.rb,
lib/eligible/v1_0/payment_report.rb,
lib/eligible/v1_0/balance_capture.rb,
lib/eligible/v1_0/value_list_item.rb,
lib/eligible/calculator_deploy_url.rb,
lib/eligible/errors/eligible_error.rb,
lib/eligible/v1_0/insurance_policy.rb,
lib/eligible/v1_0/patient_question.rb,
lib/eligible/original_signature_pdf.rb,
lib/eligible/v1_0/insurance_company.rb,
lib/eligible/v1_0/patient_statement.rb,
lib/eligible/v1_0/claim_service_line.rb,
lib/eligible/v1_0/estimate_service_line.rb,
lib/eligible/v1_0/patient_questionnaire.rb,
lib/eligible/errors/api_connection_error.rb,
lib/eligible/errors/authentication_error.rb,
lib/eligible/errors/invalid_request_error.rb,
lib/eligible/v1_0/insurance_company_alias.rb,
lib/eligible/v1_0/patient_statement_service_line.rb
Defined Under Namespace
Modules: Encryptor, JSON, Util, V1_0 Classes: APIConnectionError, APIError, APIResource, AuthenticationError, CalculatorDeployUrl, Claim, Coverage, CoverageResource, Customer, Demographic, EligibleError, EligibleObject, Enrollment, Icd, InvalidRequestError, Lockbox, Medicare, OauthToken, Ocr, OriginalSignaturePdf, Payer, PayerMapping, Payment, PreauthResource, Precert, ProviderModel, PublicKey, ReceivedPdf, Referral, RiskAssessment, SessionToken, Ticket, VisitType, X12
Constant Summary collapse
- VERSION =
'3.1.0.beta5'.freeze
- @@api_key =
nil- @@test =
false- @@api_version =
'1.5'- @@api_base =
"https://gds.eligibleapi.com/v#{@@api_version}"- @@fingerprints =
%w(ad10dbfd536a0d054b02a7d30c11aa1eb5dbfb41 1fe04161ed657b55ac29a0c48da4cf246f8e657b 1a1b7d4faa43ecdeab40cc8d203583624d5917f4 b4225ee59dc7ede4d68e7b2c75c6e6ac79649416 75132c1ab844500c6ad1f26b49c11d36933ce868 1c3fe254bded256ea30d0a235bb9881b82701082 a1cd762a9f4be0f3b6bdd6300e52c6ce8d7d67f5 36d6b6f98a2b9bcdf4321d1978553e23cf044b53)
- @@eligible_account =
nil- @@eligible_account_id =
nil
Class Method Summary collapse
- .add_fingerprint(digest) ⇒ Object
- .api_base ⇒ Object
- .api_base=(api_base) ⇒ Object
- .api_key ⇒ Object
- .api_key=(api_key) ⇒ Object
- .api_key?(params) ⇒ Boolean
- .api_url(url = '', rest_api_version = nil) ⇒ Object
- .api_version ⇒ Object
- .api_version=(version) ⇒ Object
- .authorization_header(basic_auth, auth_options) ⇒ Object
- .direct_response?(params) ⇒ Boolean
- .eligible_account ⇒ Object
- .eligible_account=(eligible_account) ⇒ Object
- .eligible_account_id ⇒ Object
- .eligible_account_id=(eligible_account_id) ⇒ Object
- .fetch_url_with_query_string(params, url, options) ⇒ Object
- .fingerprints ⇒ Object
- .generate_request_headers(headers, debug_info, basic_auth, auth_options) ⇒ Object
- .generate_request_url_and_payload(method, url, params, options) ⇒ Object
- .options_query_string(options) ⇒ Object
- .params_query_string(params) ⇒ Object
- .request(method, url, api_key, params = {}, headers = {}) ⇒ Object
- .request_payload(options, params) ⇒ Object
- .rest_api_version?(params) ⇒ Boolean
- .test ⇒ Object
- .test=(is_test) ⇒ Object
- .test_key?(params) ⇒ Boolean
- .valid_fingerprint?(received) ⇒ Boolean
- .verify_certificate ⇒ Object
Class Method Details
.add_fingerprint(digest) ⇒ Object
163 164 165 166 |
# File 'lib/eligible.rb', line 163 def self.add_fingerprint(digest) $stderr.puts 'The embedded certificate fingerprint was modified. This should only be done if instructed to by eligible support staff' @@fingerprints << digest end |
.api_base ⇒ Object
135 136 137 |
# File 'lib/eligible.rb', line 135 def self.api_base @@api_base end |
.api_base=(api_base) ⇒ Object
139 140 141 |
# File 'lib/eligible.rb', line 139 def self.api_base=(api_base) @@api_base = api_base end |
.api_key ⇒ Object
127 128 129 |
# File 'lib/eligible.rb', line 127 def self.api_key @@api_key end |
.api_key=(api_key) ⇒ Object
131 132 133 |
# File 'lib/eligible.rb', line 131 def self.api_key=(api_key) @@api_key = api_key end |
.api_key?(params) ⇒ Boolean
176 177 178 |
# File 'lib/eligible.rb', line 176 def self.api_key?(params) Util.key?(params, :api_key) end |
.api_url(url = '', rest_api_version = nil) ⇒ Object
106 107 108 109 |
# File 'lib/eligible.rb', line 106 def self.api_url(url = '', rest_api_version = nil) api_base = rest_api_version ? @@api_base.gsub(/v(\d).(\d)/, "v#{rest_api_version}") : @@api_base api_base + url.to_s end |
.api_version ⇒ Object
155 156 157 |
# File 'lib/eligible.rb', line 155 def self.api_version @@api_version end |
.api_version=(version) ⇒ Object
151 152 153 |
# File 'lib/eligible.rb', line 151 def self.api_version=(version) @@api_version = version end |
.authorization_header(basic_auth, auth_options) ⇒ Object
327 328 329 330 331 332 333 334 |
# File 'lib/eligible.rb', line 327 def self.(basic_auth, ) # Using Bearer scheme for Session Token Auth for new REST API endpoints (v1.0) return "Bearer #{[:session_token]}" if basic_auth && [:session_token] # Using Basic Auth for new REST API endpoints (v1.0) basic_auth_token = Base64.strict_encode64("#{[:api_key]}:") "Basic #{basic_auth_token}" if basic_auth end |
.direct_response?(params) ⇒ Boolean
168 169 170 |
# File 'lib/eligible.rb', line 168 def self.direct_response?(params) params[:format].is_a?(String) && params[:format].downcase == 'x12' end |
.eligible_account ⇒ Object
111 112 113 |
# File 'lib/eligible.rb', line 111 def self.eligible_account @@eligible_account end |
.eligible_account=(eligible_account) ⇒ Object
119 120 121 |
# File 'lib/eligible.rb', line 119 def self.eligible_account=(eligible_account) @@eligible_account = eligible_account end |
.eligible_account_id ⇒ Object
115 116 117 |
# File 'lib/eligible.rb', line 115 def self.eligible_account_id @@eligible_account_id end |
.eligible_account_id=(eligible_account_id) ⇒ Object
123 124 125 |
# File 'lib/eligible.rb', line 123 def self.eligible_account_id=(eligible_account_id) @@eligible_account_id = eligible_account_id end |
.fetch_url_with_query_string(params, url, options) ⇒ Object
283 284 285 286 287 288 289 290 |
# File 'lib/eligible.rb', line 283 def self.fetch_url_with_query_string(params, url, ) url += () return url unless params || params.count == 0 query_string = params_query_string(params) url += [:basic_auth] ? "?#{query_string}" : "&#{query_string}" url end |
.fingerprints ⇒ Object
159 160 161 |
# File 'lib/eligible.rb', line 159 def self.fingerprints @@fingerprints end |
.generate_request_headers(headers, debug_info, basic_auth, auth_options) ⇒ Object
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/eligible.rb', line 305 def self.generate_request_headers(headers, debug_info, basic_auth, ) begin headers = { x_eligible_debuginfo: Eligible::JSON.dump(debug_info) }.merge(headers) rescue => e headers = { x_eligible_client_raw_user_agent: debug_info.inspect, error: "#{e} (#{e.class})" }.merge(headers) end headers = { user_agent: "eligible-ruby/#{Eligible::VERSION}", content_type: 'application/json' }.merge(headers) headers[:authorization] = (basic_auth, **) headers[:eligible_version] = api_version if api_version headers[:eligible_account] = eligible_account if eligible_account headers[:eligible_account_id] = eligible_account_id if eligible_account_id headers end |
.generate_request_url_and_payload(method, url, params, options) ⇒ Object
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/eligible.rb', line 266 def self.generate_request_url_and_payload(method, url, params, ) # GET requests, parameters on the query string # POST requests, parameters as json in the body url = api_url(url, [:rest_api_version]) # Used rest_api_version param only to identify new REST API version, and is not required to make calls for new REST api endpoints params.delete(:rest_api_version) case method.to_s.downcase.to_sym when :get, :head, :delete url = fetch_url_with_query_string(params, url, **) payload = nil else payload = request_payload(, **params) end [url, payload] end |
.options_query_string(options) ⇒ Object
292 293 294 |
# File 'lib/eligible.rb', line 292 def self.() [:basic_auth] ? '' : "?test=#{[:test]}&api_key=#{[:api_key]}" end |
.params_query_string(params) ⇒ Object
296 297 298 |
# File 'lib/eligible.rb', line 296 def self.params_query_string(params) Util.flatten_params(params).collect { |key, value| "#{key}=#{Util.url_encode(value)}" }.join('&') end |
.request(method, url, api_key, params = {}, headers = {}) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/eligible.rb', line 184 def self.request(method, url, api_key, params = {}, headers = {}) session_token = Util.value(params, :session_token) api_key ||= @@api_key unless session_token test = self.test api_key = Util.value(params, :api_key) if api_key?(params) test = Util.value(params, :test) if test_key?(params) rest_api_version = Util.value(params, :rest_api_version) if rest_api_version?(params) basic_auth = true if rest_api_version?(params) fail AuthenticationError, 'No API key provided. (HINT: set your API key using "Eligible.api_key = <API-KEY>".' unless api_key || session_token lang_version = "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})" debug_info = { bindings_version: Eligible::VERSION, lang: 'ruby', lang_version: lang_version, platform: RUBY_PLATFORM, publisher: 'eligible', uname: uname } # Set request URL and Payload based on new and old endpoints version url, payload = generate_request_url_and_payload( method, url, params, **{ test: test, rest_api_version: rest_api_version, api_key: api_key, basic_auth: basic_auth }, ) # Set request Headers and Authorization based on new and old endpoints version headers = generate_request_headers(headers, debug_info, basic_auth, **{ api_key: api_key, session_token: session_token }) opts = { method: method, url: url, headers: headers, open_timeout: 30, payload: payload, timeout: 80, ssl_verify_callback: verify_certificate, ssl_verify_callback_warnings: false } begin response = execute_request(opts) rescue SocketError => e handle_restclient_error(e) rescue NoMethodError => e # Work around RestClient bug raise unless e. =~ /\WRequestFailed\W/ e = APIConnectionError.new('Unexpected HTTP response code') handle_restclient_error(e) rescue RestClient::ExceptionWithResponse => e err_rcode = e.http_code err_rbody = e.http_body if err_rcode && err_rbody handle_api_error(err_rcode, err_rbody) else handle_restclient_error(e) end rescue RestClient::Exception, Errno::ECONNREFUSED => e handle_restclient_error(e) end rbody = response.body rcode = response.code begin # Would use :symbolize_names => true, but apparently there is # some library out there that makes symbolize_names not work. resp = direct_response?(params) ? rbody : Eligible::JSON.load(rbody) rescue MultiJson::DecodeError raise APIError.new("Invalid response object from API: #{rbody.inspect} (HTTP response code was #{rcode})", rcode, rbody) end resp = Util.symbolize_names(resp) return [ resp, api_key ] end |
.request_payload(options, params) ⇒ Object
300 301 302 303 |
# File 'lib/eligible.rb', line 300 def self.request_payload(, params) params.merge!('test' => [:test], 'api_key' => [:api_key]) unless [:basic_auth] Util.key?(params, :file) ? params : Eligible::JSON.dump(params) end |
.rest_api_version?(params) ⇒ Boolean
180 181 182 |
# File 'lib/eligible.rb', line 180 def self.rest_api_version?(params) Util.key?(params, :rest_api_version) end |
.test ⇒ Object
143 144 145 |
# File 'lib/eligible.rb', line 143 def self.test @@test ? 'true' : 'false' end |
.test=(is_test) ⇒ Object
147 148 149 |
# File 'lib/eligible.rb', line 147 def self.test=(is_test) @@test = is_test end |
.test_key?(params) ⇒ Boolean
172 173 174 |
# File 'lib/eligible.rb', line 172 def self.test_key?(params) Util.key?(params, :test) end |
.valid_fingerprint?(received) ⇒ Boolean
346 347 348 |
# File 'lib/eligible.rb', line 346 def self.valid_fingerprint?(received) fingerprints.include?(OpenSSL::Digest::SHA1.hexdigest(received.to_der)) end |
.verify_certificate ⇒ Object
336 337 338 339 340 341 342 343 344 |
# File 'lib/eligible.rb', line 336 def self.verify_certificate lambda do |preverify_ok, certificate_store| return true if test == 'true' return false unless preverify_ok received = certificate_store.chain.first return true unless received.to_der == certificate_store.current_cert.to_der valid_fingerprint?(received) end end |