Skip to content

Commit

Permalink
Merge pull request #47 from onfido/release-upgrade
Browse files Browse the repository at this point in the history
Refresh onfido-ruby after onfido-openapi-spec update (d65af1f)
  • Loading branch information
RiccardoPetteruti-Onfido authored May 15, 2024
2 parents e3b62c0 + eb33056 commit 200f82d
Show file tree
Hide file tree
Showing 348 changed files with 73,119 additions and 2,434 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.4', '2.5', '2.6', '2.7', '3.0', '3.1']
ruby-version: ['2.7', '3.0', '3.1', '3.2']

steps:
- uses: actions/checkout@v2
Expand All @@ -22,4 +22,14 @@ jobs:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
- name: Run tests
if: ${{ matrix.ruby-version == '3.2' &&
github.repository_owner == 'onfido' &&
github.actor != 'dependabot[bot]' }}
run: bundle exec rspec spec
env:
ONFIDO_API_TOKEN: ${{ secrets.ONFIDO_API_TOKEN }}
ONFIDO_SAMPLE_APPLICANT_ID: ${{ secrets.ONFIDO_SAMPLE_APPLICANT_ID }}
ONFIDO_SAMPLE_VIDEO_ID_1: ${{ secrets.ONFIDO_SAMPLE_VIDEO_ID_1 }}
ONFIDO_SAMPLE_VIDEO_ID_2: ${{ secrets.ONFIDO_SAMPLE_VIDEO_ID_2 }}
ONFIDO_SAMPLE_MOTION_ID_1: ${{ secrets.ONFIDO_SAMPLE_MOTION_ID_1 }}
ONFIDO_SAMPLE_MOTION_ID_2: ${{ secrets.ONFIDO_SAMPLE_MOTION_ID_2 }}
1 change: 1 addition & 0 deletions .openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.5.0
151 changes: 143 additions & 8 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,148 @@
# This file is based on https://github.com/rails/rails/blob/master/.rubocop.yml (MIT license)
# Automatically generated by OpenAPI Generator (https://openapi-generator.tech)
AllCops:
NewCops: enable
TargetRubyVersion: 2.4.0
TargetRubyVersion: 2.4
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
# to ignore them, so only the ones explicitly set in this file are enabled.
DisabledByDefault: true
Exclude:
- '**/templates/**/*'
- '**/vendor/**/*'
- 'actionpack/lib/action_dispatch/journey/parser.rb'

Layout/LineLength:
Max: 100
# Prefer &&/|| over and/or.
Style/AndOr:
Enabled: true

Metrics/BlockLength:
Exclude:
- spec/**/*
# Align `when` with `case`.
Layout/CaseIndentation:
Enabled: true

# Align comments with method definitions.
Layout/CommentIndentation:
Enabled: true

Layout/ElseAlignment:
Enabled: true

Layout/EmptyLineAfterMagicComment:
Enabled: true

Style/Documentation:
# In a regular class definition, no empty lines around the body.
Layout/EmptyLinesAroundClassBody:
Enabled: true

# In a regular method definition, no empty lines around the body.
Layout/EmptyLinesAroundMethodBody:
Enabled: true

# In a regular module definition, no empty lines around the body.
Layout/EmptyLinesAroundModuleBody:
Enabled: true

Layout/FirstArgumentIndentation:
Enabled: true

# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
Style/HashSyntax:
Enabled: false

# Method definitions after `private` or `protected` isolated calls need one
# extra level of indentation.
Layout/IndentationConsistency:
Enabled: true
EnforcedStyle: indented_internal_methods

# Two spaces, no tabs (for indentation).
Layout/IndentationWidth:
Enabled: true

Layout/LeadingCommentSpace:
Enabled: true

Layout/SpaceAfterColon:
Enabled: true

Layout/SpaceAfterComma:
Enabled: true

Layout/SpaceAroundEqualsInParameterDefault:
Enabled: true

Layout/SpaceAroundKeyword:
Enabled: true

Layout/SpaceAroundOperators:
Enabled: true

Layout/SpaceBeforeComma:
Enabled: true

Layout/SpaceBeforeFirstArg:
Enabled: true

Style/DefWithParentheses:
Enabled: true

