IOT Services
A Ruby library that provides access to the IOT EVOlens API.
Installation
You know, the usual:
gem 'iot_services'
ECP Usage
First, you must instantiate the API client:
evolens = IOTServices::Evolens::Client.new(
base_url: ENV['EVOLENS_BASE_URL'],
client_id: ENV['EVOLENS_ECP_CLIENT_ID'],
client_secret: ENV['EVOLENS_ECP_CLIENT_SECRET'],
# http_opts: {logger: Logger.new(STDOUT)}
)
Then, you can create a new wearer:
response = evolens.new_wearer(
userEmail: ENV['EVOLENS_ECP_EMAIL'],
wearerId: '[email protected]',
wearerCode: '[email protected]',
wearerEmail: '[email protected]',
gender: 'MALE',
birthYear: '1982',
locationCode: '28007',
termsAndConditions: 'Y',
rightEyePrescription: {sph: '+0.00', cyl: '-0.00', axis: '00º', add: '+1.00'},
leftEyePrescription: {sph: '+0.00', cyl: '-0.00', axis: '00º', add: '+1.00'},
labCode: 'OPTICALAB',
languageCode: 'es'
)
And also send its lifestyle questionary:
response = evolens.new_questionary(
orderId: response[:orderId],
activities: [
{name: 'DRIVE', frequency: 'DURATION_A_LITTLE', isTopOne: false},
{name: 'READ', frequency: 'DURATION_ZERO', isTopOne: false},
{name: 'COMPUTER', frequency: 'DURATION_A_LOT', isTopOne: false},
{name: 'OFFICE', frequency: 'DURATION_A_LOT', isTopOne: false},
{name: 'RETAIL', frequency: 'DURATION_A_LOT', isTopOne: true}
]
)
Finally, in the response you may find the EVOlens ID:
response['orderCode'] # => "9772005ZRN87"
Listing Providers and Designs
evolens.get_providers_and_designs
# => [{'ProviderName' => 'P1', 'Designs' => ['D1', 'D2', ...]}, ...]
Authentication and Authorization
These steps are done automatically the first time a request to the API is executed, and then the authorization token is cached. So it's recommended that you reuse the client instance on every request.
However, if you want to explicitly do this, you can call the login
method.
In addition, when the authorization token expires, a new one it automatically requested on the next API call.
ECP Registration
The API is a bit convoluted on this subject. It requires another set of secrets for an admin role, an additional login request, and finally, the ECP registration is done in two steps: First, an ECP "placeholder" must be created with the admin role, and then its credentials are associated with an ECP role.
Consequently, you'll need two client instances to make this happen:
adm = IOTServices::Evolens::Client.new(
base_url: ENV['EVOLENS_BASE_URL'],
client_id: ENV['EVOLENS_ADMIN_CLIENT_ID'],
client_secret: ENV['EVOLENS_ADMIN_CLIENT_SECRET'],
admin_credentials: {
email: ENV['EVOLENS_ADMIN_EMAIL'],
password: ENV['EVOLENS_ADMIN_PASSWORD']
}
)
ecp = IOTServices::Evolens::Client.new(
base_url: ENV['EVOLENS_BASE_URL'],
client_id: ENV['EVOLENS_ECP_CLIENT_ID'],
client_secret: ENV['EVOLENS_ECP_CLIENT_SECRET']
)
Finally, you must call these two methods to complete the process:
adm.create_ecp(
store_id: 'THE_STORE_ID',
ecp_code: 'THE_ECP_CODE'
)
ecp.register_ecp(
store_code: 'THE_STORE_CODE',
ecp_code: 'THE_ECP_CODE',
email: 'SOME_EMAIL',
password: 'SOME_PASSWORD'
)
If they don't throw any errors it means everything went well.
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
Contributing
Bug reports and pull requests are welcome!