Noyo Fulfillment Ruby Library
A Ruby client for Noyo's Fulfillment Service API
Ruby Version
This client was written to target Ruby 2.6.3. Other version support not yet guaranteed.
Noyo API Docs
While using this client library, the Noyo API docs should be referenced for wider context. This will also give you a reference for things like validation and schemas, which this client library typically does not provide.
Installation
Add this line to your application's Gemfile:
gem 'noyo'
And then execute:
$ bundle
Or install it yourself as:
$ gem install noyo
REPL
During development of this library, run ./bin/console
for an irb REPL with this module included.
Usage
Configuration
Once you have a client ID and secret for your organization from Noyo, you can use it to configure your Noyo connection similar to the sample below. A sample tweak assuming you're running Rails is used below to give you an idea of a common usage.
NoyoApi::Api.configure do |config|
config.client_id = "" # your Noyo client ID
config.client_secret = "" # your Noyo client secret
if not Rails.env.production?
# For experimental development
config.fulfillment_base_uri = 'https://fulfillment-sandbox.noyoconnect.com'
end
end
If you'd like to debug the API calls being made, add a config.verbose = true
to the
configuration block. This will give you information on the underlying HTTPS calls being made.
Querying
#all
You can find all resources for a given model using the all
class method:
groups = NoyoFulfillment::Group.all
This will return a ApiResourceCollection
. This is a paginated collection. You can get the next
page of data easily:
more_groups = groups.next_page
#find
You can also just find one record for a model by ID:
group = NoyoFulfillment::Group.find('065f876d-d557-4019-8607-439b19235fa0')
Nested Resources
You can find nested resources using model helpers:
locations = group.locations # returns an ApiResourceCollection of locations
This is just syntactical sugar for:
locations = NoyoFulfillment::Location.all(group_id: group.id)
Creating data during development
You can take advantage of the FactoryBot factories built into this library, in order to speed up development time.
Create an employee
# Boilerplate to bring in factories. Could be used in a spec_helper,
# or other initialization code during the development phase.
require 'factory_bot'
FactoryBot.find_definitions
require 'faker'
groups = NoyoFulfillment::Group.all
group = groups.records.first # Find an appropriate group using this collection
locations = group.locations
location = locations.records.first
employee = FactoryBot.build(:employee, group_id: group.id, location_id: location.id)
employee = employee.create
All employee values not specified will be faked using the faker gem.
Create a dependent
Given an employee object returned from the API:
dependent = FactoryBot.build(:dependent, employee_id: employee.id)
dependent = dependent.create
Create a new hire request
Once an employee is created, you can use the model to enroll that employee into coverages:
new_hire = FactoryBot.build(:new_hire, employee_id: employee.id, carrier_id: '5d9cf3ac-ea6d-4035-a478-3b9839866a7b', dental_plan_id: 'bd90742f-f019-4a4b-b1d6-3038921e936b', vision_plan_id: 'bd90742f-f019-4a4b-b1d6-3038921e936b')
new_hire_request = employee.create_new_hire_request(new_hire.attributes)
Create a termination request
Given an employee object returned from the API:
termination = FactoryBot.build(:termination, employee_id: employee.id)
termination_request = employee.create_termination_request(termination.attributes)
Create a demographic change request
Given an employee object returned from the API:
demographic_change = FactoryBot.build(:demographic_change, member_type: 'employee', employee_id: employee.id)
demographic_change_request = employee.create_demographic_change_request(demographic_change.attributes)
Create an open enrollment request
Given an employee object returned from the API:
open_enrollment = FactoryBot.build(:open_enrollment, member_type: 'employee', employee_id: employee.id, carrier_id: '5d9cf3ac-ea6d-4035-a478-3b9839866a7b', dental_plan_id: 'bd90742f-f019-4a4b-b1d6-3038921e936b', vision_plan_id: 'bd90742f-f019-4a4b-b1d6-3038921e936b')
open_enrollment_request = employee.create_open_enrollment_request(open_enrollment.attributes)
Create a qualifying life event request
Given an employee object returned from the API:
= FactoryBot.build(:qualifying_life_event, member_type: 'employee', employee_id: employee.id, carrier_id: '5d9cf3ac-ea6d-4035-a478-3b9839866a7b', dental_plan_id: 'bd90742f-f019-4a4b-b1d6-3038921e936b', vision_plan_id: 'bd90742f-f019-4a4b-b1d6-3038921e936b')
= employee.(.attributes)