noyo 0.1.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.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +57 -0
  3. data/.codecov.yml +13 -0
  4. data/.gitignore +12 -0
  5. data/.rspec +3 -0
  6. data/.rubocop.yml +73 -0
  7. data/.ruby-version +1 -0
  8. data/CODE_OF_CONDUCT.md +74 -0
  9. data/Gemfile +4 -0
  10. data/Gemfile.lock +89 -0
  11. data/README.md +176 -0
  12. data/Rakefile +6 -0
  13. data/bin/console +7 -0
  14. data/bin/setup +8 -0
  15. data/lib/noyo.rb +3 -0
  16. data/lib/noyo_accounts.rb +4 -0
  17. data/lib/noyo_accounts/client.rb +6 -0
  18. data/lib/noyo_accounts/client/services.rb +8 -0
  19. data/lib/noyo_accounts/client/services/auth_service.rb +45 -0
  20. data/lib/noyo_api.rb +6 -0
  21. data/lib/noyo_api/api.rb +13 -0
  22. data/lib/noyo_api/client.rb +9 -0
  23. data/lib/noyo_api/client/services.rb +8 -0
  24. data/lib/noyo_api/client/services/base_service.rb +37 -0
  25. data/lib/noyo_api/client/user_agent.rb +15 -0
  26. data/lib/noyo_api/client/version.rb +5 -0
  27. data/lib/noyo_api/configuration.rb +28 -0
  28. data/lib/noyo_fulfillment.rb +5 -0
  29. data/lib/noyo_fulfillment/api_response.rb +32 -0
  30. data/lib/noyo_fulfillment/models.rb +25 -0
  31. data/lib/noyo_fulfillment/models/api_resource.rb +191 -0
  32. data/lib/noyo_fulfillment/models/api_resource_collection.rb +41 -0
  33. data/lib/noyo_fulfillment/models/base_model.rb +115 -0
  34. data/lib/noyo_fulfillment/models/contact.rb +19 -0
  35. data/lib/noyo_fulfillment/models/demographic_change.rb +8 -0
  36. data/lib/noyo_fulfillment/models/dependent.rb +15 -0
  37. data/lib/noyo_fulfillment/models/employee.rb +108 -0
  38. data/lib/noyo_fulfillment/models/group.rb +25 -0
  39. data/lib/noyo_fulfillment/models/group_enrollment.rb +20 -0
  40. data/lib/noyo_fulfillment/models/group_plans.rb +15 -0
  41. data/lib/noyo_fulfillment/models/group_plans/add.rb +11 -0
  42. data/lib/noyo_fulfillment/models/group_plans/base.rb +22 -0
  43. data/lib/noyo_fulfillment/models/group_plans/dental.rb +13 -0
  44. data/lib/noyo_fulfillment/models/group_plans/life.rb +11 -0
  45. data/lib/noyo_fulfillment/models/group_plans/long_term_disability.rb +11 -0
  46. data/lib/noyo_fulfillment/models/group_plans/medical.rb +12 -0
  47. data/lib/noyo_fulfillment/models/group_plans/short_term_disability.rb +11 -0
  48. data/lib/noyo_fulfillment/models/group_plans/vision.rb +11 -0
  49. data/lib/noyo_fulfillment/models/individual_enrollment.rb +32 -0
  50. data/lib/noyo_fulfillment/models/location.rb +16 -0
  51. data/lib/noyo_fulfillment/models/member_request.rb +40 -0
  52. data/lib/noyo_fulfillment/models/member_transaction.rb +27 -0
  53. data/lib/noyo_fulfillment/models/mixins.rb +9 -0
  54. data/lib/noyo_fulfillment/models/mixins/has_person.rb +29 -0
  55. data/lib/noyo_fulfillment/models/mixins/nested_under.rb +64 -0
  56. data/lib/noyo_fulfillment/models/new_hire.rb +7 -0
  57. data/lib/noyo_fulfillment/models/open_enrollment.rb +7 -0
  58. data/lib/noyo_fulfillment/models/person.rb +18 -0
  59. data/lib/noyo_fulfillment/models/qualifying_life_event.rb +8 -0
  60. data/lib/noyo_fulfillment/models/termination.rb +9 -0
  61. data/noyo.gemspec +47 -0
  62. metadata +232 -0
