Skip to content

Commit

Permalink
Merge 21e27c1 into d2f48e6
Browse files Browse the repository at this point in the history
  • Loading branch information
aromaron committed Mar 20, 2018
2 parents d2f48e6 + 21e27c1 commit 06c6356
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,29 @@ Document methods:
)
```

- Transfer:
+ Using a template

```ruby
args = {
template_id: '29f3cb01-744d-4eae-8718-213aec8a1678',
document_id: '29f3cb01-744d-4eae-8718-213aec8a1678',
fields: {
name: 'My Client Name',
date: 'Sep 27 2017'
},
signatories: [{
name: 'Some name',
email: 'some@email.com',
tax_id: 'AAA010101AAA'
}],
callback_url: 'https://www.example.com/webhook/url',
external_id: 'unique-id'
}

document = Mifiel::Document.transfer_from_template(args)
```

- Save Document related files

```ruby
Expand Down
23 changes: 23 additions & 0 deletions lib/mifiel/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Document < Mifiel::Base
delete :delete, '/documents/:id'
post :create_from_template, '/templates/:template_id/generate_document', timeout: 60
post :create_many_from_template, '/templates/:template_id/generate_documents', timeout: 60
post :transfer, '/documents/:id/transfer', timeout: 60

# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def self.create(args)
Expand Down Expand Up @@ -71,5 +72,27 @@ def self.build_signatories(signatories)
signatories.each_with_index { |s, i| sgries[i] = s }
sgries
end

# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def self.transfer_from_template(args)
id = args[:document_id]

payload = {
from: args[:from],
to: args[:to],
signatories: args[:signatories],
template_id: args[:template_id],
fields: args[:fields],
callback_url: args[:callback_url],
sign_callback_url: args[:sign_callback_url],
allow_business: args[:allow_business],
external_id: args[:external_id]
}
payload.reject! { |_k, v| v.nil? }

response = Mifiel::Document.process_request("/documents/#{id}/transfer", :post, payload)
Mifiel::Document.new(JSON.parse(response))
end
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
end
end
26 changes: 26 additions & 0 deletions spec/mifiel/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,30 @@
end
end
end

describe '#transfer' do
context 'from template' do
let!(:template_id) { 'c6c29866-7fd6-4f77-9ecd-eae8bc3a772a' }
let!(:document) { Mifiel::Document.all.first }

let!(:template) do
Mifiel::Document.transfer_from_template(
template_id: template_id,
document_id: document.id,
fields: {
name: 'some'
},
signatories: [{
name: 'Signer',
email: 'signer@email.com'
}, {
name: 'Signer',
email: 'signer@email.com'
}]
)
end

it { expect(document).to be_a Mifiel::Document }
end
end
end
9 changes: 9 additions & 0 deletions spec/support/fake_mifiel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class FakeMifiel < Sinatra::Base
id: params[:id]
).to_json
end


get '/api/v1/documents/:id/file' do
status 200
Expand Down Expand Up @@ -105,6 +106,14 @@ class FakeMifiel < Sinatra::Base
{ widget_id: '123bc', success: true }.to_json
end

post '/api/v1/documents/:id/transfer' do
content_type :json
status 200
document(
id: params[:id]
).to_json
end

private

def template(args = {})
Expand Down

0 comments on commit 06c6356

Please sign in to comment.