eligible 2.3 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/eligible.gemspec CHANGED
@@ -6,15 +6,14 @@ require 'eligible/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "eligible"
8
8
  gem.version = Eligible::VERSION
9
- gem.authors = ["Andy Brett"]
10
- gem.email = ["andy@andybrett.com"]
11
- gem.description = 'Eligible is a developer-friendly way to process health care eligibility checks. Learn more at https://eligibleapi.com'
9
+ gem.authors = ["Katelyn Gleaon", "Rodrigo Dominguez", "Andry Brett"]
10
+ gem.email = ["k@eligibleapi.com", "rod@eligibleapi.com", "andy@andybrett.com"]
11
+ gem.description = 'Eligible is a developer-friendly way to process health care eligibility checks. Learn more at https://www.eligibleapi.com'
12
12
  gem.summary = 'Ruby wrapper for the Eligible API'
13
- gem.homepage = "https://eligibleapi.com/"
13
+ gem.homepage = "https://www.eligibleapi.com/"
14
14
  gem.license = "MIT"
15
15
 
16
16
  gem.files = `git ls-files`.split($/)
17
- # gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
17
  gem.test_files = `git ls-files -- test/*`.split("\n")
19
18
  gem.require_paths = ["lib"]
20
19
 
@@ -23,6 +22,6 @@ Gem::Specification.new do |gem|
23
22
  gem.add_development_dependency('test-unit')
24
23
  gem.add_development_dependency('rake')
25
24
 
26
- gem.add_dependency('rest-client', '~> 1.4')
27
- gem.add_dependency('multi_json', '>= 1.0.4', '< 2')
25
+ gem.add_dependency('rest-client', '~> 1.6.7')
26
+ gem.add_dependency('multi_json', '~> 1.7.9')
28
27
  end
data/lib/eligible.rb CHANGED
@@ -2,9 +2,8 @@ require 'cgi'
2
2
  require 'set'
3
3
  require 'rubygems'
4
4
  require 'openssl'
5
- require 'json'
5
+ require 'net/https'
6
6
 
7
- gem 'rest-client', '~> 1.4'
8
7
  require 'rest_client'
9
8
  require 'multi_json'
10
9
 
@@ -13,14 +12,14 @@ require 'eligible/util'
13
12
  require 'eligible/json'
14
13
  require 'eligible/eligible_object'
15
14
  require 'eligible/api_resource'
16
- require 'eligible/plan'
17
- require 'eligible/service'
18
15
  require 'eligible/demographic'
19
16
  require 'eligible/claim'
20
17
  require 'eligible/enrollment'
21
18
  require 'eligible/coverage'
22
19
  require 'eligible/payment'
23
20
  require 'eligible/x12'
21
+ require 'eligible/medicare'
22
+ require 'eligible/ticket'
24
23
 
25
24
  # Errors
26
25
  require 'eligible/errors/eligible_error'
@@ -30,13 +29,13 @@ require 'eligible/errors/api_error'
30
29
  require 'eligible/errors/invalid_request_error'
31
30
 
32
31
  module Eligible
33
- @@api_key = nil
32
+ @@api_key = nil
34
33
  @@test = false
35
34
  @@api_base = 'https://gds.eligibleapi.com/v1.1'
36
35
  @@api_version = 1.1
37
36
 
38
37
  def self.api_url(url='')
39
- @@api_base + url
38
+ @@api_base + url.to_s
40
39
  end
41
40
 
42
41
  def self.api_key
@@ -47,9 +46,16 @@ module Eligible
47
46
  @@api_key = api_key
48
47
  end
49
48
 
49
+ def self.api_base
50
+ @@api_base
51
+ end
52
+
53
+ def self.api_base=(api_base)
54
+ @@api_base = api_base
55
+ end
50
56
 
51
57
  def self.test
52
- @@test? 'true':'false'
58
+ @@test ? 'true' : 'false'
53
59
  end
54
60
 
55
61
  def self.test=(is_test)
@@ -62,31 +68,12 @@ module Eligible
62
68
 
63
69
  def self.api_version
64
70
  @@api_version
65
- end
71
+ end
66
72
 
67
73
  def self.request(method, url, api_key, params={}, headers={})
68
74
  api_key ||= @@api_key
69
75
  raise AuthenticationError.new('No API key provided. (HINT: set your API key using "Eligible.api_key = <API-KEY>".') unless api_key
70
76
 
