Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,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 @@ -11,6 +11,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 @@ -83,5 +84,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 @@ -152,4 +152,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
8 changes: 8 additions & 0 deletions spec/support/fake_mifiel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ class FakeMifiel < Sinatra::Base # rubocop:disable Metrics/ClassLength
{ 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