mifiel 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -0
- data/lib/mifiel/document.rb +19 -3
- data/lib/mifiel/version.rb +1 -1
- data/spec/mifiel/document_spec.rb +53 -20
- data/spec/support/fake_mifiel.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b81aa9ae009760bdbf21c71d2af638956d898e7
|
4
|
+
data.tar.gz: 7b62d15b2abe554804ba41b5eaf9d13fe2a06199
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4aa349459b1752a1e682cd4dc8c959dede12e95b519cda0497b1d6c4cc381b1000c9eb7bf147e983ab6d6166c97ddcfa3638d261ab998352526042d5bcc0bb95
|
7
|
+
data.tar.gz: 484c3f9becf2180f30e3bc11c105ba79e72c764c2ac07632897c6333b52b731c598bd5e566914bfd0ba18e513609322fce3c1d1f6bf45c221f9f99fd508ecefd
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Gem Version][gem-version-image]][gem-version-url]
|
4
4
|
[![Build Status][travis-image]][travis-url]
|
5
|
+
[![Coverage Status][coveralls-image]][coveralls-url]
|
5
6
|
[![security][security-image]][security-url]
|
6
7
|
|
7
8
|
Ruby SDK for [Mifiel](https://www.mifiel.com) API.
|
@@ -78,6 +79,17 @@ Document methods:
|
|
78
79
|
)
|
79
80
|
```
|
80
81
|
|
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
|
+
|
81
93
|
- Sign:
|
82
94
|
+ With a pre-created Certificate
|
83
95
|
|
@@ -146,7 +158,12 @@ Certificate methods:
|
|
146
158
|
|
147
159
|
[gem-version-image]: https://badge.fury.io/rb/mifiel.svg
|
148
160
|
[gem-version-url]: https://badge.fury.io/rb/mifiel
|
161
|
+
|
149
162
|
[security-url]: https://hakiri.io/github/Mifiel/ruby-api-client/master
|
150
163
|
[security-image]: https://hakiri.io/github/Mifiel/ruby-api-client/master.svg
|
164
|
+
|
151
165
|
[travis-image]: https://travis-ci.org/Mifiel/ruby-api-client.svg?branch=master
|
152
166
|
[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
|
data/lib/mifiel/document.rb
CHANGED
@@ -17,7 +17,8 @@ module Mifiel
|
|
17
17
|
original_hash: hash,
|
18
18
|
name: name
|
19
19
|
}
|
20
|
-
process_request('/documents', :post, payload)
|
20
|
+
response = process_request('/documents', :post, payload)
|
21
|
+
JSON.load(response)
|
21
22
|
end
|
22
23
|
|
23
24
|
def request_signature(email, cc: nil)
|
@@ -26,7 +27,22 @@ module Mifiel
|
|
26
27
|
Mifiel::Document._request("#{Mifiel.config.base_url}/documents/#{id}/request_signature", :post, params)
|
27
28
|
end
|
28
29
|
|
29
|
-
def
|
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)
|
30
46
|
path[0] = '' if path[0] == '/'
|
31
47
|
rest_request = RestClient::Request.new(
|
32
48
|
url: "#{Mifiel.config.base_url}/#{path}",
|
@@ -35,7 +51,7 @@ module Mifiel
|
|
35
51
|
ssl_version: 'SSLv23'
|
36
52
|
)
|
37
53
|
req = ApiAuth.sign!(rest_request, Mifiel.config.app_id, Mifiel.config.app_secret)
|
38
|
-
|
54
|
+
req.execute
|
39
55
|
end
|
40
56
|
|
41
57
|
def self.build_signatories(signatories)
|
data/lib/mifiel/version.rb
CHANGED
@@ -19,39 +19,72 @@ describe Mifiel::Document do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe '
|
22
|
+
describe 'working with a document' do
|
23
23
|
let!(:document) { Mifiel::Document.all.first }
|
24
|
-
let!(:error_body) { { errors: ['some error'] }.to_json }
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
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)}
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
36
32
|
end
|
33
|
+
end
|
37
34
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
49
52
|
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#request_signature' do
|
56
|
+
let!(:error_body) { { errors: ['some error'] }.to_json }
|
50
57
|
|
51
58
|
it '' do
|
52
59
|
expect do
|
53
60
|
document.request_signature('some@email.com')
|
54
|
-
end.
|
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('some@email.com')
|
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('some@email.com')
|
86
|
+
end.to raise_error(Mifiel::ServerError)
|
87
|
+
end
|
55
88
|
end
|
56
89
|
end
|
57
90
|
end
|
data/spec/support/fake_mifiel.rb
CHANGED
@@ -45,6 +45,21 @@ class FakeMifiel < Sinatra::Base
|
|
45
45
|
).to_json
|
46
46
|
end
|
47
47
|
|
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
|
+
|
48
63
|
post '/api/v1/documents/:id/request_signature' do
|
49
64
|
content_type :json
|
50
65
|
status 200
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mifiel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genaro Madrid
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|