71
- # if !verify_ssl_certs
72
- # unless @no_verify
73
- # $stderr.puts "WARNING: Running without SSL cert verification. Execute 'Eligible.verify_ssl_certs = true' to enable verification."
74
- # @no_verify = true
75
- # end
76
- # ssl_opts = { :verify_ssl => false }
77
- # elsif !Util.file_readable(@@ssl_bundle_path)
78
- # unless @no_bundle
79
- # $stderr.puts "WARNING: Running without SSL cert verification because #{@@ssl_bundle_path} isn't readable"
80
- # @no_bundle = true
81
- # end
82
- # ssl_opts = { :verify_ssl => false }
83
- # else
84
- # ssl_opts = {
85
- # :verify_ssl => OpenSSL::SSL::VERIFY_PEER,
86
- # :ssl_ca_file => @@ssl_bundle_path
87
- # }
88
- # end
89
- uname = (@@uname ||= RUBY_PLATFORM =~ /linux|darwin/i ? `uname -a 2>/dev/null`.strip : nil)
90
77
  lang_version = "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})"
91
78
  ua = {
92
79
  :bindings_version => Eligible::VERSION,
@@ -97,20 +84,20 @@ module Eligible
97
84
  :uname => uname
98
85
  }
99
86
 
100
- # params = Util.objects_to_ids(params)
87
+ # GET requests, parameters on the query string
88
+ # POST requests, parameters as json in the body
101
89
  url = self.api_url(url)
102
90
  case method.to_s.downcase.to_sym
103
- when :get, :head, :delete
104
- # Make params into GET parameters
105
- url += "?api_key=#{api_key}"
106
- if params && params.count > 0
107
- query_string = Util.flatten_params(params).collect{|key, value| "#{key}=#{Util.url_encode(value)}"}.join('&')
108
- url += "&#{query_string}"
109
- end
110
- url +="&test=#{self.test}"
111
- payload = nil
112
- else
113
- payload = params.merge!({'api_key' => api_key ,'test' => self.test }).to_json #Util.flatten_params(params).collect{|(key, value)| "#{key}=#{Util.url_encode(value)}"}.join('&')
91
+ when :get, :head
92
+ url += "?api_key=#{api_key}"
93
+ if params && params.count > 0
94
+ query_string = Util.flatten_params(params).collect { |key, value| "#{key}=#{Util.url_encode(value)}" }.join('&')
95
+ url += "&#{query_string}"
96
+ end
97
+ url +="&test=#{self.test}"
98
+ payload = nil
99
+ else
100
+ payload = Eligible::JSON.dump(params.merge!({ 'api_key' => api_key, 'test' => self.test }))
114
101
  end
115
102
 
116
103
  begin
@@ -128,9 +115,7 @@ module Eligible
128
115
  :content_type => 'application/x-www-form-urlencoded'
129
116
  }.merge(headers)
130
117
 
131
- if self.api_version
132
- headers[:eligible_version] = self.api_version
133
- end
118
+ headers[:eligible_version] = self.api_version if self.api_version
134
119
 
135
120
  opts = {
136
121
  :method => method,
@@ -139,8 +124,8 @@ module Eligible
139
124
  :open_timeout => 30,
140
125
  :payload => payload,
141
126
  :timeout => 80
142
- }#.merge(ssl_opts)
143
-
127
+ }
128
+
144
129
  begin
145
130
  response = execute_request(opts)
146
131
 
@@ -169,7 +154,11 @@ module Eligible
169
154
  begin
170
155
  # Would use :symbolize_names => true, but apparently there is
171
156
  # some library out there that makes symbolize_names not work.
172
- resp = params[:format] && params[:format].match(/x12/i) ? rbody : Eligible::JSON.load(rbody)
157
+ resp = if params[:format] && params[:format].downcase == 'x12' || url[-4..-1].downcase == '/x12'
158
+ rbody
159
+ else
160
+ Eligible::JSON.load(rbody)
161
+ end
173
162
  rescue MultiJson::DecodeError
174
163
  raise APIError.new("Invalid response object from API: #{rbody.inspect} (HTTP response code was #{rcode})", rcode, rbody)
175
164
  end
@@ -180,6 +169,10 @@ module Eligible
180
169
 
181
170
  private
182
171
 
172
+ def self.uname
173
+ @@uname ||= RUBY_PLATFORM =~ /linux|darwin/i ? `uname -a 2>/dev/null`.strip : nil
174
+ end
175
+
183
176
  def self.execute_request(opts)
184
177
  RestClient::Request.execute(opts)
185
178
  end
@@ -194,12 +187,12 @@ module Eligible
194
187
  end
195
188
 
196
189
  case rcode
197
- when 400, 404 then
198
- raise invalid_request_error(error, rcode, rbody, error_obj)
199
- when 401
200
- raise authentication_error(error, rcode, rbody, error_obj)
201
- else
202
- raise api_error(error, rcode, rbody, error_obj)
190
+ when 400, 404 then
191
+ raise invalid_request_error(error, rcode, rbody, error_obj)
192
+ when 401
193
+ raise authentication_error(error, rcode, rbody, error_obj)
194
+ else
195
+ raise api_error(error, rcode, rbody, error_obj)
203
196
  end
204
197
  end