# Defining a method with parameters needs parentheses.
Style/MethodDefParentheses:
Enabled: true

Style/FrozenStringLiteralComment:
Enabled: false
EnforcedStyle: always

# Use `foo {}` not `foo{}`.
Layout/SpaceBeforeBlockBraces:
Enabled: true

# Use `foo { bar }` not `foo {bar}`.
Layout/SpaceInsideBlockBraces:
Enabled: true

# Use `{ a: 1 }` not `{a:1}`.
Layout/SpaceInsideHashLiteralBraces:
Enabled: true

Layout/SpaceInsideParens:
Enabled: true

# Check quotes usage according to lint rule below.
#Style/StringLiterals:
# Enabled: true
# EnforcedStyle: single_quotes

# Detect hard tabs, no hard tabs.
Layout/IndentationStyle:
Enabled: true

# Blank lines should not have any spaces.
Layout/TrailingEmptyLines:
Enabled: true

# No trailing whitespace.
Layout/TrailingWhitespace:
Enabled: false

# Use quotes for string literals when they are enough.
Style/RedundantPercentQ:
Enabled: true

# Align `end` with the matching keyword or starting expression except for
# assignments, where it should be aligned with the LHS.
Layout/EndAlignment:
Enabled: true
EnforcedStyleAlignWith: variable
AutoCorrect: true

# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
Lint/RequireParentheses:
Enabled: true

Style/RedundantReturn:
Enabled: true
AllowMultipleReturnValues: true

Style/Semicolon:
Enabled: true
AllowAsExpressionSeparator: true
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Changelog

## v2.9.0 24 November 2023

- Added `signed_evidence_file` method for WorkflowRuns
Expand Down
7 changes: 3 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec

group :development, :test do
gem 'pry'
gem 'rake', '~> 13.0.1'
gem 'pry-byebug'
gem 'pry-stack_explorer'
gem 'rubocop', '~> 0.66.0'
end
12 changes: 5 additions & 7 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
The MIT License (MIT)

Original work Copyright (c) 2015 Hassle
Modified work Copyright 2019 Onfido
Copyright (c) 2024 Onfido

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -10,14 +9,13 @@ 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 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.

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
103 changes: 52 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
# Onfido
# Onfido Ruby Library

The official Ruby library for integrating with the Onfido API.

