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



34
35
36
37
38
39
# File 'lib/change_health/connection.rb', line 34

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, base_uri: nil, auth_headers: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/change_health/connection.rb', line 16

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

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