eligible 2.0
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/.gitignore +17 -0
- data/CONTRIBUTORS +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +348 -0
- data/Rakefile +4 -0
- data/eligible.gemspec +28 -0
- data/lib/eligible/api_resource.rb +14 -0
- data/lib/eligible/claim.rb +22 -0
- data/lib/eligible/coverage.rb +16 -0
- data/lib/eligible/demographic.rb +40 -0
- data/lib/eligible/eligible_object.rb +121 -0
- data/lib/eligible/enrollment.rb +20 -0
- data/lib/eligible/errors/api_connection_error.rb +4 -0
- data/lib/eligible/errors/api_error.rb +4 -0
- data/lib/eligible/errors/authentication_error.rb +4 -0
- data/lib/eligible/errors/eligible_error.rb +20 -0
- data/lib/eligible/json.rb +21 -0
- data/lib/eligible/plan.rb +42 -0
- data/lib/eligible/service.rb +59 -0
- data/lib/eligible/util.rb +109 -0
- data/lib/eligible/version.rb +3 -0
- data/lib/eligible/webhook.rb +16 -0
- data/lib/eligible.rb +218 -0
- data/test/test_eligible.rb +344 -0
- data/test/test_helper.rb +87 -0
- metadata +144 -0
data/.gitignore
ADDED
data/CONTRIBUTORS
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Andy Brett <andy@andybrett.com>
|
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Eligible
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
# Eligible
|
|
2
|
+
|
|
3
|
+
Ruby bindings for the [Eligible API](https://eligibleapi.com/rest-api-v1)
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'eligible'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself with:
|
|
16
|
+
|
|
17
|
+
$ gem install eligible
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Setup
|
|
22
|
+
require 'eligible'
|
|
23
|
+
Eligible.api_key = YOUR_KEY
|
|
24
|
+
|
|
25
|
+
### Format
|
|
26
|
+
|
|
27
|
+
Include `{ :format => "X12" }` in the params hash to get back the raw X12 response.
|
|
28
|
+
|
|
29
|
+
### Retrieve Plan object and query it
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
params = {
|
|
33
|
+
:payer_name => "Aetna",
|
|
34
|
+
:payer_id => "000001",
|
|
35
|
+
:provider_last_name => "Last",
|
|
36
|
+
:provider_first_name => "First",
|
|
37
|
+
:provider_npi => "12345678",
|
|
38
|
+
:member_id => "12345678",
|
|
39
|
+
:member_last_name => "Austen",
|
|
40
|
+
:member_first_name => "Jane",
|
|
41
|
+
:member_dob => "1955-12-14"
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
plan = Eligible::Plan.get(params)
|
|
45
|
+
plan.all # returns all fields on the plan, per the plan/all endpoint
|
|
46
|
+
plan.status # returns status fields on the plan, per the plan/status endpoint
|
|
47
|
+
## Etc.: plan.deductible, plan.dates, plan.balance, plan.stop_loss
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Retrieve Service object and query it
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
params = {
|
|
54
|
+
:payer_name => "Aetna",
|
|
55
|
+
:payer_id => "000001",
|
|
56
|
+
:provider_last_name => "Last",
|
|
57
|
+
:provider_first_name => "First",
|
|
58
|
+
:provider_npi => "12345678",
|
|
59
|
+
:member_id => "12345678",
|
|
60
|
+
:member_last_name => "Austen",
|
|
61
|
+
:member_first_name => "Jane",
|
|
62
|
+
:member_dob => "1955-12-14"
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
service = Eligible::Service.get(params)
|
|
66
|
+
service.all # returns all fields for the service, per service/all
|
|
67
|
+
service.visits # returns the visits for the service, per service/visits
|
|
68
|
+
## Etc.: service.copayment, service.coinsurance, service.deductible
|
|
69
|
+
|
|
70
|
+
## The endpoints 'general' and 'list' have a slightly different syntax than the others:
|
|
71
|
+
json = Eligible::Service.general(params)
|
|
72
|
+
json = Eligible::Service.list(params)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Retrieve Demographic object and query it
|
|
76
|
+
|
|
77
|
+
```ruby
|
|
78
|
+
params = {
|
|
79
|
+
:payer_name => "Aetna",
|
|
80
|
+
:payer_id => "000001",
|
|
81
|
+
:provider_last_name => "Last",
|
|
82
|
+
:provider_first_name => "First",
|
|
83
|
+
:provider_npi => "12345678",
|
|
84
|
+
:member_id => "12345678",
|
|
85
|
+
:member_last_name => "Austen",
|
|
86
|
+
:member_first_name => "Jane",
|
|
87
|
+
:member_dob => "1955-12-14"
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
demographic = Eligible::Demographic.get(params)
|
|
91
|
+
demographic.all # returns all fields for the demographic, per demographic/all
|
|
92
|
+
demographic.zip # returns the patient's zip code, per demographic/zip
|
|
93
|
+
## Etc.: demographic.employer, demographic.address, demographic.dob
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Retrieve Claim object
|
|
97
|
+
|
|
98
|
+
```ruby
|
|
99
|
+
params = {
|
|
100
|
+
:payer_name => "Aetna",
|
|
101
|
+
:payer_id => "000001",
|
|
102
|
+
:information_receiver_organization_name => "Organization",
|
|
103
|
+
:information_receiver_last_name => "Last",
|
|
104
|
+
:information_receiver_first_name => "First",
|
|
105
|
+
:information_receiver_etin => "12345678",
|
|
106
|
+
:provider_organization_name => "Marshall Group",
|
|
107
|
+
:provider_last_name => "Last",
|
|
108
|
+
:provider_first_name => "First",
|
|
109
|
+
:provider_npi => "12345678",
|
|
110
|
+
:provider_tax_id => "12345678",
|
|
111
|
+
:member_id => "12345678",
|
|
112
|
+
:member_last_name => "Last",
|
|
113
|
+
:member_first_name => "First",
|
|
114
|
+
:member_dob => "1955-12-14",
|
|
115
|
+
:dependent_last_name => "Last",
|
|
116
|
+
:dependent_first_name => "First",
|
|
117
|
+
:dependent_dob => "1975-12-14",
|
|
118
|
+
:dependent_gender => "M",
|
|
119
|
+
:trace_number => "12345",
|
|
120
|
+
:claim_control_number => "67890",
|
|
121
|
+
:claim_charge_amount => "45.00",
|
|
122
|
+
:claim_start_date => "2013-01-05",
|
|
123
|
+
:claim_end_date => "2013-01-05"
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
claim = Eligible::Claim.get(params)
|
|
127
|
+
claim.status # Returns in real time the status (paid, not paid, rejected, denied, etc) of claim specified.
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Post Enrollment object
|
|
131
|
+
|
|
132
|
+
```ruby
|
|
133
|
+
params = {
|
|
134
|
+
"provider_list" => [
|
|
135
|
+
{
|
|
136
|
+
"facility_name" => "Quality",
|
|
137
|
+
"provider_name" => "Jane Austen",
|
|
138
|
+
"tax_id" => "12345678",
|
|
139
|
+
"address" => "125 Snow Shoe Road",
|
|
140
|
+
"city" => "Sacramento",
|
|
141
|
+
"state" => "CA",
|
|
142
|
+
"zip" => "94107",
|
|
143
|
+
"ptan" => "54321",
|
|
144
|
+
"npi" => "987654321"
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"facility_name" => "Aetna",
|
|
148
|
+
"provider_name" => "Jack Austen",
|
|
149
|
+
"tax_id" => "12345678",
|
|
150
|
+
"address" => "985 Snow Shoe Road",
|
|
151
|
+
"city" => "Menlo Park",
|
|
152
|
+
"state" => "CA",
|
|
153
|
+
"zip" => "94107",
|
|
154
|
+
"ptan" => "54321",
|
|
155
|
+
"npi" => "987654321"
|
|
156
|
+
}
|
|
157
|
+
],
|
|
158
|
+
"payer_ids" => [
|
|
159
|
+
"00431",
|
|
160
|
+
"00282"
|
|
161
|
+
]
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
Eligible::Enrollment.post(params)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Retrieve Enrollment object
|
|
168
|
+
|
|
169
|
+
```ruby
|
|
170
|
+
params = { "enrollment_request_id" => "123" }
|
|
171
|
+
|
|
172
|
+
enrollment = Eligible::Enrollment.get(params)
|
|
173
|
+
enrollment.status # returns the status of the request to enroll the provider(s)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Retrieve Coverage object
|
|
177
|
+
|
|
178
|
+
```ruby
|
|
179
|
+
params = {
|
|
180
|
+
:service_type => "33",
|
|
181
|
+
:network => "OUT",
|
|
182
|
+
:payer_id => "000001",
|
|
183
|
+
:provider_last_name => "Last",
|
|
184
|
+
:provider_first_name => "First",
|
|
185
|
+
:provider_npi => "12345678",
|
|
186
|
+
:member_id => "12345678",
|
|
187
|
+
:member_last_name => "Austen",
|
|
188
|
+
:member_first_name => "Jane",
|
|
189
|
+
:member_dob => "1955-12-14"
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
coverage = Eligible::Coverage.get(params)
|
|
193
|
+
coverage.all # returns all coverage info for the request
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Post Claim object
|
|
197
|
+
|
|
198
|
+
```ruby
|
|
199
|
+
params = {
|
|
200
|
+
"api_key": "asdfsdfsd21132ddsfsdfd",
|
|
201
|
+
"receiver": {
|
|
202
|
+
"name": "AETNA",
|
|
203
|
+
"id": "60054"
|
|
204
|
+
},
|
|
205
|
+
"billing_provider": {
|
|
206
|
+
"taxonomy_code": "332B00000X",
|
|
207
|
+
"practice_name": "Jane Austen Practice",
|
|
208
|
+
"npi": "1922222222",
|
|
209
|
+
"address": {
|
|
210
|
+
"street_line_1": "419 Fulton",
|
|
211
|
+
"street_line_2": "",
|
|
212
|
+
"city": "San Francisco",
|
|
213
|
+
"state": "CA",
|
|
214
|
+
"zip": "94102"
|
|
215
|
+
},
|
|
216
|
+
"tin": "43291023",
|
|
217
|
+
"insurance_provider_id": "129873210"
|
|
218
|
+
},
|
|
219
|
+
"pay_to_provider": {
|
|
220
|
+
"address": {
|
|
221
|
+
"street_line_1": "",
|
|
222
|
+
"street_line_2": "",
|
|
223
|
+
"city": "",
|
|
224
|
+
"state": "",
|
|
225
|
+
"zip": ""
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
"subscriber": {
|
|
229
|
+
"last_name": "Franklin",
|
|
230
|
+
"first_name": "Benjamin",
|
|
231
|
+
"member_id": "W2832032427",
|
|
232
|
+
"group_id": "455716",
|
|
233
|
+
"group_name": "none",
|
|
234
|
+
"dob": "1734-05-04",
|
|
235
|
+
"gender": "M",
|
|
236
|
+
"address": {
|
|
237
|
+
"street_line_1": "435 Sugar Lane",
|
|
238
|
+
"street_line_2": "",
|
|
239
|
+
"city": "Sweet",
|
|
240
|
+
"state": "OH",
|
|
241
|
+
"zip": "436233127"
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
"payer": {
|
|
245
|
+
"name": "AETNA",
|
|
246
|
+
"id": "60054",
|
|
247
|
+
"address": {
|
|
248
|
+
"street_line_1": "Po Box 981106",
|
|
249
|
+
"street_line_2": "",
|
|
250
|
+
"city": "El Paso",
|
|
251
|
+
"state": "TX",
|
|
252
|
+
"zip": "799981222"
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
"dependent": {
|
|
256
|
+
"relationship": "",
|
|
257
|
+
"last_name": "",
|
|
258
|
+
"first_name": "",
|
|
259
|
+
"dob": "",
|
|
260
|
+
"gender": "",
|
|
261
|
+
"address": {
|
|
262
|
+
"street_line_1": "",
|
|
263
|
+
"street_line_2": "",
|
|
264
|
+
"city": "",
|
|
265
|
+
"state": "",
|
|
266
|
+
"zip": ""
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
"claim": {
|
|
270
|
+
"claim_number": "412",
|
|
271
|
+
"total_charge_amount": "275",
|
|
272
|
+
"claim_frequency": "1",
|
|
273
|
+
"patient_signature_on_file": "Y",
|
|
274
|
+
"provider_plan_participation": "A",
|
|
275
|
+
"direct_payment_authorized": "Y",
|
|
276
|
+
"release_of_information": "I",
|
|
277
|
+
"service_lines": [
|
|
278
|
+
{
|
|
279
|
+
"line_number": "1",
|
|
280
|
+
"place_of_service": "11",
|
|
281
|
+
"charge_amount": "275",
|
|
282
|
+
"product_service": "99213",
|
|
283
|
+
"qualifier": "HC",
|
|
284
|
+
"description": "",
|
|
285
|
+
"modifier_1": "",
|
|
286
|
+
"modifier_2": "",
|
|
287
|
+
"modifier_3": "",
|
|
288
|
+
"modifier_4": "",
|
|
289
|
+
"diagnosis_1": "32723",
|
|
290
|
+
"diagnosis_2": "",
|
|
291
|
+
"diagnosis_3": "",
|
|
292
|
+
"diagnosis_4": "",
|
|
293
|
+
"service_start": "2013-03-07",
|
|
294
|
+
"service_end": "2013-03-07",
|
|
295
|
+
"authorization_code": ""
|
|
296
|
+
}
|
|
297
|
+
]
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
Eligible::Claim.post(params)
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### Retrieve all Claim objects/acknowledgments
|
|
305
|
+
|
|
306
|
+
```ruby
|
|
307
|
+
claims = Eligible::Claim.all # returns status information for all claims that have been submitted with the API key
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### Retrieve individual Claim object/acknowledgment
|
|
311
|
+
|
|
312
|
+
```ruby
|
|
313
|
+
params = {
|
|
314
|
+
:response_id => "12345"
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
claim = Eligible::Claim.get(params) # returns status information on an individual claim
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## Tests
|
|
321
|
+
|
|
322
|
+
You can run tests with
|
|
323
|
+
|
|
324
|
+
```ruby
|
|
325
|
+
rake test
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
If you do send a pull request, please add passing tests for the new feature/fix.
|
|
329
|
+
|
|
330
|
+
## Contributing
|
|
331
|
+
|
|
332
|
+
1. Fork it
|
|
333
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
334
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
335
|
+
4. Run tests (see above)
|
|
336
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
|
337
|
+
6. Create new Pull Request
|
|
338
|
+
|
|
339
|
+
## Changelog
|
|
340
|
+
|
|
341
|
+
#### 1.1
|
|
342
|
+
|
|
343
|
+
- Additional endpoints for service/general and service/list
|
|
344
|
+
- Support x12 format in params
|
|
345
|
+
|
|
346
|
+
#### 1.0
|
|
347
|
+
|
|
348
|
+
- Initial release
|
data/Rakefile
ADDED
data/eligible.gemspec
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'eligible/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |gem|
|
|
7
|
+
gem.name = "eligible"
|
|
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'
|
|
12
|
+
gem.summary = 'Ruby wrapper for the Eligible API'
|
|
13
|
+
gem.homepage = "https://eligibleapi.com/"
|
|
14
|
+
gem.license = "MIT"
|
|
15
|
+
|
|
16
|
+
gem.files = `git ls-files`.split($/)
|
|
17
|
+
# gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
18
|
+
gem.test_files = `git ls-files -- test/*`.split("\n")
|
|
19
|
+
gem.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
gem.add_development_dependency('mocha')
|
|
22
|
+
gem.add_development_dependency('shoulda')
|
|
23
|
+
gem.add_development_dependency('test-unit')
|
|
24
|
+
gem.add_development_dependency('rake')
|
|
25
|
+
|
|
26
|
+
gem.add_dependency('rest-client', '~> 1.4')
|
|
27
|
+
gem.add_dependency('multi_json', '>= 1.0.4', '< 2')
|
|
28
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Eligible
|
|
2
|
+
class APIResource < EligibleObject
|
|
3
|
+
def self.class_name
|
|
4
|
+
self.name.split('::')[-1]
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.url()
|
|
8
|
+
if self == APIResource
|
|
9
|
+
raise NotImplementedError.new('APIResource is an abstract class. You should perform actions on its subclasses (Plan, Service, etc.)')
|
|
10
|
+
end
|
|
11
|
+
"/#{CGI.escape(class_name.downcase)}/all.json"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Eligible
|
|
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
|
+
|
|
8
|
+
def self.post(params, api_key=nil)
|
|
9
|
+
response, api_key = Eligible.request(:get, "/claims.json", api_key, params)
|
|
10
|
+
Util.convert_to_eligible_object(response, api_key)
|
|
11
|
+
end
|
|
12
|
+
|
|
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
|
+
end
|
|
17
|
+
|
|
18
|
+
def status
|
|
19
|
+
error ? nil : to_hash
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Eligible
|
|
2
|
+
|
|
3
|
+
class Coverage < APIResource
|
|
4
|
+
|
|
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
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module Eligible
|
|
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
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
module Eligible
|
|
2
|
+
|
|
3
|
+
class EligibleObject
|
|
4
|
+
include Enumerable
|
|
5
|
+
|
|
6
|
+
attr_accessor :api_key
|
|
7
|
+
attr_accessor :eligible_id
|
|
8
|
+
@@permanent_attributes = Set.new([:api_key, :error, :balance, :address, :dob])
|
|
9
|
+
|
|
10
|
+
# The default :id method is deprecated and isn't useful to us
|
|
11
|
+
if method_defined?(:id)
|
|
12
|
+
undef :id
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def initialize(id=nil, api_key=nil)
|
|
16
|
+
@api_key = api_key
|
|
17
|
+
@values = {}
|
|
18
|
+
# This really belongs in APIResource, but not putting it there allows us
|
|
19
|
+
# to have a unified inspect method
|
|
20
|
+
@unsaved_values = Set.new
|
|
21
|
+
@transient_values = Set.new
|
|
22
|
+
self.eligible_id = id if id
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.construct_from(values, api_key=nil)
|
|
26
|
+
obj = self.new(values[:eligible_id], api_key)
|
|
27
|
+
obj.refresh_from(values, api_key)
|
|
28
|
+
obj
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def refresh_from(values, api_key, partial=false)
|
|
32
|
+
@api_key = api_key
|
|
33
|
+
|
|
34
|
+
removed = partial ? Set.new : Set.new(@values.keys - values.keys)
|
|
35
|
+
added = Set.new(values.keys - @values.keys)
|
|
36
|
+
# Wipe old state before setting new. This is useful for e.g. updating a
|
|
37
|
+
# customer, where there is no persistent card parameter. Mark those values
|
|
38
|
+
# which don't persist as transient
|
|
39
|
+
|
|
40
|
+
instance_eval do
|
|
41
|
+
remove_accessors(removed)
|
|
42
|
+
add_accessors(added)
|
|
43
|
+
end
|
|
44
|
+
removed.each do |k|
|
|
45
|
+
@values.delete(k)
|
|
46
|
+
@transient_values.add(k)
|
|
47
|
+
@unsaved_values.delete(k)
|
|
48
|
+
end
|
|
49
|
+
values.each do |k, v|
|
|
50
|
+
@values[k] = v#Util.convert_to_eligible_object(v, api_key)
|
|
51
|
+
@transient_values.delete(k)
|
|
52
|
+
@unsaved_values.delete(k)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def [](k)
|
|
57
|
+
k = k.to_sym if k.kind_of?(String)
|
|
58
|
+
@values[k]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def []=(k, v)
|
|
62
|
+
send(:"#{k}=", v)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def keys
|
|
66
|
+
@values.keys
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def values
|
|
70
|
+
@values.values
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def to_json(*a)
|
|
74
|
+
Eligible::JSON.dump(@values)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def to_hash
|
|
78
|
+
@values
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def each(&blk)
|
|
82
|
+
@values.each(&blk)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def error
|
|
86
|
+
keys.include?(:error) ? @values[:error] : nil
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
protected
|
|
90
|
+
|
|
91
|
+
def metaclass
|
|
92
|
+
class << self; self; end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def remove_accessors(keys)
|
|
96
|
+
metaclass.instance_eval do
|
|
97
|
+
keys.each do |k|
|
|
98
|
+
next if @@permanent_attributes.include?(k)
|
|
99
|
+
k_eq = :"#{k}="
|
|
100
|
+
remove_method(k) if method_defined?(k)
|
|
101
|
+
remove_method(k_eq) if method_defined?(k_eq)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def add_accessors(keys)
|
|
107
|
+
metaclass.instance_eval do
|
|
108
|
+
keys.each do |k|
|
|
109
|
+
next if @@permanent_attributes.include?(k)
|
|
110
|
+
k_eq = :"#{k}="
|
|
111
|
+
define_method(k) { @values[k] }
|
|
112
|
+
define_method(k_eq) do |v|
|
|
113
|
+
@values[k] = v
|
|
114
|
+
@unsaved_values.add(k)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Eligible
|
|
2
|
+
|
|
3
|
+
class Enrollment < APIResource
|
|
4
|
+
|
|
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
|
|
9
|
+
|
|
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
|
|
14
|
+
|
|
15
|
+
def all
|
|
16
|
+
error ? nil : to_hash
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|