# ONEAccess for Ruby This is a ruby gem that wraps the ONEAccess API in an easy to use ruby library, so the API can be accesses transparently by invoking methods. The full documentation about the ONEAccess API can be found at: http://apidocs.oneaccess.io/docs Currently, only the version `v1.1` is supported by this gem. ## Installation & Setup Install the gem directly: ``` gem install oneaccess ``` or add it to your `Gemfile`: ``` gem 'oneaccess' ``` The gem must be initialized with the API keys. If it's being used in a Rails project, then the file `/config/initializers/oneaccess.rb` should be created: ```ruby ONEAccess.configure do |config| config.api_key = 'API_KEY_HERE' config.master_api_key = 'MASTER_API_KEY_HERE' end ``` ## Tests The tests are written in RSpec. Run the `rspec` in the root directory of the project. A coverage report is automatically generated and stored under `/coverage`. ## Documentation The API and data model has been converted into ruby modules and classes following the same organization as defined in the OA documentation, but adapted to the ruby convetions (underscored instead of camelCase). Therefore, by reading the official documentation you can easily infer what the ruby API will look like. Not all the methods in the API are currently supported, here's a list of all suported calls: - User by Email: _/user/getByEmail_ - Research Document: _/research/document_ - Research Document by User ID: _/research/documentByUserId_ - Organization's Product Groups: _/entitlement/organization/productgroup/getList_ - User's Product Groups: _/entitlement/user/productgroup/getList_ ### User by Email _(/user/getByEmail)_ Official Documentation: http://apidocs.oneaccess.io/docs/usergetorcreate This method returns a `User` object if it matches the first name, last name, and email. If there's not a match, then a new user is created and returned. #### How to use: ```ruby resp = ONEAccess::API::User.getByEmail(first_name: 'Alex', last_name: 'Santos', email: 'alex@ae.com') resp.data #=> instance of ONEAcess::DataObject::User resp.data.id #=> 305 (id of the user) resp.data.organization.id #=> 805 (id of the company) resp.data.email #=> alex@ae.com ``` ### Research Document _(/research/document)_ Official Documentation: http://apidocs.oneaccess.io/docs/researchdocument This method retrieves a research document by providing the research ID and the first name, last name, and email of the user requesting access. If the user does not have access to the research, a `ONEAccess::Error:APIError` exception will be raisen. #### How to use: ```ruby begin resp = ONEAccess::API::Research.document(document_id: 2341, first_name: 'Alex', last_name: 'Santos', email: 'alex@ae.com') resp.data #=> instance of ONEAcess::DataObject::ResearchDocumentInfo resp.data.url #=> url of the document resp.data.title #=> document's title resp.data.saml #=> instance of ONEAccess::DataObject::SAMLInfo puts "requires SAML" unless resp.data.saml.nil? rescue ONEAccess::Error::APIError => e if e.api_status_code == ONEAccess::APIStatusCode::OBJECT_NOT_FOUND puts "Not entitled or does not exist" end end ``` ### Research Document by User ID _(/research/documentByUserId)_ Official Documentation: http://apidocs.oneaccess.io/docs/researchdocumentbyuserid Similar to the previous method, this method retrieves a research document by providing the research ID, but together with the user's ID instead. If the user does not have access to the research, a `ONEAccess::Error:APIError` exception will be raisen. #### How to use: ```ruby begin resp = ONEAccess::API::Research.document_by_user_id(document_id: 2341, user_id: 805) resp.data #=> instance of ONEAcess::DataObject::ResearchDocumentInfo resp.data.url #=> url of the document resp.data.title #=> document's title resp.data.saml #=> instance of ONEAccess::DataObject::SAMLInfo puts "requires SAML" unless resp.data.saml.nil? rescue ONEAccess::Error::APIError => e if e.api_status_code == ONEAccess::APIStatusCode::OBJECT_NOT_FOUND puts "Not entitled or does not exist" end end ```