Class: ChangeHealth::Connection

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/change_health/connection.rb

Constant Summary collapse

URI_BUILDER =
->(host) { "https://#{host}apigw.changehealthcare.com/".freeze }
QA_ENDPOINT =
URI_BUILDER.call('sandbox.')
PROD_ENDPOINT =
URI_BUILDER.call('')

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.endpoint_for(klass, default_endpoint: nil) ⇒ Object



24
25
26
27
28
29
# File 'lib/change_health/connection.rb', line 24

def self.endpoint_for(klass, default_endpoint: nil)
  endpoint_options = ChangeHealth.configuration.endpoints || {}
  default_endpoint ||= klass::ENDPOINT

  endpoint_options[klass.to_s] || endpoint_options[klass.to_s.to_sym] || default_endpoint
end

Instance Method Details

#request(endpoint:, query: nil, body: nil, headers: {}, auth: true, verb: :post) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/change_health/connection.rb', line 16

def request(endpoint:, query: nil, body: nil, headers: {}, auth: true, verb: :post)
  body    = body.to_json if body.is_a?(Hash)
  headers = {} if headers.nil?
  headers = auth_header.merge(headers) if auth

  self.class.send(verb.to_s, endpoint, query: query, body: body, headers: headers)
end