Skip to content

Commit

Permalink
Merge pull request #7 from Coinberry/add-extractions-endpoint
Browse files Browse the repository at this point in the history
Add extraction endpoint
  • Loading branch information
Ola Sitarska authored Aug 14, 2020
2 parents 9c5dcc9 + 578e8d6 commit f4acd94
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/onfido.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
require 'onfido/resources/applicant'
require 'onfido/resources/check'
require 'onfido/resources/document'
require 'onfido/resources/extraction'
require 'onfido/resources/live_photo'
require 'onfido/resources/live_video'
require 'onfido/resources/report'
Expand Down
4 changes: 4 additions & 0 deletions lib/onfido/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@ def webhook
def address
Onfido::Address.new(@api_key)
end

def extraction
Onfido::Extraction.new(@api_key)
end
end
end
9 changes: 9 additions & 0 deletions lib/onfido/resources/extraction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Onfido
class Extraction < Resource
def create(document_id:)
payload = { document_id: document_id }

post(path: 'extractions', payload: payload)
end
end
end
19 changes: 19 additions & 0 deletions spec/integrations/extraction_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'tempfile'

describe Onfido::Extraction do
subject(:extraction) { described_class.new }

describe '#create' do
let(:params) do
{
document_id: '7568415-123123-123123'
}
end

it 'creates a new extraction' do
response = extraction.create(params)

expect(response['document_id']).to eq('7568415-123123-123123')
end
end
end
4 changes: 4 additions & 0 deletions spec/support/fake_onfido_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class FakeOnfidoAPI < Sinatra::Base
json_response(201, 'document.json')
end

post '/v3/extractions' do
json_response(201, 'extraction.json')
end

get '/v3/documents/:id' do
json_response(200, 'document.json')
end
Expand Down
23 changes: 23 additions & 0 deletions spec/support/fixtures/extraction.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"document_id": "7568415-123123-123123",
"document_classification": {
"issuing_country": "FRA",
"document_type": "national_identity_card"
},
"extracted_data": {
"date_of_birth": "1965-09-08",
"document_number": "400925733",
"first_name": "MARIE",
"gender": "Female",
"last_name": "MAVARINE",
"mrz_line1": "P<GBRDU<MARIE<<MAVARINE<<<<<<<<<<<<<<<<<<<<<",
"mrz_line2": "4009257333GBR6509088F1307072<<<<<<<<<<<<<<06",
"nationality": "BRITISH CITIZEN",
"full_name": "MAVARINE DU MARIE",
"date_of_expiry": "2013-07-07",
"middle_name": "DU",
"address_line_1": "52 RUE DES FLEURS",
"address_line_2": "33500 BORDEAUX",
"address_line_3": "FRANCE"
}
}

0 comments on commit f4acd94

Please sign in to comment.