[![Gem Version](https://badge.fury.io/rb/onfido.svg)](http://badge.fury.io/rb/onfido)
[![Build Status](https://travis-ci.org/onfido/onfido-ruby.svg?branch=master)](https://travis-ci.org/onfido/onfido-ruby)
Documentation can be found at <https://documentation.onfido.com>.

Documentation can be found at https://documentation.onfido.com
This version uses Onfido API v3.6. Refer to our [API versioning guide](https://developers.onfido.com/guide/api-versioning-policy#client-libraries) for details of which client library versions use which versions of the API.

This version uses Onfido API v3.6 and is compatible with Ruby 2.4 onwards. Refer to our [API versioning guide](https://developers.onfido.com/guide/api-versioning-policy#client-libraries) for details of which client library versions use which versions of the API.
[![Gem Version](https://badge.fury.io/rb/onfido.svg)](http://badge.fury.io/rb/onfido)
[![Build Status](https://travis-ci.org/onfido/onfido-ruby.svg?branch=master)](https://travis-ci.org/onfido/onfido-ruby)

## Installation
## Installation & Usage

Add this line to your application's Gemfile:
### Installation

```ruby
gem 'onfido', '~> 2.0.1'
gem onfido, '~> 2.0.1'
```

## Getting started

Configure with your API token and region:
Configure with your API token, region and optional timeout (default value is 30):

```ruby
onfido = Onfido::API.new(
api_key: ENV['ONFIDO_API_KEY'],
# Supports :eu, :us and :ca. Previously defaulted to :eu.
region: :eu
)
require onfido

Onfido.configure do |config|
config.api_token = ENV["ONFIDO_API_TOKEN"]
config.region = config.region[:EU]
config.timeout = 30
end

onfido_api = Onfido::DefaultApi.new
```

All resources share the same interface when making API calls. Use `.create` to create a resource, `.find` to find one, and `.all` to fetch all resources.

For example, to create an applicant:
### Making a call to the API

```ruby
onfido.applicant.create(
applicant = onfido_api.create_applicant(
first_name: 'Test',
last_name: 'Applicant'
)
Expand All @@ -44,62 +46,61 @@ Documentation and code examples can be found at https://documentation.onfido.com

## Error Handling

There are 3 classes of errors raised by the library, all of which subclass `Onfido::OnfidoError`:
All errors are wrapped by `ApiError` coming from [FaradayExpection](https://www.rubydoc.info/github/lostisland/faraday/Faraday/ClientError):

- `Onfido::RequestError` is raised whenever Onfido returns a `4xx` response
- `Onfido::ServerError` is raised whenever Onfido returns a `5xx` response
- `Onfido::ConnectionError` is raised whenever a network error occurs (e.g., a timeout)
- `Connection timed out` is raised in case of `Faraday::TimeoutError`
- `Connection failed` is raised in case of `Faraday::ConnectionFailed`

All 3 error classes provide the `response_code`, `response_body`, `json_body`, `type` and `fields` of the error (although for `Onfido::ServerError` and `Onfido::ConnectionError` the last 3 are likely to be `nil`).
All errors provide the `response_code`, `response_body`, `json_body`, `type` and `fields` of the error.

```ruby
def create_applicant
onfido.applicant.create(params)
rescue Onfido::RequestError => e
onfido_api.create_applicant(params)
rescue Faraday::ConnectionFailed => e
e.type # => 'validation_error'
e.fields # => { "email": { "messages": ["invalid format"] } }
e.response_code # => '422'
end
```

## Other configuration
### Webhook event verification

Optional configuration options with their defaults:
Webhook events payload needs to be verified before it can be accessed. Library allows to easily decode the payload and verify its signature before returning it as an object for user convenience:

```ruby
onfido = Onfido::API.new(
# ...
open_timeout: 10,
read_timeout: 30
)
```
require 'onfido/webhook_event_verifier'

## Verifying webhooks
def webhook_verifier()
verifier = Onfido::WebhookEventVerifier.new("_ABC123abc...3ABC123_")

Each webhook endpoint has a secret token, generated automatically and [exposed](https://documentation.onfido.com/#register-webhook) in the API. When sending a request, Onfido includes a signature computed using the request body and this token in the `X-SHA2-Signature` header.
signature = "a0...760e"

You should compare this provided signature to one you generate yourself with the token to verify that a webhook is a genuine request from Onfido.
event = verifier.read_payload('{"payload":{"r...3"}}', signature)

```ruby
if Onfido::Webhook.valid?(request.raw_post,
request.headers["X-SHA2-Signature"],
ENV['ONFIDO_WEBHOOK_TOKEN'])
process_webhook
else
render status: 498, text: "498 Token expired/invalid"
end
rescue Onfido::OnfidoInvalidSignatureError => e
e.type
e.fields
e.response_code
end
```

Read more at https://developers.onfido.com/guide/manual-webhook-signature-verification#webhook-security

## Contributing

1. Fork it ( https://github.com/onfido/onfido-ruby/fork )
This library is automatically generated using [OpenAPI Generator](https://openapi-generator.tech) - version: 7.5.0; therefore all the contributions, except tests files, should target [Onfido OpenAPI specification repository](https://github.com/onfido/onfido-openapi-spec/tree/master) instead of this repository.

For contributions to the tests instead, please follow the steps below:

1. [Fork](<https://github.com/onfido/onfido-ruby/fork>) repository
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
3. Make your changes
4. Commit your changes (`git commit -am 'Add some feature'`)
5. Push to the branch (`git push origin my-new-feature`)
6. Create a new Pull Request

## More documentation

More documentation and code examples can be found at https://documentation.onfido.com
More documentation and code examples can be found at <https://documentation.onfido.com>.

## Support
Should you encounter any technical issues during integration, please contact Onfido's Customer Support team
via the [Customer Experience Portal](https://public.support.onfido.com/) which also includes support documentation.
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require "bundler/gem_tasks"

begin
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)
task default: :spec
rescue LoadError
# no rspec available
end
Loading

0 comments on commit 200f82d

Please sign in to comment.