205
198
 
@@ -217,17 +210,18 @@ module Eligible
217
210
 
218
211
  def self.handle_restclient_error(e)
219
212
  case e
220
- when RestClient::ServerBrokeConnection, RestClient::RequestTimeout
221
- message = "Could not connect to Eligible (#{@@api_base}). Please check your internet connection and try again."
222
- when RestClient::SSLCertificateNotVerified
223
- message = "Could not verify Eligible's SSL certificate."
224
- when SocketError
225
- message = 'Unexpected error communicating when trying to connect to Eligible.'
226
- else
227
- message = 'Unexpected error communicating with Eligible. If this problem persists, let us know at support@eligible.com.'
213
+ when RestClient::ServerBrokeConnection, RestClient::RequestTimeout
214
+ message = "Could not connect to Eligible (#{@@api_base}). Please check your internet connection and try again."
215
+ when RestClient::SSLCertificateNotVerified
216
+ message = "Could not verify Eligible's SSL certificate."
217
+ when SocketError
218
+ message = 'Unexpected error communicating when trying to connect to Eligible.'
219
+ else
220
+ message = 'Unexpected error communicating with Eligible. If this problem persists, let us know at support@eligible.com.'
228
221
  end
229
222
  message += "\n\n(Network error: #{e.message})"
230
223
  raise APIConnectionError.new(message)
231
224
  end
232
225
 
233
226
  end
227
+
@@ -1,5 +1,6 @@
1
1
  module Eligible
2
2
  class APIResource < EligibleObject
3
+
3
4
  def self.class_name
4
5
  self.name.split('::')[-1]
5
6
  end
@@ -8,7 +9,8 @@ module Eligible
8
9
  if self == APIResource
9
10
  raise NotImplementedError.new('APIResource is an abstract class. You should perform actions on its subclasses (Plan, Service, etc.)')
10
11
  end
11
- "/#{CGI.escape(class_name.downcase)}/all.json"
12
+ "/#{CGI.escape(class_name.downcase)}/"
12
13
  end
14
+
13
15
  end
14
16
  end
@@ -1,22 +1,28 @@
1
1
  module Eligible
2
2
  class Claim < APIResource
3
- def self.get(params, api_key=nil)
4
- response, api_key = Eligible.request(:get, "/claims/acknowledgements/#{params[:reference_id]}.json", api_key, params)
5
- Util.convert_to_eligible_object(response, api_key)
6
- end
7
3
 
8
- def self.post(params, api_key=nil)
9
- response, api_key = Eligible.request(:post, "/claims.json", api_key, params)
10
- Util.convert_to_eligible_object(response, api_key)
11
- end
4
+ class << self
5
+
6
+ def get(params, api_key = nil)
7
+ response, api_key = Eligible.request(:get, "/claims/acknowledgements/#{params[:reference_id]}.json", api_key, params)
8
+ Util.convert_to_eligible_object(response, api_key)
9
+ end
10
+
11
+ def post(params, api_key = nil)
12
+ response, api_key = Eligible.request(:post, '/claims.json', api_key, params)
13
+ Util.convert_to_eligible_object(response, api_key)
14
+ end
15
+
16
+ def all(api_key = nil)
17
+ response, api_key = Eligible.request(:get, '/claims/acknowledgements.json', api_key)
18
+ Util.convert_to_eligible_object(response, api_key)
19
+ end
12
20
 
13
- def self.all(api_key=nil)
14
- response, api_key = Eligible.request(:get, "/claims/acknowledgements.json", api_key)
15
- Util.convert_to_eligible_object(response, api_key)
16
21
  end
17
22
 
18
23
  def status
19
24
  error ? nil : to_hash
20
25
  end
26
+
21
27
  end
22
28
  end
@@ -1,29 +1,24 @@
1
1
  module Eligible
2
-
3
2
  class Coverage < APIResource
4
3
 
5
- def self.get(params, api_key=nil)
6
- response, api_key = Eligible.request(:get, url, api_key, params)
7
- Util.convert_to_eligible_object(response, api_key)
8
- end
9
-
10
- def all
11
- error ? nil : to_hash
12
- end
4
+ class << self
13
5
 
6
+ def get(params, api_key=nil)
7
+ response, api_key = Eligible.request(:get, '/coverage/all.json', api_key, params)
8
+ Util.convert_to_eligible_object(response, api_key)
9
+ end
14
10
 
11
+ def batch_post(params, api_key=nil)
12
+ response, api_key = Eligible.request(:post, '/coverage/all/batch.json', api_key, params)
13
+ Util.convert_to_eligible_object(response, api_key)
14
+ end
15
15
 
