Skip to content

Commit

Permalink
Feat: Add Monitor Support (#40)
Browse files Browse the repository at this point in the history
* feat(onfido API): Add support for monitors

* refactor(version): Bump to 2.6.0

* refactor(monitor spec): Remove unnecessary Tempfile require

* refactor(fixtures): Add missing new lines
  • Loading branch information
dorlandimort authored Dec 2, 2022
1 parent 665d462 commit f51d65e
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v2.6.0, 22 November 2022

- Added support for [Monitors](https://documentation.onfido.com/#monitors)

## v2.5.0, 22 October 2022

- Added Motion capture support
Expand Down
1 change: 1 addition & 0 deletions lib/onfido.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
require 'onfido/resources/extraction'
require 'onfido/resources/live_photo'
require 'onfido/resources/live_video'
require 'onfido/resources/monitor'
require 'onfido/resources/motion_capture'
require 'onfido/resources/report'
require 'onfido/resources/sdk_token'
Expand Down
4 changes: 4 additions & 0 deletions lib/onfido/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def live_video
@live_video ||= Onfido::LiveVideo.new(options)
end

def monitor
@monitor ||= Onfido::Monitor.new(options)
end

def motion_capture
@motion_capture ||= Onfido::MotionCapture.new(options)
end
Expand Down
24 changes: 24 additions & 0 deletions lib/onfido/resources/monitor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module Onfido
class Monitor < Resource
def create(applicant_id:, report_name:, **payload)
payload[:applicant_id] = applicant_id
payload[:report_name] = report_name

post(path: 'watchlist_monitors', payload: payload)
end

def find(monitor_id)
get(path: "watchlist_monitors/#{monitor_id}")
end

def all(applicant_id)
get(path: "watchlist_monitors?applicant_id=#{applicant_id}")
end

def destroy(monitor_id)
delete(path: "watchlist_monitors/#{monitor_id}")
end
end
end
2 changes: 1 addition & 1 deletion lib/onfido/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Onfido
VERSION = '2.5.0'
VERSION = '2.6.0'
end
40 changes: 40 additions & 0 deletions spec/integrations/monitor_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

describe Onfido::Monitor do
include_context 'fake onfido api'

subject(:monitor) { onfido.monitor }

let(:monitor_id) { '2748c4fc-c6b8-4c1e-a383-21efa241ce1e' }

describe '#create' do
let(:applicant_id) { '61f659cb-c90b-4067-808a-6136b5c01351' }
let(:report_name) { 'watchlist_standard' }

it 'creates a monitor for the applicant' do
response = monitor.create(applicant_id: applicant_id, report_name: report_name)
expect(response).to be_a(Hash).and include('id' => monitor_id, 'report_name' => report_name)
end
end

describe '#find' do
it 'returns the expected monitor' do
response = monitor.find(monitor_id)

expect(response).to be_a(Hash).and include('id' => monitor_id)
end
end

describe '#all' do
it 'returns a list of monitors' do
applicant_id = '1030303-123123-123123'
response = monitor.all(applicant_id)

expect(response['monitors']).to be_an(Array).and contain_exactly(an_instance_of(Hash))
end
end

it 'returns success code' do
expect { monitor.destroy(monitor_id) }.not_to raise_error
end
end
20 changes: 20 additions & 0 deletions spec/support/fake_onfido_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,26 @@ class FakeOnfidoAPI < Sinatra::Base # rubocop:disable Metrics/ClassLength
"\x01\x02\x03" # acts as binary file data
end

post '/v3.5/watchlist_monitors' do
json_response(201, 'monitor.json')
end

get '/v3.5/watchlist_monitors/:id' do
json_response(200, 'monitor.json')
end

get '/v3.5/watchlist_monitors' do
if params['applicant_id'] == '1030303-123123-123123'
json_response(200, 'monitors.json')
else
status 404
end
end

delete '/v3.5/watchlist_monitors/:id' do
status 204
end

get '/v3.5/motion_captures/:id' do
json_response(200, 'motion_capture.json')
end
Expand Down
8 changes: 8 additions & 0 deletions spec/support/fixtures/monitor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "2748c4fc-c6b8-4c1e-a383-21efa241ce1e",
"report_name": "watchlist_standard",
"created_at": "2022-09-01T15:01:36.921Z",
"deleted_at": null,
"sandbox": false,
"tags": []
}
12 changes: 12 additions & 0 deletions spec/support/fixtures/monitors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"monitors": [
{
"id": "2748c4fc-c6b8-4c1e-a383-21efa241ce1e",
"report_name": "watchlist_standard",
"created_at": "2022-09-01T15:01:36.921Z",
"deleted_at": null,
"sandbox": false,
"tags": []
}
]
}

0 comments on commit f51d65e

Please sign in to comment.