Skip to content

Commit cb9cdee

Browse files
committed
Merge branch 'release/v1.1.2'
2 parents 21d22bc + c5056ac commit cb9cdee

File tree

5 files changed

+105
-24
lines changed

5 files changed

+105
-24
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![Gem Version][gem-version-image]][gem-version-url]
44
[![Build Status][travis-image]][travis-url]
5+
[![Coverage Status][coveralls-image]][coveralls-url]
56
[![security][security-image]][security-url]
67

78
Ruby SDK for [Mifiel](https://www.mifiel.com) API.
@@ -78,6 +79,17 @@ Document methods:
7879
)
7980
```
8081

82+
- Save Document related files
83+
84+
```ruby
85+
# save the original file
86+
document.save_file('path/to/save/file.pdf')
87+
# save the signed file (original file + signatures page)
88+
document.save_file_signed('path/to/save/file-signed.pdf')
89+
# save the signed xml file
90+
document.save_xml('path/to/save/xml.xml')
91+
```
92+
8193
- Sign:
8294
+ With a pre-created Certificate
8395

@@ -146,7 +158,12 @@ Certificate methods:
146158

147159
[gem-version-image]: https://badge.fury.io/rb/mifiel.svg
148160
[gem-version-url]: https://badge.fury.io/rb/mifiel
161+
149162
[security-url]: https://hakiri.io/github/Mifiel/ruby-api-client/master
150163
[security-image]: https://hakiri.io/github/Mifiel/ruby-api-client/master.svg
164+
151165
[travis-image]: https://travis-ci.org/Mifiel/ruby-api-client.svg?branch=master
152166
[travis-url]: https://travis-ci.org/Mifiel/ruby-api-client
167+
168+
[coveralls-image]: https://coveralls.io/repos/github/Mifiel/ruby-api-client/badge.svg?branch=master
169+
[coveralls-url]: https://coveralls.io/github/Mifiel/ruby-api-client?branch=master

lib/mifiel/document.rb

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def self.create(signatories:, file: nil, hash: nil, name: nil, callback_url: nil
1717
original_hash: hash,
1818
name: name
1919
}
20-
process_request('/documents', :post, payload)
20+
response = process_request('/documents', :post, payload)
21+
JSON.load(response)
2122
end
2223

2324
def request_signature(email, cc: nil)
@@ -26,7 +27,22 @@ def request_signature(email, cc: nil)
2627
Mifiel::Document._request("#{Mifiel.config.base_url}/documents/#{id}/request_signature", :post, params)
2728
end
2829

29-
def self.process_request(path, method, payload)
30+
def save_file(path)
31+
response = Mifiel::Document.process_request("/documents/#{id}/file", :get)
32+
File.open(path, 'wb') { |file| file.write(response) }
33+
end
34+
35+
def save_file_signed(path)
36+
response = Mifiel::Document.process_request("/documents/#{id}/file_signed", :get)
37+
File.open(path, 'wb') { |file| file.write(response) }
38+
end
39+
40+
def save_xml(path)
41+
response = Mifiel::Document.process_request("/documents/#{id}/xml", :get)
42+
File.open(path, 'w') { |file| file.write(response) }
43+
end
44+
45+
def self.process_request(path, method, payload=nil)
3046
path[0] = '' if path[0] == '/'
3147
rest_request = RestClient::Request.new(
3248
url: "#{Mifiel.config.base_url}/#{path}",
@@ -35,7 +51,7 @@ def self.process_request(path, method, payload)
3551
ssl_version: 'SSLv23'
3652
)
3753
req = ApiAuth.sign!(rest_request, Mifiel.config.app_id, Mifiel.config.app_secret)
38-
JSON.load(req.execute)
54+
req.execute
3955
end
4056

4157
def self.build_signatories(signatories)

lib/mifiel/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Mifiel
2-
VERSION = '1.1.1'.freeze
2+
VERSION = '1.1.2'.freeze
33
end

spec/mifiel/document_spec.rb

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,72 @@
1919
end
2020
end
2121

22-
describe '#request_signature' do
22+
describe 'working with a document' do
2323
let!(:document) { Mifiel::Document.all.first }
24-
let!(:error_body) { { errors: ['some error'] }.to_json }
2524

26-
it '' do
27-
expect do
28-
document.request_signature('[email protected]')
29-
end.not_to raise_error
30-
end
25+
describe '#save_file' do
26+
let!(:path) {'tmp/the-file.pdf' }
27+
before { File.unlink(path) if File.exist?(path)}
3128

32-
context 'when bad request' do
33-
before do
34-
url = %r{mifiel.com\/api\/v1\/documents\/#{document.id}\/request_signature}
35-
stub_request(:post, url).to_return(body: error_body, status: 404)
29+
it 'should get the file' do
30+
document.save_file(path)
31+
expect(File.exist?(path)).to be true
3632
end
33+
end
3734

38-
it '' do
39-
expect do
40-
document.request_signature('[email protected]')
41-
end.to raise_error(Mifiel::BadRequestError)
35+
describe '#save_file_signed' do
36+
let!(:path) {'tmp/the-file-signed.pdf' }
37+
before { File.unlink(path) if File.exist?(path)}
38+
39+
it 'should get the file' do
40+
document.save_file_signed(path)
41+
expect(File.exist?(path)).to be true
4242
end
4343
end
4444

45-
context 'when server error' do
46-
before do
47-
url = %r{mifiel.com\/api\/v1\/documents\/#{document.id}\/request_signature}
48-
stub_request(:post, url).to_return(body: error_body, status: 500)
45+
describe '#save_xml' do
46+
let!(:path) {'tmp/the-xml.xml' }
47+
before { File.unlink(path) if File.exist?(path)}
48+
49+
it 'should get the file' do
50+
document.save_xml(path)
51+
expect(File.exist?(path)).to be true
4952
end
53+
end
54+
55+
describe '#request_signature' do
56+
let!(:error_body) { { errors: ['some error'] }.to_json }
5057

5158
it '' do
5259
expect do
5360
document.request_signature('[email protected]')
54-
end.to raise_error(Mifiel::ServerError)
61+
end.not_to raise_error
62+
end
63+
64+
context 'when bad request' do
65+
before do
66+
url = %r{mifiel.com\/api\/v1\/documents\/#{document.id}\/request_signature}
67+
stub_request(:post, url).to_return(body: error_body, status: 404)
68+
end
69+
70+
it '' do
71+
expect do
72+
document.request_signature('[email protected]')
73+
end.to raise_error(Mifiel::BadRequestError)
74+
end
75+
end
76+
77+
context 'when server error' do
78+
before do
79+
url = %r{mifiel.com\/api\/v1\/documents\/#{document.id}\/request_signature}
80+
stub_request(:post, url).to_return(body: error_body, status: 500)
81+
end
82+
83+
it '' do
84+
expect do
85+
document.request_signature('[email protected]')
86+
end.to raise_error(Mifiel::ServerError)
87+
end
5588
end
5689
end
5790
end

spec/support/fake_mifiel.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ class FakeMifiel < Sinatra::Base
4545
).to_json
4646
end
4747

48+
get '/api/v1/documents/:id/file' do
49+
status 200
50+
'some-pdf-formatted-string'
51+
end
52+
53+
get '/api/v1/documents/:id/file_signed' do
54+
status 200
55+
'some-pdf-formatted-string'
56+
end
57+
58+
get '/api/v1/documents/:id/xml' do
59+
status 200
60+
'<some><xml>contents</xml></some>'
61+
end
62+
4863
post '/api/v1/documents/:id/request_signature' do
4964
content_type :json
5065
status 200

0 commit comments

Comments
 (0)