16
- def self.batch_post(params, api_key=nil)
17
- #https://gds.eligibleapi.com/v1.1/coverage/all/batch.json
18
- response, api_key = Eligible.request(:post, '/coverage/all/batch.json', api_key, params)
19
- Util.convert_to_eligible_object(response, api_key)
20
- end
16
+ def batch_medicare_post(params, api_key=nil)
17
+ response, api_key = Eligible.request(:post, '/medicare/coverage/batch.json', api_key, params)
18
+ Util.convert_to_eligible_object(response, api_key)
19
+ end
21
20
 
22
- def self.batch_medicare_post(params, api_key=nil)
23
- response, api_key = Eligible.request(:post, '/medicare/coverage/batch.json', api_key, params)
24
- Util.convert_to_eligible_object(response, api_key)
25
21
  end
26
22
 
27
23
  end
28
-
29
24
  end
@@ -1,46 +1,16 @@
1
1
  module Eligible
2
2
  class Demographic < APIResource
3
- COMMON_ATTRIBUTES = [:timestamp, :eligible_id, :mapping_version]
4
- ZIP_ATTRIBUTES = [:zip]
5
- EMPLOYER_ATTRIBUTES = [:group_id, :group_name]
6
- ADDRESS_ATTRIBUTES = [:address]
7
- DOB_ATTRIBUTES = [:dob]
8
-
9
- def self.get(params, api_key=nil)
10
- response, api_key = Eligible.request(:get, url, api_key, params)
11
- Util.convert_to_eligible_object(response, api_key)
12
- end
13
-
14
- def all
15
- error ? nil : to_hash
16
- end
17
-
18
- def zip
19
- keys = COMMON_ATTRIBUTES
20
- h = to_hash.select { |k, v| keys.include?(k) }
21
- h[:zip] = to_hash[:address][:zip]
22
- error ? nil : h
23
- end
24
-
25
- def employer
26
- keys = COMMON_ATTRIBUTES + EMPLOYER_ATTRIBUTES
27
- error ? nil : to_hash.select { |k, v| keys.include?(k) }
28
- end
29
-
30
- def address
31
- keys = COMMON_ATTRIBUTES + ADDRESS_ATTRIBUTES
32
- error ? nil : to_hash.select { |k, v| keys.include?(k) }
33
- end
34
-
35
- def dob
36
- keys = COMMON_ATTRIBUTES + DOB_ATTRIBUTES
37
- error ? nil : to_hash.select { |k, v| keys.include?(k) }
38
- end
3
+ class << self
39
4
 
5
+ def get(params, api_key=nil)
6
+ response, api_key = Eligible.request(:get, '/demographic/all.json', api_key, params)
7
+ Util.convert_to_eligible_object(response, api_key)
8
+ end
40
9
 
41
- def self.batch_post(params, api_key=nil)
42
- response, api_key = Eligible.request(:post, '/demographic/all/batch.json', api_key, params)
43
- Util.convert_to_eligible_object(response, api_key)
10
+ def batch_post(params, api_key=nil)
11
+ response, api_key = Eligible.request(:post, '/demographic/all/batch.json', api_key, params)
12
+ Util.convert_to_eligible_object(response, api_key)
13
+ end
44
14
  end
45
15
  end
46
16
  end
@@ -47,7 +47,7 @@ module Eligible
47
47
  @unsaved_values.delete(k)
48
48
  end
49
49
  values.each do |k, v|
50
- @values[k] = v#Util.convert_to_eligible_object(v, api_key)
50
+ @values[k] = v
51
51
  @transient_values.delete(k)
52
52
  @unsaved_values.delete(k)
53
53
  end
@@ -1,28 +1,23 @@
1
1
  module Eligible
2
-
3
2
  class Enrollment < APIResource
4
3
 
5
- def self.get(params, api_key=nil)
6
- response, api_key = Eligible.request(:get, "/enrollment.json", api_key, params)
7
- Util.convert_to_eligible_object(response, api_key)
8
- end
4
+ class << self
9
5
 
10
- def self.post(params, api_key=nil)
11
- response, api_key = Eligible.request(:post, "/enrollment.json", api_key, params)
12
- Util.convert_to_eligible_object(response, api_key)
13
- end
6
+ def get(params, api_key=nil)
7
+ response, api_key = Eligible.request(:get, "/enrollment.json", api_key, params)
8
+ Util.convert_to_eligible_object(response, api_key)
9
+ end
10
+
11
+ def post(params, api_key=nil)
12
+ response, api_key = Eligible.request(:post, "/enrollment.json", api_key, params)
13
+ Util.convert_to_eligible_object(response, api_key)
14
+ end
14
15
 
15
- def all
16
- error ? nil : to_hash
17
16
  end
18
17
 
19
18
  def enrollment_npis
20
- r = Array.new
21
- values[0].each do |value|
22
- r << value[:enrollment_npi]
23
- end
24
- r
19
+ values.first[:enrollment_npis]
25
20
  end
26
- end
27
21
 
22
+ end
28
23
  end