Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #43 from icopass/master
Browse files Browse the repository at this point in the history
Added #find, #all, #download to the LivePhoto class
  • Loading branch information
alanjc7 committed Apr 3, 2018
2 parents 138d8a0 + 2ad7170 commit 15b9451
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/onfido/resources/live_photo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,20 @@ def create(applicant_id, payload)
payload: payload
)
end

def find(applicant_id, live_photo_id)
query_string = "applicant_id=#{applicant_id}"
get(url: url_for("live_photos/#{live_photo_id}?#{query_string}"))
end

def download(applicant_id, live_photo_id)
query_string = "applicant_id=#{applicant_id}"
get(url: url_for("live_photos/#{live_photo_id}/download?#{query_string}"))
end

def all(applicant_id)
query_string = "applicant_id=#{applicant_id}"
get(url: url_for("live_photos?#{query_string}"))
end
end
end
29 changes: 29 additions & 0 deletions spec/integrations/live_photo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,33 @@
end
end
end

describe '#find' do
let(:applicant_id) { '1030303-123123-123123' }
let(:live_photo_id) { '3538c8f6-fdce-4745-9d34-fc246bc05aa1' }

it 'returns the expected live photo' do
response = live_photo.find(applicant_id, live_photo_id)
expect(response['id']).to eq(live_photo_id)
end
end

describe '#all' do
let(:applicant_id) { '1030303-123123-123123' }

it 'returns list of documents' do
response = live_photo.all(applicant_id)
expect(response['live_photos']).not_to be_empty
end
end

describe '#download' do
let(:applicant_id) { '1030303-123123-123123' }
let(:live_photo_id) { '3538c8f6-fdce-4745-9d34-fc246bc05aa1' }

it 'returns the file data' do
response = live_photo.download(applicant_id, live_photo_id)
expect(response).not_to be_nil
end
end
end
26 changes: 26 additions & 0 deletions spec/support/fake_onfido_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,32 @@ class FakeOnfidoAPI < Sinatra::Base
json_response(201, 'live_photo.json')
end

get '/v2/live_photos/:id' do
if params["applicant_id"] != "1030303-123123-123123"
status 404
else
json_response(200, 'live_photo.json')
end
end

get '/v2/live_photos' do
if params["applicant_id"] != "1030303-123123-123123"
status 404
else
json_response(200, 'live_photos.json')
end
end

get '/v2/live_photos/:id/download' do
if params["applicant_id"] != "1030303-123123-123123"
status 404
else
status 200
content_type 'image/jpeg'
"\x01\x02\x03" # acts as binary file data
end
end

post '/v2/applicants/:id/checks' do
json_response(201, 'check.json')
end
Expand Down
9 changes: 7 additions & 2 deletions spec/support/fixtures/live_photo.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"id": "7410A943-8F00-43D8-98DE-36A774196D86",
"created_at": "2014-05-23 13:50:33Z"
"id": "3538c8f6-fdce-4745-9d34-fc246bc05aa1",
"created_at": "2014-05-23 13:50:33Z",
"file_name": "onfido_captured_image.jpg",
"file_type": "image/jpeg",
"file_size": 47544,
"href": "/v2/live_photos/3538c8f6-fdce-4745-9d34-fc246bc05aa1",
"download_href": "/v2/live_photos/3538c8f6-fdce-4745-9d34-fc246bc05aa1/download"
}
22 changes: 22 additions & 0 deletions spec/support/fixtures/live_photos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"live_photos": [
{
"id": "3538c8f6-fdce-4745-9d34-fc246bc05aa1",
"created_at": "2014-05-23 13:50:33Z",
"file_name": "onfido_captured_image.jpg",
"file_type": "image/jpeg",
"file_size": 47544,
"href": "/v2/live_photos/3538c8f6-fdce-4745-9d34-fc246bc05aa1",
"download_href": "/v2/live_photos/3538c8f6-fdce-4745-9d34-fc246bc05aa1/download"
},
{
"id": "5134c12a-555a-1234-5e12-9d34fcbc11ba",
"created_at": "2014-05-23 13:50:33Z",
"file_name": "onfido_captured_image.jpg",
"file_type": "image/jpeg",
"file_size": 47544,
"href": "/v2/live_photos/5134c12a-555a-1234-5e12-9d34fcbc11ba",
"download_href": "/v2/live_photos/5134c12a-555a-1234-5e12-9d34fcbc11ba/download"
}
]
}

0 comments on commit 15b9451

Please sign in to comment.