Lifen
Lifen is a ruby client for Lifen JSON API.
Installation
Add this line to your application's Gemfile:
gem 'lifen'
And then execute:
$ bundle
Or install it yourself as:
$ gem install lifen
Usage
Configuration
Lifen can be configured (ideally inside an initializer) like so:
Lifen.configure do |config|
config.site = "https://develop.lifen.fr/"
config.application_access_token = "application_access_token"
# optionnal
config.proxy_url = "http://my.proxy.fr/"
config.expiration_margin = 60 # in seconds, default: 0
end
Optionnal configuration:
proxy_url
: enables you to route all your requests via a proxyexpiration_margin
: by default a token is considered valid until the expiration time but you can add a security expiration margin
Managing users
user = Lifen::User.new(email: "[email protected]", first_name: "Jean", last_name: "Dupont")
user.create
user.token.refresh
user.status.reload
other_user = Lifen::User.find("user_uuid")
other_user.first_name = "Marc"
other_user.save
other_user.reload
Creating a user in a threadsafe way
Assuming the lifen uuid
is stored on the User
model as lifen_uuid
, you can simply change the create
method to became threadsafe:
lifen_user.create(
persisted_lifen_uuid: ->(internal_user) {
user.reload
current_uuid = user.lifen_uuid
if current_uuid.blank?
nil
else
current_uuid
end
},
save_to_db: ->(lifen_user) {
user.lifen_uuid = lifen_user.uuid
user.save!
}
)
Managing users' settings
user.settings
user.settings.reload
user.settings.push_notifications
user.settings.push_notifications = false
user.settings.save
Refreshing a token in a threadsafe way
Depending on the OAuth provider strategy, the token refresh strategy has to be adapted. In our case, if token are stored in a database, you can ask the client to reload the token from your database value before performing a real refresh:
token.refresh_once_if_needed do |token|
current_user.reload
token.value = current_user.lifen_token
token.expires_at = current_user.lifen_token_expires_at.to_i
end
Managing flows
user = Lifen::User.new(uuid: "valid_uuid")
user.flows
flow = Lifen::Flow.new(user: user, title: "Honestica Rocks !")
flow.create
flow.attach_users(user)
flow.detach_users(user)
# alternate strategy
flow = Lifen::Flow.new(user: user, title: "honestica Rocks !", users: [user_1, user_2])
flow.create
Managing messages
= Lifen::Message.new(flow: flow, content: "Hello World !")
.create
Managing a Binary
binary = Lifen::Binary.new(uuid: "b7c7dae671b93e951ce6a4f530736276")
binary.download
Communications with an Attachment (FHIR)
sender = Lifen::User.find_by_rpps("899900018483")
recipient = Lifen::User.find_by_rpps("899900018484")
channel = recipient.channels.first
category = Lifen::Category.new(code: "MEDICAL_REPORT") # default case, optionnal element
= Lifen::Attachment.new(title: "Test document", path: "path/to/file")
patient = Lifen::Patient.new(first_name: "Jean", last_name: "Dupond", birthdate: Date.new(2000,1,1))
communication = Lifen::Communication.new(sender: sender, recipient: recipient, channel: channel, attachment: , patient: patient, category: category)
communication.send
communication = Lifen::Communication.find("valid-communication-uuid")
communication.status
Communications with a Binary (FHIR)
sender = Lifen::User.find_by_rpps("899900018483")
recipient = Lifen::User.find_by_rpps("899900018484")
channel = recipient.channels.first
binary = Lifen::Binary.new(uuid: "b7c7dae671b93e951ce6a4f530736276")
communication = Lifen::Communication.new(sender: sender, recipient: recipient, channel: channel, binary: binary, patient: patient, category: category)
communication.send
Custom Channels management
recipient = Lifen::User.new(uuid: "valid-user-uuid")
# To create a new mailing address channel
channel = recipient.create_address(type: "address", lines: ["39 rue Aboukir"], city: "Paris", postal_code: "75002", country: "France")
# To create a new telecom channel fax
channel = recipient.create_telecom(type: "telecom", system: "fax", value: "+33102030405")
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
License
The MIT License (MIT)
Copyright (c) 2016-2017 Honestica
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.