@@ -0,0 +1,41 @@
1
+ # Used for pluralize
2
+ require 'active_support/inflector'
3
+ require 'httparty'
4
+
5
+ module NoyoFulfillment
6
+ class ApiResourceCollection < NoyoFulfillment::BaseModel
7
+ attr_accessor :records, :page_number
8
+
9
+ delegate :map, to: :records
10
+ delegate :each, to: :records
11
+ delegate :detect, to: :records
12
+
13
+ def initialize(records, page_number = 0)
14
+ @records = records
15
+ @page_number = page_number
16
+ super(records: records, page_number: page_number)
17
+ end
18
+
19
+ def next_page
20
+ raise "Invalid number of records: #{records.size}" if !records.size.positive?
21
+
22
+ klass = records.first.class
23
+ next_page_number = page_number + 1
24
+ klass.all(next_page_number)
25
+ end
26
+
27
+ def [](key)
28
+ records[key]
29
+ end
30
+
31
+ def first
32
+ records.first
33
+ end
34
+
35
+ def size
36
+ records.size
37
+ end
38
+ alias count size
39
+ alias length size
40
+ end
41
+ end
@@ -0,0 +1,115 @@
1
+ module NoyoFulfillment
2
+ class BaseModel
3
+ def self.class_name
4
+ name.split('::')[-1]
5
+ end
6
+
7
+ def initialize(options = nil)
8
+ return if options.nil?
9
+
10
+ options.keys.each do |key|
11
+ if respond_to?("#{key}=")
12
+ send("#{key}=", options[key])
13
+ end
14
+ end
15
+ end
16
+
17
+ def inspect
18
+ string = "#<#{self.class.name}:#{object_id} "
19
+ fields = []
20
+
21
+ id_field = :@id
22
+ if instance_variables.include?(id_field)
23
+ fields << "#{id_field}: #{send(:id)}"
24
+ end
25
+ non_id_fields = instance_variables.reject{ |x| x == id_field }
26
+ fields += non_id_fields.map{ |field| "#{field}: #{send(field.to_s.tr('@', ''))}" }
27
+ string << fields.join(', ') << '>'
28
+ end
29
+
30
+
31
+ # Probably should be overriden in a subclass, if there's any excluded
32
+ # attributes from API interaction
33
+ def excluded_attributes
34
+ [ ]
35
+ end
36
+
37
+ # only those that should be imported to and exported from the API
38
+ def synced_attributes
39
+ exclusions = excluded_attributes.dup
40
+ exclusions.map!{ |item| "@#{item}".to_sym }
41
+ instance_variables - exclusions
42
+ end
43
+
44
+ # Updates this instance's variables with cooresponding ones on the updated_resource object.
45
+ # Does so deeply.
46
+ def update_attrs(updated_resource)
47
+ attributes_set = synced_attributes.to_set
48
+ attributes_set.merge(updated_resource.synced_attributes)
49
+ attributes_set.each do |var|
50
+ str = var.to_s.gsub(/^@/, '')
51
+ if !respond_to?("#{str}=") ||
52
+ !updated_resource.respond_to?(str) ||
53
+ updated_resource.send(str).nil?
54
+ next
55
+ end
56
+
57
+ the_attr = send(str)
58
+
59
+ # get deep attrs, whether or not it's a part of an array
60
+ if the_attr.respond_to?(:update_attrs)
61
+ the_attr.update_attrs(updated_resource.send(str))
62
+ else
63
+ instance_variable_set(var, updated_resource.send(str))
64
+ end
65
+ end
66
+ end
67
+
68
+ # Returns a hash of settable attributes, including deep hashes of children
69
+ def attributes(options = {})
70
+ attrs = {}
71
+
72
+ synced_attributes.each do |var|
73
+ attr_name_str = var.to_s.gsub(/^@/, '')
74
+ next if !respond_to?(attr_name_str)
75
+
76
+ attr_value = send(attr_name_str)
77
+
78
+ # get deep attrs, whether or not it's a part of an array
79
+ if attr_value.respond_to?(:attributes)
80
+ attr_value = attr_value.attributes(options)
81
+ end
82
+
83
+ if attr_value.is_a?(Array)
84
+ attr_value = map_nested_attr(attr_value, options)
85
+ end
86
+
87
+ if !attr_value.nil?
88
+ attrs[attr_name_str.to_sym] = attr_value
89
+ end
90
+ end
91
+
92
+ attrs
93
+ end
94
+
95
+ def to_h
96
+ Hash[instance_variables.map{ |var| [ var.to_s[1..-1], instance_variable_get(var) ] }]
97
+ end
98
+
99
+ def ==(other)
100
+ !other.nil? && self.class.name == other.class.name && id == other.id
101
+ end
102
+
103
+ private
104
+
105
+ def map_nested_attr(the_attr, options)
106
+ the_attr.map do |inner_attr|
107
+ if inner_attr.respond_to?(:attributes)
108
+ inner_attr.attributes(options)
109
+ else
110
+ inner_attr
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,19 @@
1
+ module NoyoFulfillment
2
+ class Contact < NoyoFulfillment::ApiResource
3
+ include NoyoFulfillment::Mixins::NestedUnder
4
+ nested_under NoyoFulfillment::Group
5
+
6
+ attr_accessor(
7
+ :id,
8
+ :version,
9
+ :group_id,
10
+ :first_name,
11
+ :last_name,
12
+ :title,
13
+ :email,
14
+ :phone_number,
15
+ :types,
16
+ :primary_contact,
17
+ )
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ module NoyoFulfillment
2
+ class DemographicChange < NoyoFulfillment::BaseModel
3
+ attr_accessor(
4
+ :change_date,
5
+ :member_changes,
6
+ )
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ require 'active_support/core_ext/hash'
2
+
3
+ module NoyoFulfillment
4
+ class Dependent < NoyoFulfillment::ApiResource
5
+ include NoyoFulfillment::Mixins::HasPerson
6
+ include NoyoFulfillment::Mixins::NestedUnder
7
+ nested_under NoyoFulfillment::Employee
8
+
9
+ attr_accessor(
10
+ :id,
11
+ :relationship,
12
+ :employee_id,
13
+ )
14
+ end
15
+ end
@@ -0,0 +1,108 @@
1
+ require 'active_support/core_ext/hash'
2
+
3
+ module NoyoFulfillment
4
+ class Employee < NoyoFulfillment::ApiResource
5
+ include NoyoFulfillment::Mixins::HasPerson
6
+
7
+ attr_accessor(
8
+ :id,
9
+ :employment,
10
+ :group_id,
11
+ :location_id,
12
+ )
13
+
14
+ def individual_enrollments
15
+ IndividualEnrollment.all(employee_id: id)
16
+ end
17
+
18
+ def check_id!
19
+ if id.nil? || id.empty?
20
+ raise 'Must have an employee ID before creating a member request. Is this employee created?'
21
+ end
22
+ end
23
+
24
+ def new_hire_request_attrs(options = {})
25
+ check_id!
26
+
27
+ body = NoyoFulfillment::NewHire.new(options).attributes
28
+ {
29
+ employee_id: id,
30
+ body: body,
31
+ }
32
+ end
33
+
34
+ def termination_request_attrs(options = {})
35
+ check_id!
36
+
37
+ options.merge(employee_id: id)
38
+ body = NoyoFulfillment::Termination.new(options).attributes
39
+ {
40
+ employee_id: id,
41
+ body: body,
42
+ }
43
+ end
44
+
45
+ def demographic_change_request_attrs(options = {})
46
+ check_id!
47
+
48
+ options.merge(employee_id: id)
49
+ body = NoyoFulfillment::DemographicChange.new(options).attributes
50
+ {
51
+ employee_id: id,
52
+ body: body,
53
+ }
54
+ end
55
+
56
+ def open_enrollment_request_attrs(options = {})
57
+ check_id!
58
+
59
+ options.merge(employee_id: id)
60
+ body = NoyoFulfillment::OpenEnrollment.new(options).attributes
61
+ {
62
+ employee_id: id,
63
+ body: body,
64
+ }
65
+ end
66
+
67
+ def qualifying_life_event_request_attrs(options = {})
68
+ check_id!
69
+
70
+ options.merge(employee_id: id)
71
+ body = NoyoFulfillment::QualifyingLifeEvent.new(options).attributes
72
+ {
73
+ employee_id: id,
74
+ body: body,
75
+ }
76
+ end
77
+
78
+ def create_new_hire_request(options = {})
79
+ member_request_attrs = new_hire_request_attrs(options)
80
+ member_request = MemberRequest.new_hire_request(member_request_attrs)
81
+ member_request.create
82
+ end
83
+
84
+ def create_termination_request(options = {})
85
+ member_request_attrs = termination_request_attrs(options)
86
+ member_request = MemberRequest.termination_request(member_request_attrs)
87
+ member_request.create
88
+ end
89
+
90
+ def create_demographic_change_request(options = {})
91
+ member_request_attrs = demographic_change_request_attrs(options)
92
+ member_request = MemberRequest.demographic_request(member_request_attrs)
93
+ member_request.create
94
+ end
95
+
96
+ def create_open_enrollment_request(options = {})
97
+ member_request_attrs = open_enrollment_request_attrs(options)
98
+ member_request = MemberRequest.open_enrollment_request(member_request_attrs)
99
+ member_request.create
100
+ end
101
+
102
+ def create_qualifying_life_event_request(options = {})
103
+ member_request_attrs = qualifying_life_event_request_attrs(options)
104
+ member_request = MemberRequest.qualifying_life_event_request(member_request_attrs)
105
+ member_request.create
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,25 @@
1
+ module NoyoFulfillment
2
+ class Group < NoyoFulfillment::ApiResource
3
+ attr_accessor(
4
+ :id,
5
+ :version,
6
+ :created,
7
+ :modified,
8
+ :organization_id,
9
+ :name,
10
+ :sic_code,
11
+ )
12
+
13
+ def contacts
14
+ Contact.all(group_id: id)
15
+ end
16
+
17
+ def locations
18
+ Location.all(group_id: id)
19
+ end
20
+
21
+ def group_enrollments
22
+ GroupEnrollment.all(group_id: id)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ module NoyoFulfillment
2
+ class GroupEnrollment < NoyoFulfillment::ApiResource
3
+ include NoyoFulfillment::Mixins::NestedUnder
4
+ nested_under NoyoFulfillment::Group, required: false # Sometimes this is root level
5
+
6
+ attr_accessor(
7
+ :id,
8
+ :version,
9
+ :created,
10
+ :modified,
11
+ :group_id,
12
+ :carrier_id,
13
+ :line_of_coverage,
14
+ )
15
+
16
+ def plans
17
+ NoyoFulfillment::GroupPlans::Base.all(group_enrollment_id: id)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ require 'noyo_fulfillment/models/group_plans/base'
2
+ require 'noyo_fulfillment/models/group_plans/add'
3
+ require 'noyo_fulfillment/models/group_plans/dental'
4
+ require 'noyo_fulfillment/models/group_plans/life'
5
+ require 'noyo_fulfillment/models/group_plans/long_term_disability'
6
+ require 'noyo_fulfillment/models/group_plans/medical'
7
+ require 'noyo_fulfillment/models/group_plans/short_term_disability'
8
+ require 'noyo_fulfillment/models/group_plans/vision'
9
+
10
+ module NoyoFulfillment
11
+ module Models
12
+ module GroupPlans
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module NoyoFulfillment
2
+ module GroupPlans
3
+ class ADD < NoyoFulfillment::GroupPlans::Base
4
+ attr_accessor(
5
+ :plan_type,
6
+ :status,
7
+ :eligible_member_types,
8
+ )
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ module NoyoFulfillment
2
+ module GroupPlans
3
+ class Base < NoyoFulfillment::ApiResource
4
+ include NoyoFulfillment::Mixins::NestedUnder
5
+ nested_under NoyoFulfillment::GroupEnrollment
6
+
7
+ attr_accessor(
8
+ :id,
9
+ :version,
10
+ :group_enrollment_id,
11
+ :name,
12
+ :code,
13
+ :created,
14
+ :modified,
15
+ )
16
+
17
+ def self.resource_path_name
18
+ 'plans'
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ module NoyoFulfillment
2
+ module GroupPlans
3
+ class Dental < NoyoFulfillment::GroupPlans::Base
4
+ attr_accessor(
5
+ :plan_type,
6
+ :network,
7
+ :voluntary,
8
+ :status,
9
+ :eligible_member_types,
10
+ )
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module NoyoFulfillment
2
+ module GroupPlans
3
+ class Life < NoyoFulfillment::GroupPlans::Base
4
+ attr_accessor(
5
+ :plan_type,
6
+ :status,
7
+ :eligible_member_types,
8
+ )
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module NoyoFulfillment
2
+ module GroupPlans
3
+ class LongTermDisability < NoyoFulfillment::GroupPlans::Base
4
+ attr_accessor(
5
+ :plan_type,
6
+ :status,
7
+ :eligible_member_types,
8
+ )
9
+ end
10
+ end
11
+ end