mifiel 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +20 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.rubocop.yml +20 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +117 -0
- data/Rakefile +5 -0
- data/bump +70 -0
- data/lib/mifiel.rb +20 -0
- data/lib/mifiel/base.rb +16 -0
- data/lib/mifiel/certificate.rb +24 -0
- data/lib/mifiel/config.rb +38 -0
- data/lib/mifiel/document.rb +84 -0
- data/lib/mifiel/errors.rb +8 -0
- data/lib/mifiel/version.rb +3 -0
- data/mifiel.gemspec +32 -0
- data/spec/fixtures/FIEL_AAA010101AAA.cer +0 -0
- data/spec/fixtures/FIEL_AAA010101AAA.key +0 -0
- data/spec/fixtures/example.pdf +0 -0
- data/spec/mifiel/document_spec.rb +77 -0
- data/spec/spec_helper.rb +15 -0
- metadata +257 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a4771294e3b399b292c103b30308f6803e8ec8c7
|
4
|
+
data.tar.gz: 4cc235a00d7d16efb58d900670f45a628c58b008
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2f9460d1b14fb42270b49eb8a6edc945563dc0505a7ec8902f75e868253b1713632bbaec715cf74eb8eca422d3cb015527f15cec36716bbb62fef52eb9622137
|
7
|
+
data.tar.gz: ee57285f4b61a68110d254fb5baba7c8ebdeef5e0cbc149fbdaa7801b67d1f3f680de6a414f282f66299137bca3314706081897f25aa5ddc92f6370846f40e9f
|
data/.editorconfig
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# EditorConfig helps developers define and maintain consistent
|
2
|
+
# coding styles between different editors and IDEs
|
3
|
+
# editorconfig.org
|
4
|
+
|
5
|
+
root = true
|
6
|
+
|
7
|
+
[*]
|
8
|
+
|
9
|
+
# Change these settings to your own preference
|
10
|
+
indent_style = space
|
11
|
+
indent_size = 2
|
12
|
+
|
13
|
+
# We recommend you to keep these unchanged
|
14
|
+
end_of_line = lf
|
15
|
+
charset = utf-8
|
16
|
+
trim_trailing_whitespace = true
|
17
|
+
insert_final_newline = true
|
18
|
+
|
19
|
+
[*.md]
|
20
|
+
trim_trailing_whitespace = false
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Style/IndentationConsistency:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Style/SingleSpaceBeforeFirstArg:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Style/AlignHash:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Style/SpaceAroundEqualsInParameterDefault:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Style/Documentation:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/EmptyLinesAroundBlockBody:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Metrics/LineLength:
|
20
|
+
Max: 1000
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
mifiel_api_client
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.2
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 Genaro Madrid
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
# Mifiel
|
2
|
+
|
3
|
+
Ruby SDK for [Mifiel](https://www.mifiel.com) API.
|
4
|
+
Please read our [documentation](https://www.mifiel.com/api-docs/) for instructions on how to start using the API.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'mifiel'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install mifiel
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Document methods:
|
25
|
+
|
26
|
+
- Find:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
document = Mifiel::Document.find('id')
|
30
|
+
document.original_hash
|
31
|
+
document.file
|
32
|
+
document.file_signed
|
33
|
+
# ...
|
34
|
+
```
|
35
|
+
|
36
|
+
- Find all:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
documents = Mifiel::Document.all
|
40
|
+
```
|
41
|
+
|
42
|
+
- Create:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
document = Mifiel::Document.create(
|
46
|
+
file: 'path/to/my-file.pdf',
|
47
|
+
signatories: [
|
48
|
+
{ name: 'Signer 1', email: 'signer1@email.com', tax_id: 'AAA010101AAA' },
|
49
|
+
{ name: 'Signer 2', email: 'signer2@email.com', tax_id: 'AAA010102AAA' }
|
50
|
+
]
|
51
|
+
)
|
52
|
+
```
|
53
|
+
|
54
|
+
- Sign:
|
55
|
+
+ With a pre-created Certificate
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
certificate = Mifiel::Certificate.find('cert-id')
|
59
|
+
document.sign(certificate_id: certificate.id)
|
60
|
+
```
|
61
|
+
|
62
|
+
+ With a new one
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
document.sign(certificate: File.read('FIEL_AAA010101AAA.cer'))
|
66
|
+
```
|
67
|
+
|
68
|
+
- Delete
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
document.delete
|
72
|
+
```
|
73
|
+
|
74
|
+
Certificate methods:
|
75
|
+
|
76
|
+
- Sat Certificates
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
sat_certificates = Mifiel::Certificate.sat
|
80
|
+
```
|
81
|
+
|
82
|
+
- Find:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
certificate = Mifiel::Certificate.find('id')
|
86
|
+
certificate.cer_hex
|
87
|
+
certificate.type_of
|
88
|
+
# ...
|
89
|
+
```
|
90
|
+
|
91
|
+
- Find all:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
certificates = Mifiel::Certificate.all
|
95
|
+
```
|
96
|
+
|
97
|
+
- Create
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
certificate = Mifiel::Certificate.create(
|
101
|
+
file: 'path/to/my-certificate.cer'
|
102
|
+
)
|
103
|
+
```
|
104
|
+
|
105
|
+
- Delete
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
certificate.delete
|
109
|
+
```
|
110
|
+
|
111
|
+
## Contributing
|
112
|
+
|
113
|
+
1. Fork it ( https://github.com/[my-github-username]/mifiel/fork )
|
114
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
115
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
116
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
117
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bump
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
import re, glob, sys, os
|
3
|
+
|
4
|
+
__USAGE__ = \
|
5
|
+
"""BUMP is a semantic versioning bump script which accepts the following
|
6
|
+
mutually exclusive arguments:
|
7
|
+
-m - a "major" version bump equal to +1.0.0
|
8
|
+
-n - a "minor" version bump equal to +0.1.0
|
9
|
+
-p - a "patch" version bump equal to +0.0.1
|
10
|
+
-h - a "hot fix" version bump equal to +0.0.1
|
11
|
+
|
12
|
+
All of these options allow for the -r flag, which indicates that the state
|
13
|
+
is a RELEASE not a SNAPSHOT. If -r is not specified, then -SNAPSHOT is
|
14
|
+
appended to the updated version string."""
|
15
|
+
|
16
|
+
__INITIAL__ = ['0', '0', '1']
|
17
|
+
|
18
|
+
|
19
|
+
if __name__ == "__main__":
|
20
|
+
v = []
|
21
|
+
try:
|
22
|
+
version_file = glob.glob("lib/*/version.rb")[0]
|
23
|
+
raw_v = re.search(r'VERSION = \'(.*)\'', open(version_file).read(), re.M|re.I|re.S).group(1)
|
24
|
+
v = re.split(re.compile("\.|-"), raw_v)
|
25
|
+
v = v[0:3]
|
26
|
+
map(int, v)
|
27
|
+
|
28
|
+
except ValueError:
|
29
|
+
print("failed to parse the existing VERSION file, assuming v 0.0.1")
|
30
|
+
v = ['0', '0', '1']
|
31
|
+
|
32
|
+
except FileNotFoundError:
|
33
|
+
print("failed to find a VERSION file, assuming v 0.0.0")
|
34
|
+
v = ['0', '0', '0']
|
35
|
+
|
36
|
+
op = ''
|
37
|
+
try:
|
38
|
+
op = sys.argv[1]
|
39
|
+
except:
|
40
|
+
print(__USAGE__)
|
41
|
+
sys.exit(-1)
|
42
|
+
|
43
|
+
if(op == '-m'):
|
44
|
+
v = [str(int(v[0])+1), '0', '0']
|
45
|
+
|
46
|
+
elif(op == '-n'):
|
47
|
+
v = [v[0], str(int(v[1])+1), '0']
|
48
|
+
|
49
|
+
elif(op == '-p' or op == '-h'):
|
50
|
+
v = [v[0], v[1], str(int(v[2])+1)]
|
51
|
+
|
52
|
+
else:
|
53
|
+
print(__USAGE__)
|
54
|
+
sys.exit(-1)
|
55
|
+
|
56
|
+
v = '.'.join(v)
|
57
|
+
|
58
|
+
if(op == '-h'):
|
59
|
+
os.system("git checkout -b hotfix/v%s master" % v)
|
60
|
+
|
61
|
+
else:
|
62
|
+
os.system("git checkout -b release/v%s develop" % v)
|
63
|
+
|
64
|
+
os.system("bump set %s" % v)
|
65
|
+
|
66
|
+
v += "\n"
|
67
|
+
|
68
|
+
print(v)
|
69
|
+
|
70
|
+
sys.exit(0)
|
data/lib/mifiel.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'active_rest_client'
|
2
|
+
|
3
|
+
module Mifiel
|
4
|
+
require 'mifiel/errors'
|
5
|
+
autoload :Base, 'mifiel/base'
|
6
|
+
autoload :Document, 'mifiel/document'
|
7
|
+
autoload :Certificate, 'mifiel/certificate'
|
8
|
+
autoload :Config, 'mifiel/config'
|
9
|
+
|
10
|
+
BASE_URL = 'https://www.mifiel.com/api/v1'
|
11
|
+
|
12
|
+
def self.config
|
13
|
+
if block_given?
|
14
|
+
yield(Mifiel::Config)
|
15
|
+
else
|
16
|
+
Mifiel::Config
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/mifiel/base.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Mifiel
|
2
|
+
class Base < ActiveRestClient::Base
|
3
|
+
after_request :rescue_errors
|
4
|
+
|
5
|
+
def rescue_errors(name, response)
|
6
|
+
if response.status == 400 # bad request
|
7
|
+
result = JSON.load(response.body)
|
8
|
+
message = result['errors'] || [result['error']]
|
9
|
+
raise BadRequestError, message.to_a.join(', ')
|
10
|
+
elsif (500..599).include?(response.status)
|
11
|
+
raise ServerError, "Server could not process your request: status #{response.status}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Mifiel
|
2
|
+
class Certificate < Mifiel::Base
|
3
|
+
|
4
|
+
get :all, '/keys'
|
5
|
+
get :find, '/keys/:id'
|
6
|
+
put :save, '/keys/:id'
|
7
|
+
get :sat, '/keys/sat'
|
8
|
+
|
9
|
+
def self.create(file:)
|
10
|
+
rest_request = RestClient::Request.new(
|
11
|
+
url: "#{Mifiel.config.base_url}/keys",
|
12
|
+
method: :post,
|
13
|
+
payload: {
|
14
|
+
cer_file: File.new(file)
|
15
|
+
},
|
16
|
+
ssl_version: 'SSLv23'
|
17
|
+
)
|
18
|
+
response = ApiAuth.sign!(rest_request, Mifiel.config.app_id, Mifiel.config.app_secret).execute
|
19
|
+
JSON.load(response)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Mifiel
|
2
|
+
module Config
|
3
|
+
class << self
|
4
|
+
attr_reader :app_id, :app_secret, :base_url
|
5
|
+
|
6
|
+
def reset
|
7
|
+
@app_id = nil
|
8
|
+
@app_secret = nil
|
9
|
+
@base_url = Mifiel::BASE_URL
|
10
|
+
end
|
11
|
+
|
12
|
+
def app_id=(app_id)
|
13
|
+
@app_id = app_id
|
14
|
+
set_api_auth_credentials
|
15
|
+
end
|
16
|
+
|
17
|
+
def app_secret=(app_secret)
|
18
|
+
@app_secret = app_secret
|
19
|
+
set_api_auth_credentials
|
20
|
+
end
|
21
|
+
|
22
|
+
def base_url=(base_url)
|
23
|
+
@base_url = base_url
|
24
|
+
set_api_auth_credentials
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def set_api_auth_credentials
|
30
|
+
ActiveRestClient::Base.base_url = base_url
|
31
|
+
ActiveRestClient::Base.api_auth_credentials(app_id, app_secret)
|
32
|
+
ActiveRestClient::Base.request_body_type = :json
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
reset
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'open3'
|
3
|
+
|
4
|
+
module Mifiel
|
5
|
+
class Document < Mifiel::Base
|
6
|
+
|
7
|
+
get :all, '/documents'
|
8
|
+
get :find, '/documents/:id'
|
9
|
+
put :save, '/documents/:id'
|
10
|
+
delete :delete, '/documents/:id'
|
11
|
+
|
12
|
+
def self.create(file:, signatories:, hash:nil)
|
13
|
+
sgries = {}
|
14
|
+
signatories.each_with_index {|s, i| sgries[i] = s}
|
15
|
+
rest_request = RestClient::Request.new(
|
16
|
+
url: "#{Mifiel.config.base_url}/documents",
|
17
|
+
method: :post,
|
18
|
+
payload: {
|
19
|
+
file: File.new(file),
|
20
|
+
hash: hash,
|
21
|
+
signatories: sgries
|
22
|
+
},
|
23
|
+
ssl_version: 'SSLv23'
|
24
|
+
)
|
25
|
+
response = ApiAuth.sign!(rest_request, Mifiel.config.app_id, Mifiel.config.app_secret).execute
|
26
|
+
JSON.load(response)
|
27
|
+
end
|
28
|
+
|
29
|
+
def sign(certificate_id:nil, certificate:nil)
|
30
|
+
fail ArgumentError, 'Either certificate_id or certificate must be provided' if !certificate_id && !certificate
|
31
|
+
fail ArgumentError, 'Only one of certificate_id or certificate must be provided' if certificate_id && certificate
|
32
|
+
fail NoSignatureError, 'You must first call build_signature or provide a signature' unless signature
|
33
|
+
params = { signature: signature }
|
34
|
+
params[:key] = certificate_id if certificate_id
|
35
|
+
params[:certificate] = certificate.unpack('H*')[0] if certificate
|
36
|
+
|
37
|
+
Mifiel::Document._request("#{Mifiel.config.base_url}/documents/#{id}/sign", :post, params)
|
38
|
+
rescue ActiveRestClient::HTTPClientException => e
|
39
|
+
message = e.result.errors || [e.result.error]
|
40
|
+
raise MifielError, message.to_a.join(', ')
|
41
|
+
rescue ActiveRestClient::HTTPServerException
|
42
|
+
raise MifielError, 'Server could not process request'
|
43
|
+
end
|
44
|
+
|
45
|
+
def build_signature(private_key, private_key_pass)
|
46
|
+
self.signature ||= sign_hash(private_key, private_key_pass, original_hash)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# Sign the provided hash
|
52
|
+
# @param key [String] The contents of the .key file (File.read(...))
|
53
|
+
# @param pass [String] The password of the key
|
54
|
+
# @param hash [String] The hash or string to sign
|
55
|
+
#
|
56
|
+
# @return [String] Hex string of the signature
|
57
|
+
def sign_hash(key, pass, hash)
|
58
|
+
private_key = build_private_key(key, pass)
|
59
|
+
unless private_key.private?
|
60
|
+
raise NotPrivateKeyError, "The private key is not valid"
|
61
|
+
end
|
62
|
+
signature = private_key.sign(OpenSSL::Digest::SHA256.new, hash)
|
63
|
+
signature.unpack('H*')[0]
|
64
|
+
end
|
65
|
+
|
66
|
+
def build_private_key(private_data, key_pass)
|
67
|
+
# create file so we can converted to pem
|
68
|
+
private_file = File.new("./tmp/tmp-#{rand(1000)}.key", 'w+')
|
69
|
+
private_file.write(private_data.force_encoding('UTF-8'))
|
70
|
+
private_file.close
|
71
|
+
|
72
|
+
key2pem_command = "openssl pkcs8 -in #{private_file.path} -inform DER -passin pass:#{key_pass}"
|
73
|
+
priv_pem_s, error, status = Open3.capture3(key2pem_command)
|
74
|
+
|
75
|
+
# delete file from file system
|
76
|
+
File.unlink private_file.path
|
77
|
+
fail PrivateKeyError.new("#{error}, #{status}") unless error.empty?
|
78
|
+
|
79
|
+
OpenSSL::PKey::RSA.new priv_pem_s
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module Mifiel
|
2
|
+
MifielError = Class.new StandardError
|
3
|
+
BadRequestError = Class.new StandardError
|
4
|
+
ServerError = Class.new StandardError
|
5
|
+
PrivateKeyError = Class.new StandardError
|
6
|
+
NotPrivateKeyError = Class.new ArgumentError
|
7
|
+
NoSignatureError = Class.new StandardError
|
8
|
+
end
|
data/mifiel.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mifiel/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'mifiel'
|
8
|
+
spec.version = Mifiel::VERSION
|
9
|
+
spec.authors = ['Genaro Madrid']
|
10
|
+
spec.email = ['genmadrid@gmail.com']
|
11
|
+
spec.summary = %q{Ruby SDK for mifiel.com.}
|
12
|
+
spec.homepage = 'https://github.com/Mifiel/ruby-api-client'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_runtime_dependency 'rest-client', '~> 1.7'
|
21
|
+
spec.add_runtime_dependency 'json', '~> 1.8'
|
22
|
+
spec.add_runtime_dependency 'api-auth', '~> 1.4'
|
23
|
+
spec.add_runtime_dependency 'active_rest_client', '~> 1.2'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.1', '>= 3.1.7'
|
28
|
+
spec.add_development_dependency 'pry', '~> 0.10', '>= 0.10.1'
|
29
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.3', '>= 3.3.0'
|
30
|
+
spec.add_development_dependency 'bump', '~> 0.5', '>= 0.5.3'
|
31
|
+
spec.add_development_dependency 'webmock', '~> 1.22', '>= 1.22.2'
|
32
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,77 @@
|
|
1
|
+
describe Mifiel::Document do
|
2
|
+
let!(:certificate) { File.read('spec/fixtures/FIEL_AAA010101AAA.cer') }
|
3
|
+
let!(:private_key) { File.read('spec/fixtures/FIEL_AAA010101AAA.key') }
|
4
|
+
let!(:private_key_pass) { '12345678a' }
|
5
|
+
|
6
|
+
describe '#create' do
|
7
|
+
context 'with a document' do
|
8
|
+
let(:document) do
|
9
|
+
Mifiel::Document.create(
|
10
|
+
file: 'spec/fixtures/example.pdf',
|
11
|
+
signatories: [
|
12
|
+
{ name: 'Signer 1', email: 'signer1@email.com', tax_id: 'AAA010101AAA' },
|
13
|
+
{ name: 'Signer 2', email: 'signer2@email.com', tax_id: 'AAA010102AAA' }
|
14
|
+
]
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
it { expect(document).to be_a(Hash) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#sign' do
|
23
|
+
let!(:signature) { 'signature' }
|
24
|
+
let!(:document) { Mifiel::Document.all.first }
|
25
|
+
|
26
|
+
context 'without build_signature first called' do
|
27
|
+
it do
|
28
|
+
expect{document.sign(certificate_id: 3)}.to raise_error(Mifiel::NoSignatureError)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with build_signature called before' do
|
33
|
+
it do
|
34
|
+
document.build_signature(private_key, private_key_pass)
|
35
|
+
expect{document.sign(certificate_id: 3)}.not_to raise_error
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with signature' do
|
40
|
+
it do
|
41
|
+
document.signature = signature
|
42
|
+
expect{document.sign(certificate_id: 3)}.not_to raise_error
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'with certificate' do
|
47
|
+
it do
|
48
|
+
document.build_signature(private_key, private_key_pass)
|
49
|
+
expect{document.sign(certificate: certificate)}.not_to raise_error
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#build_signature' do
|
55
|
+
let!(:document) { Mifiel::Document.all.first }
|
56
|
+
|
57
|
+
context 'with a wrong private_key' do
|
58
|
+
it do
|
59
|
+
expect{document.build_signature('asd', private_key_pass)}.to raise_error(Mifiel::PrivateKeyError)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'with a private_key that is not a private_key' do
|
64
|
+
xit do
|
65
|
+
cer = OpenSSL::X509::Certificate.new(certificate)
|
66
|
+
expect{document.build_signature(cer.public_key.to_der, private_key_pass)}.to raise_error(Mifiel::NotPrivateKeyError)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'with a wrong password' do
|
71
|
+
it do
|
72
|
+
expect{document.build_signature('asd', private_key_pass)}.to raise_error(Mifiel::PrivateKeyError)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'byebug'
|
3
|
+
require 'pry-byebug'
|
4
|
+
require 'mifiel'
|
5
|
+
# require 'webmock/rspec'
|
6
|
+
|
7
|
+
Dir['./spec/support/**/*.rb'].each { |f| require f }
|
8
|
+
|
9
|
+
# WebMock.disable_net_connect!
|
10
|
+
|
11
|
+
Mifiel.config do |config|
|
12
|
+
config.app_id = '138b94faa5a43d35f60208449f0e0916de29575e'
|
13
|
+
config.app_secret = 'mJM3igFcJp8Iu/euEtr0ZTAGixmE+4K5R9o2TEOQEQfAiEuB7MpVwgMULoDxhJvbIUCDZ5l2nnxgL93I5JBXEw=='
|
14
|
+
config.base_url = 'http://localhost:3000/api/v1'
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,257 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mifiel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Genaro Madrid
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: api-auth
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.4'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: active_rest_client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.2'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.6'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.6'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.1'
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 3.1.7
|
107
|
+
type: :development
|
108
|
+
prerelease: false
|
109
|
+
version_requirements: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - "~>"
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '3.1'
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 3.1.7
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: pry
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0.10'
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 0.10.1
|
127
|
+
type: :development
|
128
|
+
prerelease: false
|
129
|
+
version_requirements: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - "~>"
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0.10'
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: 0.10.1
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: pry-byebug
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - "~>"
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '3.3'
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: 3.3.0
|
147
|
+
type: :development
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - "~>"
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '3.3'
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: 3.3.0
|
157
|
+
- !ruby/object:Gem::Dependency
|
158
|
+
name: bump
|
159
|
+
requirement: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - "~>"
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0.5'
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 0.5.3
|
167
|
+
type: :development
|
168
|
+
prerelease: false
|
169
|
+
version_requirements: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0.5'
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: 0.5.3
|
177
|
+
- !ruby/object:Gem::Dependency
|
178
|
+
name: webmock
|
179
|
+
requirement: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - "~>"
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '1.22'
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: 1.22.2
|
187
|
+
type: :development
|
188
|
+
prerelease: false
|
189
|
+
version_requirements: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - "~>"
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '1.22'
|
194
|
+
- - ">="
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: 1.22.2
|
197
|
+
description:
|
198
|
+
email:
|
199
|
+
- genmadrid@gmail.com
|
200
|
+
executables: []
|
201
|
+
extensions: []
|
202
|
+
extra_rdoc_files: []
|
203
|
+
files:
|
204
|
+
- ".editorconfig"
|
205
|
+
- ".gitignore"
|
206
|
+
- ".rspec"
|
207
|
+
- ".rubocop.yml"
|
208
|
+
- ".ruby-gemset"
|
209
|
+
- ".ruby-version"
|
210
|
+
- Gemfile
|
211
|
+
- LICENSE.txt
|
212
|
+
- README.md
|
213
|
+
- Rakefile
|
214
|
+
- bump
|
215
|
+
- lib/mifiel.rb
|
216
|
+
- lib/mifiel/base.rb
|
217
|
+
- lib/mifiel/certificate.rb
|
218
|
+
- lib/mifiel/config.rb
|
219
|
+
- lib/mifiel/document.rb
|
220
|
+
- lib/mifiel/errors.rb
|
221
|
+
- lib/mifiel/version.rb
|
222
|
+
- mifiel.gemspec
|
223
|
+
- spec/fixtures/FIEL_AAA010101AAA.cer
|
224
|
+
- spec/fixtures/FIEL_AAA010101AAA.key
|
225
|
+
- spec/fixtures/example.pdf
|
226
|
+
- spec/mifiel/document_spec.rb
|
227
|
+
- spec/spec_helper.rb
|
228
|
+
homepage: https://github.com/Mifiel/ruby-api-client
|
229
|
+
licenses:
|
230
|
+
- MIT
|
231
|
+
metadata: {}
|
232
|
+
post_install_message:
|
233
|
+
rdoc_options: []
|
234
|
+
require_paths:
|
235
|
+
- lib
|
236
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
237
|
+
requirements:
|
238
|
+
- - ">="
|
239
|
+
- !ruby/object:Gem::Version
|
240
|
+
version: '0'
|
241
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
242
|
+
requirements:
|
243
|
+
- - ">="
|
244
|
+
- !ruby/object:Gem::Version
|
245
|
+
version: '0'
|
246
|
+
requirements: []
|
247
|
+
rubyforge_project:
|
248
|
+
rubygems_version: 2.2.2
|
249
|
+
signing_key:
|
250
|
+
specification_version: 4
|
251
|
+
summary: Ruby SDK for mifiel.com.
|
252
|
+
test_files:
|
253
|
+
- spec/fixtures/FIEL_AAA010101AAA.cer
|
254
|
+
- spec/fixtures/FIEL_AAA010101AAA.key
|
255
|
+
- spec/fixtures/example.pdf
|
256
|
+
- spec/mifiel/document_spec.rb
|
257
|
+
- spec/spec_helper.rb
|