README.md in onfido-0.0.4 vs README.md in onfido-0.1.0

- old
+ new

@@ -1,13 +1,11 @@ # Onfido A wrapper for Onfido's [API](https://onfido.com/documentation#introduction). You should always refer to the documentation for valid API calls. -[![Build Status](https://snap-ci.com/hvssle/onfido/branch/master/build_image)](https://snap-ci.com/hvssle/onfido/branch/master) [![Gem Version](https://badge.fury.io/rb/onfido.svg)](http://badge.fury.io/rb/onfido) [![Build Status](https://travis-ci.org/hvssle/onfido.svg?branch=master)](https://travis-ci.org/hvssle/onfido) -[!['gitter room'][2]][1] [1]: https://gitter.im/hvssle/onfido [2]: https://badges.gitter.im/gitterHQ/developers.png @@ -28,17 +26,16 @@ $ gem install onfido ## Usage -There are 5 configuration options for Onfido, including your `api_key`, throwing exceptions for failed responses and logging the requests. By default, `throws_exceptions` is set to `true`. If set to `false` and Onfido responds with a valid JSON body the response body will be returned instead. +There are 4 configuration options for Onfido, including your `api_key`, timeout details and logging. ```ruby Onfido.configure do |config| config.api_key = 'MY_API_KEY' config.logger = Logger.new(STDOUT) - config.throws_exceptions = false config.open_timeout = 30 config.read_timeout = 80 end ``` @@ -50,11 +47,11 @@ ### Making calls to Onfido's resources All resources share the same interface when making API calls. For creating a resource you can use `.create`, for finding one `.find` and for fetching all records for a resource `.all`. -**Note:** *All param keys should be a symbol e.g. `{type: 'express', reports: [{name: 'identity'}]}`* +**Note:** *All param keys should be a symbol e.g. `{ type: 'express', reports: [{ name: 'identity' }] }`* ### Applicant To create an applicant, you can simply use @@ -78,21 +75,21 @@ ### Document To upload a document for an applicant, you can simply use ```ruby - api.document.create('applicant_id', {file: 'http://example.com', type: 'passport') + api.document.create('applicant_id', file: 'http://example.com', type: 'passport') ``` The file can both be a `File` object or a link to an image. ### Check To create a check for an applicant, you can simply use ```ruby - api.check.create('applicant_id', {type: 'express', reports: [{name: 'identity'}]}) + api.check.create('applicant_id', type: 'express', reports: [{ name: 'identity' }]) ``` To find an existing check for an applicant ```ruby @@ -145,26 +142,22 @@ api.check.all('applicant_id', page: 2, per_page: 10) ``` ## Error Handling -By default, Onfido will attempt to raise errors returned by the API automatically. +If you rescue `Onfido::RequestError`, you are provided with the response code, response body and parsed JSON body, the type of error the the fields that have errored. -If you set the `throws_exceptions` to false, it will simply return the response body. This allows you to handle errors manually. - -If you rescue `Onfido::RequestError`, you are provided with the error message itself as well as the type of error, response code and fields that have errored. Here's how you might do that: - ```ruby def create_applicant api.applicant.create(params) rescue Onfido::RequestError => e - e.type # returns 'validation_error' - e.fields # returns {"email": {"messages": ["invalid format"]} - e.response_code # returns '401' + e.type # => 'validation_error' + e.fields # => { "email": { "messages": ["invalid format"] } } + e.response_code # => '422' end ``` -You can also rescue `Onfido::ConnectionError`, which is raised whenever something goes wrong with the connection to Onfido - you may wish to automatically retry these requests. +You can also rescue `Onfido::ConnectionError`, which is raised when something goes wrong with the connection to Onfido. This is useful for adding automatic retries to your background jobs. ### Roadmap - Improve test coverage with more scenarios - Add custom errors based on the response code.