mifiel 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1569646681fcf22ebc9758654ea1cd69335c0de8fea3be1d91a2141c0c06f83d
4
- data.tar.gz: fab079bd4ba6f4edb93a458c934b8e2f783b90296c00bc4e0d0ae0b9d8992d3b
3
+ metadata.gz: 7808cc60c36b233e6dc0ad9a8150e50c7125696a6e7ee71b66c7819196c36c5f
4
+ data.tar.gz: 7a9ecaeec4311683bdf5b5f878ab871895d83cc810cc4b4164006b731b9b3f54
5
5
  SHA512:
6
- metadata.gz: 34ea17ff1b1e888dec3ee6f9f5c2b3460bfa29dfc3629330880d0dfe831760e60e3271c2f80511d8edf2b9e0de3f5708944f221581cbf424b9ac13f7c3be303f
7
- data.tar.gz: 6f04cbd056834f0709067c43223c2f695c63e9ea9d2d51a2d6419cef800047065be3d46fe739406c9ed9d260cb7c01a6a123b89ae7e21bb6800b6f57726248ac
6
+ metadata.gz: fcb6a68adf72928f3a6db46f4894b8878c023a0ac11cbccd6daca422cfe428288402964661170ef381606d41b5f3fe53c0c2ac3c1aafab335722e213fbce9f7b
7
+ data.tar.gz: 8088355a100b92b8b793351165c37e710477d61ad112d4da44e1d2c9c26223832190d47ffc9b75cdabf15b776e3e6b897b14431a8a566480c90f248f4f42e0c1
data/.rubocop.yml CHANGED
@@ -1,5 +1,10 @@
1
+ require:
2
+ - rubocop-rspec
3
+
1
4
  AllCops:
2
- TargetRubyVersion: 2.3
5
+ TargetRubyVersion: 2.6
6
+ NewCops: enable
7
+ SuggestExtensions: false
3
8
  Exclude:
4
9
  - 'gemfiles/**/*'
5
10
 
@@ -16,3 +21,15 @@ Metrics/BlockLength:
16
21
  Exclude:
17
22
  - 'spec/**/*'
18
23
  - '*.gemspec'
24
+
25
+ Style/TrailingCommaInArguments:
26
+ EnforcedStyleForMultiline: consistent_comma
27
+
28
+ Style/TrailingCommaInArrayLiteral:
29
+ EnforcedStyleForMultiline: consistent_comma
30
+
31
+ Style/TrailingCommaInHashLiteral:
32
+ EnforcedStyleForMultiline: consistent_comma
33
+
34
+ RSpec/NestedGroups:
35
+ Enabled: false
data/.travis.yml CHANGED
@@ -5,11 +5,9 @@ sudo: false
5
5
  gemfile:
6
6
  - gemfiles/rails_5.gemfile
7
7
  - gemfiles/rails_6.gemfile
8
+ - gemfiles/rails_7.gemfile
8
9
 
9
10
  rvm:
10
- - 2.3
11
- - 2.4
12
- - 2.5
13
11
  - 2.6
14
12
  - 2.7
15
13
  - 3.0
@@ -27,8 +25,14 @@ script:
27
25
 
28
26
  matrix:
29
27
  exclude:
30
- - rvm: 2.3
31
- gemfile: gemfiles/rails_6.gemfile
32
- - rvm: 2.4
33
- gemfile: gemfiles/rails_6.gemfile
28
+ # rails 7 requires ruby > 2.7
29
+ - rvm: 2.6
30
+ gemfile: gemfiles/rails_7.gemfile
31
+ # rails 5 is too old for these ruby versions
32
+ - rvm: 2.7
33
+ gemfile: gemfiles/rails_5.gemfile
34
+ - rvm: 3.0
35
+ gemfile: gemfiles/rails_5.gemfile
36
+ - rvm: 3.1
37
+ gemfile: gemfiles/rails_5.gemfile
34
38
  fast_finish: true
data/Appraisals CHANGED
@@ -9,3 +9,8 @@ appraise 'rails-6' do
9
9
  gem 'rails', '6'
10
10
  gem 'sinatra'
11
11
  end
12
+
13
+ appraise 'rails-7' do
14
+ gem 'rails', '7'
15
+ gem 'sinatra'
16
+ end
data/Gemfile CHANGED
@@ -7,4 +7,7 @@ gemspec
7
7
 
8
8
  group :development, :test do
9
9
  gem 'coveralls', require: false
10
+ gem 'pry'
11
+ gem 'rubocop'
12
+ gem 'rubocop-rspec'
10
13
  end
data/README.md CHANGED
@@ -3,10 +3,9 @@
3
3
  [![Gem Version][gem-version-image]][gem-version-url]
4
4
  [![Build Status][travis-image]][travis-url]
5
5
  [![Coverage Status][coveralls-image]][coveralls-url]
6
- [![security][security-image]][security-url]
7
6
 
8
7
  Ruby SDK for [Mifiel](https://www.mifiel.com) API.
9
- Please read our [documentation](http://docs.mifiel.com/) for instructions on how to start using the API.
8
+ Please read our [documentation](https://docs.mifiel.com/) for instructions on how to start using the API.
10
9
 
11
10
  ## Installation
12
11
 
@@ -26,154 +25,17 @@ Or install it yourself as:
26
25
 
27
26
  ## Usage
28
27
 
29
- For your convenience Mifiel offers a Sandbox environment where you can confidently test your code.
30
-
31
- To start using the API in the Sandbox environment you need to first create an account at [sandbox.mifiel.com](https://sandbox.mifiel.com).
32
-
33
- Once you have an account you will need an APP_ID and an APP_SECRET which you can generate in [sandbox.mifiel.com/access_tokens](https://sandbox.mifiel.com/access_tokens).
34
-
35
- Then you can configure the gem with:
28
+ Follow the steps in our [documentation](https://docs.mifiel.com/) to create an account and get your access tokens, then you can configure the gem with:
36
29
 
37
30
  ```ruby
38
31
  Mifiel.config do |config|
39
32
  config.app_id = '<APP_ID>'
40
33
  config.app_secret = '<APP_SECRET>'
41
- config.base_url = 'https://app-sandbox.mifiel.com/api/v1' #remove this line when you wish to use the prod environment
34
+ # remove the next line when you wish to use the prod environment
35
+ config.base_url = 'https://app-sandbox.mifiel.com/api/v1'
42
36
  end
43
37
  ```
44
38
 
45
- Document methods:
46
-
47
- - Find:
48
-
49
- ```ruby
50
- document = Mifiel::Document.find('id')
51
- document.original_hash
52
- document.file
53
- document.file_signed
54
- # ...
55
- ```
56
-
57
- - Find all:
58
-
59
- ```ruby
60
- documents = Mifiel::Document.all
61
- ```
62
-
63
- - Create:
64
-
65
- > Use only **hash** if you dont want us to have the file.<br>
66
- > Either **file** or **hash** must be provided.
67
-
68
- ```ruby
69
- document = Mifiel::Document.create(
70
- file: 'path/to/my-file.pdf',
71
- signatories: [
72
- { name: 'Signer 1', email: 'signer1@email.com', tax_id: 'AAA010101AAA' },
73
- { name: 'Signer 2', email: 'signer2@email.com', tax_id: 'AAA010102AAA' }
74
- ]
75
- )
76
- # if you dont want us to have the PDF, you can just send us
77
- # the original_hash and the name of the document. Both are required
78
- document = Mifiel::Document.create(
79
- hash: Digest::SHA256.hexdigest(File.read('path/to/my-file.pdf')),
80
- name: 'my-file.pdf',
81
- signatories: [...]
82
- )
83
- ```
84
-
85
- - Save Document related files
86
-
87
- ```ruby
88
- # save the original file
89
- document.save_file('path/to/save/file.pdf')
90
- # save the signed file (original file + signatures page)
91
- document.save_file_signed('path/to/save/file-signed.pdf')
92
- # save the signed xml file
93
- document.save_xml('path/to/save/xml.xml')
94
- ```
95
-
96
- - Sign:
97
- + With a pre-created Certificate
98
-
99
- ```ruby
100
- certificate = Mifiel::Certificate.find('cert-id')
101
- document.sign(certificate_id: certificate.id)
102
- ```
103
-
104
- + With a new one
105
-
106
- ```ruby
107
- document.sign(certificate: File.read('FIEL_AAA010101AAA.cer'))
108
- ```
109
-
110
- - Delete
111
-
112
- ```ruby
113
- document.delete
114
- ```
115
-
116
- Certificate methods:
117
-
118
- - Sat Certificates
119
-
120
- ```ruby
121
- sat_certificates = Mifiel::Certificate.sat
122
- ```
123
-
124
- - Find:
125
-
126
- ```ruby
127
- certificate = Mifiel::Certificate.find('id')
128
- certificate.cer_hex
129
- certificate.type_of
130
- # ...
131
- ```
132
-
133
- - Find all:
134
-
135
- ```ruby
136
- certificates = Mifiel::Certificate.all
137
- ```
138
-
139
- - Create
140
-
141
- ```ruby
142
- certificate = Mifiel::Certificate.create(
143
- file: 'path/to/my-certificate.cer'
144
- )
145
- ```
146
-
147
- - Delete
148
-
149
- ```ruby
150
- certificate.delete
151
- ```
152
-
153
- User methods
154
-
155
- - Setup Widget
156
-
157
- ```ruby
158
- args = {
159
- email: 'some@email.com',
160
- tax_id: 'AAA010101AAA',
161
- callback_url: 'http://some-callback.url'
162
- }
163
-
164
- user = Mifiel::User.setup_widget(args)
165
- user.widget_id
166
- ```
167
-
168
- Filtering Results
169
-
170
- Our API returns a JSON list of items, this result can be filtered using a `where` method matching a specified criteria (or matching using regular expressions):
171
-
172
- ```ruby
173
- document = Mifiel::Document.find('id')
174
- document.signers.where(field: /receiver|issuer/, email: 'some@email.com')
175
- ```
176
-
177
39
  ## Contributing
178
40
 
179
41
  1. Fork it ( https://github.com/[my-github-username]/mifiel/fork )
@@ -182,15 +44,9 @@ Our API returns a JSON list of items, this result can be filtered using a `where
182
44
  4. Push to the branch (`git push origin my-new-feature`)
183
45
  5. Create a new Pull Request
184
46
 
185
-
186
47
  [gem-version-image]: https://badge.fury.io/rb/mifiel.svg
187
48
  [gem-version-url]: https://badge.fury.io/rb/mifiel
188
-
189
- [security-url]: https://hakiri.io/github/Mifiel/ruby-api-client/master
190
- [security-image]: https://hakiri.io/github/Mifiel/ruby-api-client/master.svg
191
-
192
49
  [travis-image]: https://travis-ci.org/Mifiel/ruby-api-client.svg?branch=master
193
50
  [travis-url]: https://travis-ci.org/Mifiel/ruby-api-client
194
-
195
51
  [coveralls-image]: https://coveralls.io/repos/github/Mifiel/ruby-api-client/badge.svg?branch=master
196
52
  [coveralls-url]: https://coveralls.io/github/Mifiel/ruby-api-client?branch=master
@@ -7,6 +7,9 @@ gem "sinatra"
7
7
 
8
8
  group :development, :test do
9
9
  gem "coveralls", require: false
10
+ gem "pry"
11
+ gem "rubocop"
12
+ gem "rubocop-rspec"
10
13
  end
11
14
 
12
15
  gemspec path: "../"
@@ -7,6 +7,9 @@ gem "sinatra"
7
7
 
8
8
  group :development, :test do
9
9
  gem "coveralls", require: false
10
+ gem "pry"
11
+ gem "rubocop"
12
+ gem "rubocop-rspec"
10
13
  end
11
14
 
12
15
  gemspec path: "../"
@@ -0,0 +1,15 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "7"
6
+ gem "sinatra"
7
+
8
+ group :development, :test do
9
+ gem "coveralls", require: false
10
+ gem "pry"
11
+ gem "rubocop"
12
+ gem "rubocop-rspec"
13
+ end
14
+
15
+ gemspec path: "../"
data/lib/mifiel/base.rb CHANGED
@@ -1,19 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rest-client'
4
-
5
3
  module Mifiel
6
4
  class Base < Flexirest::Base
7
5
  after_request :rescue_errors
8
6
 
9
7
  def rescue_errors(_name, response)
10
- if (400..499).cover?(response.status)
8
+ case response.status
9
+ when (400..499)
11
10
  result = JSON.parse(response.body)
12
11
  message = result['errors'] || [result['error']]
13
12
  raise BadRequestError, message.to_a.join(', ')
14
- elsif (500..599).cover?(response.status)
13
+ when (500..599)
15
14
  raise ServerError, "Could not process your request: status #{response.status}"
16
15
  end
17
16
  end
17
+
18
+ def self.process_request(path, mthd, payload: nil, type: false)
19
+ url = "#{Mifiel.config.base_url}/#{path.gsub(%r{^/}, '')}"
20
+ options = { request_body_type: type }
21
+ options[:plain] = true if type == :plain
22
+ _request(
23
+ url,
24
+ mthd,
25
+ payload,
26
+ options,
27
+ )
28
+ end
18
29
  end
19
30
  end
@@ -8,16 +8,8 @@ module Mifiel
8
8
  get :sat, '/keys/sat'
9
9
 
10
10
  def self.create(cer_file)
11
- rest_request = RestClient::Request.new(
12
- url: "#{Mifiel.config.base_url}/keys",
13
- method: :post,
14
- payload: {
15
- cer_file: File.new(cer_file)
16
- },
17
- ssl_version: 'SSLv23'
18
- )
19
- req = ApiAuth.sign!(rest_request, Mifiel.config.app_id, Mifiel.config.app_secret)
20
- Mifiel::Certificate.new(JSON.parse(req.execute))
11
+ payload = { cer_file: File.new(cer_file) }
12
+ process_request('/keys', :post, payload: payload, type: :form_multipart)
21
13
  end
22
14
  end
23
15
  end
data/lib/mifiel/config.rb CHANGED
@@ -30,8 +30,25 @@ module Mifiel
30
30
 
31
31
  def set_api_auth_credentials
32
32
  Flexirest::Base.base_url = base_url
33
- Flexirest::Base.api_auth_credentials(app_id, app_secret)
33
+ Flexirest::Base.api_auth_credentials(
34
+ app_id,
35
+ app_secret,
36
+ with_http_method: true,
37
+ )
34
38
  Flexirest::Base.request_body_type = :json
39
+ Flexirest::Base.faraday_config do |faraday|
40
+ faraday.headers['User-Agent'] = user_agent
41
+ end
42
+ end
43
+
44
+ def user_agent
45
+ [
46
+ "#{Gem::Platform::RUBY.upcase}/#{RUBY_VERSION}",
47
+ "mifiel/#{Mifiel::VERSION}",
48
+ "faraday/#{Faraday::VERSION}",
49
+ # there is no easy way to get OS version in ruby
50
+ "(#{RUBY_PLATFORM}/-)",
51
+ ].join(' ')
35
52
  end
36
53
  end
37
54
 
@@ -7,12 +7,23 @@ module Mifiel
7
7
  class Document < Mifiel::Base
8
8
  get :all, '/documents'
9
9
  get :find, '/documents/:id'
10
+
11
+ get :raw_file, '/documents/:id/file', plain: true
12
+ # @deprecated in favor of raw_file
13
+ get :raw_data, '/documents/:id/file', plain: true
14
+
15
+ get :raw_file_signed, '/documents/:id/file_signed', plain: true
16
+ # @deprecated in favor of raw_file_signed
17
+ get :raw_signed_data, '/documents/:id/file_signed', plain: true
18
+
19
+ get :raw_xml, '/documents/:id/xml', plain: true
20
+
10
21
  put :save, '/documents/:id'
11
22
  delete :delete, '/documents/:id'
12
23
  post :create_from_template, '/templates/:template_id/generate_document', timeout: 60
13
24
  post :create_many_from_template, '/templates/:template_id/generate_documents', timeout: 60
14
25
 
15
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
26
+ # rubocop:disable Metrics/MethodLength
16
27
  def self.create(args)
17
28
  signatories = args[:signatories]
18
29
  file = args[:file]
@@ -27,55 +38,30 @@ module Mifiel
27
38
  callback_url: callback_url,
28
39
  file: (File.new(file) if file),
29
40
  original_hash: hash,
30
- name: name
41
+ name: name,
31
42
  }
32
- payload = args.merge(payload)
33
- payload.reject! { |_k, v| v.nil? }
34
- response = process_request('/documents', :post, payload)
35
- Mifiel::Document.new(JSON.parse(response))
43
+ payload = args.merge(payload).compact
44
+ process_request('/documents', :post, payload: payload, type: :form_multipart)
36
45
  end
37
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
46
+ # rubocop:enable Metrics/MethodLength
38
47
 
39
- def request_signature(email, cc: nil) # rubocop:disable Naming/MethodParameterName
48
+ # @deprecated
49
+ def request_signature(email, cc: nil)
40
50
  params = { email: email }
41
51
  params[:cc] = cc if cc.is_a?(Array)
42
- Mifiel::Document._request("#{Mifiel.config.base_url}/documents/#{id}/request_signature", :post, params)
43
- end
44
-
45
- def raw_data
46
- response = Mifiel::Document.process_request("/documents/#{id}/file", :get)
47
-
48
- response.body
52
+ Mifiel::Base.process_request("/documents/#{id}/request_signature", :post, payload: params)
49
53
  end
50
54
 
51
55
  def save_file(path)
52
- File.open(path, 'wb') { |file| file.write(raw_data) }
53
- end
54
-
55
- def raw_signed_data
56
- response = Mifiel::Document.process_request("/documents/#{id}/file_signed", :get)
57
-
58
- response.body
56
+ File.binwrite(path, raw_file)
59
57
  end
60
58
 
61
59
  def save_file_signed(path)
62
- File.open(path, 'wb') { |file| file.write(raw_signed_data) }
60
+ File.binwrite(path, raw_file_signed)
63
61
  end
64
62
 
65
63
  def save_xml(path)
66
- response = Mifiel::Document.process_request("/documents/#{id}/xml", :get)
67
- File.open(path, 'w') { |file| file.write(response) }
68
- end
69
-
70
- def self.process_request(path, method, payload = nil)
71
- rest_request = RestClient::Request.new(
72
- url: "#{Mifiel.config.base_url}/#{path.gsub(%r{^\/}, '')}",
73
- method: method,
74
- payload: payload,
75
- ssl_version: 'SSLv23'
76
- )
77
- req = ApiAuth.sign!(rest_request, Mifiel.config.app_id, Mifiel.config.app_secret)
78
- req.execute
64
+ File.write(path, raw_xml)
79
65
  end
80
66
 
81
67
  def self.build_signatories(signatories)
@@ -18,7 +18,7 @@ module Mifiel
18
18
  template_id: id,
19
19
  identifier: identifier,
20
20
  documents: documents,
21
- callback_url: callback_url
21
+ callback_url: callback_url,
22
22
  )
23
23
  end
24
24
  end
data/lib/mifiel/user.rb CHANGED
@@ -3,27 +3,5 @@
3
3
  module Mifiel
4
4
  class User < Mifiel::Base
5
5
  post :setup_widget, '/users/setup-widget'
6
-
7
- def self.setup_widget(args) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
8
- email = args[:email]
9
- tax_id = args[:tax_id]
10
- callback_url = args[:callback_url]
11
-
12
- raise ArgumentError, 'Email must be provided' unless email
13
- raise ArgumentError, 'Tax id must be provided' unless tax_id
14
-
15
- rest_request = RestClient::Request.new(
16
- url: "#{Mifiel.config.base_url}/users/setup-widget",
17
- method: :post,
18
- payload: {
19
- email: email,
20
- tax_id: tax_id,
21
- callback_url: callback_url
22
- },
23
- ssl_version: 'SSLv23'
24
- )
25
- req = ApiAuth.sign!(rest_request, Mifiel.config.app_id, Mifiel.config.app_secret)
26
- Mifiel::User.new(JSON.parse(req.execute))
27
- end
28
6
  end
29
7
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mifiel
4
- VERSION = '1.3.1'
4
+ VERSION = '1.4.0'
5
5
  end
data/lib/mifiel.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'flexirest'
4
+ require 'mifiel/version'
4
5
 
5
6
  module Mifiel
6
7
  require 'mifiel/errors'
@@ -11,7 +12,7 @@ module Mifiel
11
12
  autoload :Config, 'mifiel/config'
12
13
  autoload :User, 'mifiel/user'
13
14
 
14
- BASE_URL = 'https://www.mifiel.com/api/v1'
15
+ BASE_URL = 'https://app.mifiel.com/api/v1'
15
16
 
16
17
  def self.config
17
18
  if block_given?
data/mifiel.gemspec CHANGED
@@ -16,12 +16,14 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0")
18
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
19
  spec.require_paths = ['lib']
21
- spec.required_ruby_version = '>= 2.3'
20
+ spec.required_ruby_version = '>= 2.6'
22
21
 
23
22
  spec.add_runtime_dependency 'activesupport'
24
- spec.add_runtime_dependency 'api-auth', '~> 1.4'
23
+
24
+ # 1.4 fixes a security MITM issue
25
+ # 2.5 is actually a breaking change: it changes the MD5 header
26
+ spec.add_runtime_dependency 'api-auth', '>= 1.4', '< 2.5'
25
27
  spec.add_runtime_dependency 'flexirest', '~> 1.6'
26
28
  spec.add_runtime_dependency 'json', '>= 1.8'
27
29
  spec.add_runtime_dependency 'rest-client', '>= 1.8'
@@ -29,10 +31,10 @@ Gem::Specification.new do |spec|
29
31
  spec.add_development_dependency 'appraisal'
30
32
  spec.add_development_dependency 'bump', '~> 0.5', '>= 0.5.3'
31
33
  spec.add_development_dependency 'bundler'
32
- spec.add_development_dependency 'rake', '~> 13.0'
33
- spec.add_development_dependency 'rspec', '~> 3.10'
34
- spec.add_development_dependency 'rubocop', '~> 1.24'
35
- spec.add_development_dependency 'simplecov', '~> 0.21'
34
+ spec.add_development_dependency 'rake'
35
+ spec.add_development_dependency 'rspec'
36
+ spec.add_development_dependency 'simplecov'
36
37
  spec.add_development_dependency 'sinatra'
37
38
  spec.add_development_dependency 'webmock'
39
+ spec.metadata['rubygems_mfa_required'] = 'true'
38
40
  end
@@ -3,8 +3,8 @@
3
3
  describe Mifiel::Base do
4
4
  describe 'rescue_errors' do
5
5
  describe 'when bad request' do
6
- it 'should raise error' do
7
- base = Mifiel::Base.new
6
+ it 'raises error' do
7
+ base = described_class.new
8
8
  expect do
9
9
  base.rescue_errors('blah', FakeResponse.new(400))
10
10
  end.to raise_error(Mifiel::BadRequestError)
@@ -12,8 +12,8 @@ describe Mifiel::Base do
12
12
  end
13
13
 
14
14
  describe 'when server error' do
15
- it 'should raise error' do
16
- base = Mifiel::Base.new
15
+ it 'raises error' do
16
+ base = described_class.new
17
17
  expect do
18
18
  base.rescue_errors('blah', FakeResponse.new(500))
19
19
  end.to raise_error(Mifiel::ServerError)
@@ -3,11 +3,11 @@
3
3
  describe Mifiel::Certificate do
4
4
  describe '#create' do
5
5
  let(:certificate) do
6
- Mifiel::Certificate.create(
7
- 'spec/fixtures/FIEL_AAA010101AAA.cer'
6
+ described_class.create(
7
+ 'spec/fixtures/FIEL_AAA010101AAA.cer',
8
8
  )
9
9
  end
10
10
 
11
- it { expect(certificate).to be_a(Mifiel::Certificate) }
11
+ it { expect(certificate).to be_a(described_class) }
12
12
  end
13
13
  end
@@ -1,65 +1,65 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  describe Mifiel::Document do
4
- let!(:certificate) { File.read('spec/fixtures/FIEL_AAA010101AAA.cer') }
5
- let!(:private_key) { File.read('spec/fixtures/FIEL_AAA010101AAA.key') }
6
- let!(:private_key_pass) { '12345678a' }
4
+ let(:certificate) { File.read('spec/fixtures/FIEL_AAA010101AAA.cer') }
5
+ let(:private_key) { File.read('spec/fixtures/FIEL_AAA010101AAA.key') }
6
+ let(:private_key_pass) { '12345678a' }
7
7
 
8
8
  describe '#create' do
9
9
  context 'with a document' do
10
10
  let(:document) do
11
- Mifiel::Document.create(
11
+ described_class.create(
12
12
  file: 'spec/fixtures/example.pdf',
13
13
  signatories: [
14
14
  { name: 'Signer 1', email: 'signer1@email.com', tax_id: 'AAA010101AAA' },
15
- { name: 'Signer 2', email: 'signer2@email.com', tax_id: 'AAA010102AAA' }
16
- ]
15
+ { name: 'Signer 2', email: 'signer2@email.com', tax_id: 'AAA010102AAA' },
16
+ ],
17
17
  )
18
18
  end
19
19
 
20
- it { expect(document).to be_a(Mifiel::Document) }
20
+ it { expect(document).to be_a(described_class) }
21
21
  end
22
22
 
23
- context 'from template' do
23
+ describe 'from template' do
24
24
  let!(:template_id) { 'c6c29866-7fd6-4f77-9ecd-eae8bc3a772a' }
25
25
  let!(:document) do
26
- Mifiel::Document.create_from_template(
26
+ described_class.create_from_template(
27
27
  template_id: template_id,
28
28
  fields: {
29
- name: 'some'
29
+ name: 'some',
30
30
  },
31
31
  signatories: [{
32
32
  name: 'Signer',
33
- email: 'signer@email.com'
33
+ email: 'signer@email.com',
34
34
  }, {
35
35
  name: 'Signer',
36
- email: 'signer@email.com'
37
- }]
36
+ email: 'signer@email.com',
37
+ },],
38
38
  )
39
39
  end
40
40
 
41
- it { expect(document).to be_a Mifiel::Document }
41
+ it { expect(document).to be_a described_class }
42
42
  end
43
43
 
44
- context 'many from template' do
44
+ describe 'many from template' do
45
45
  let!(:template_id) { 'c6c29866-7fd6-4f77-9ecd-eae8bc3a772a' }
46
46
  let!(:documents) do
47
- Mifiel::Document.create_many_from_template(
47
+ described_class.create_many_from_template(
48
48
  template_id: template_id,
49
49
  callback_url: 'http://some-callback.url/mifiel',
50
50
  identifier: 'name',
51
51
  documents: [{
52
52
  fields: {
53
- name: 'Some Name'
53
+ name: 'Some Name',
54
54
  },
55
55
  signatories: [{
56
56
  name: 'Signer',
57
- email: 'signer@email.com'
57
+ email: 'signer@email.com',
58
58
  }, {
59
59
  name: 'Signer',
60
- email: 'signer@email.com'
61
- }]
62
- }]
60
+ email: 'signer@email.com',
61
+ },],
62
+ }],
63
63
  )
64
64
  end
65
65
 
@@ -68,29 +68,30 @@ describe Mifiel::Document do
68
68
  end
69
69
 
70
70
  describe 'working with a document' do
71
- let!(:document) { Mifiel::Document.all.first }
71
+ let!(:document) { described_class.all.first }
72
72
 
73
- describe '#raw_data' do
73
+ describe '#raw_file' do
74
74
  let(:document_content) { 'some-pdf-formatted-string' }
75
75
 
76
- it 'should get the file raw data' do
77
- expect(document.raw_data).to eq document_content
76
+ it 'gets the file raw data' do
77
+ expect(document.raw_file).to eq document_content
78
78
  end
79
79
  end
80
80
 
81
- describe '#raw_signed_data' do
81
+ describe '#raw_file_signed' do
82
82
  let(:document_content) { 'some-pdf-formatted-string' }
83
83
 
84
- it 'should get the file raw signed data' do
85
- expect(document.raw_signed_data).to eq document_content
84
+ it 'gets the file raw signed data' do
85
+ expect(document.raw_file_signed).to eq document_content
86
86
  end
87
87
  end
88
88
 
89
89
  describe '#save_file' do
90
90
  let!(:path) { 'tmp/the-file.pdf' }
91
- before { File.unlink(path) if File.exist?(path) }
92
91
 
93
- it 'should get the file' do
92
+ before { FileUtils.rm_f(path) }
93
+
94
+ it 'gets the file' do
94
95
  document.save_file(path)
95
96
  expect(File.exist?(path)).to be true
96
97
  end
@@ -98,9 +99,10 @@ describe Mifiel::Document do
98
99
 
99
100
  describe '#save_file_signed' do
100
101
  let!(:path) { 'tmp/the-file-signed.pdf' }
101
- before { File.unlink(path) if File.exist?(path) }
102
102
 
103
- it 'should get the file' do
103
+ before { FileUtils.rm_f(path) }
104
+
105
+ it 'gets the file' do
104
106
  document.save_file_signed(path)
105
107
  expect(File.exist?(path)).to be true
106
108
  end
@@ -108,9 +110,10 @@ describe Mifiel::Document do
108
110
 
109
111
  describe '#save_xml' do
110
112
  let!(:path) { 'tmp/the-xml.xml' }
111
- before { File.unlink(path) if File.exist?(path) }
112
113
 
113
- it 'should get the file' do
114
+ before { FileUtils.rm_f(path) }
115
+
116
+ it 'gets the file' do
114
117
  document.save_xml(path)
115
118
  expect(File.exist?(path)).to be true
116
119
  end
@@ -119,7 +122,7 @@ describe Mifiel::Document do
119
122
  describe '#request_signature' do
120
123
  let!(:error_body) { { errors: ['some error'] }.to_json }
121
124
 
122
- it '' do
125
+ it do
123
126
  expect do
124
127
  document.request_signature('some@email.com')
125
128
  end.not_to raise_error
@@ -127,11 +130,11 @@ describe Mifiel::Document do
127
130
 
128
131
  context 'when bad request' do
129
132
  before do
130
- url = %r{mifiel.com\/api\/v1\/documents\/#{document.id}\/request_signature}
133
+ url = %r{mifiel.com/api/v1/documents/#{document.id}/request_signature}
131
134
  stub_request(:post, url).to_return(body: error_body, status: 404)
132
135
  end
133
136
 
134
- it '' do
137
+ it do
135
138
  expect do
136
139
  document.request_signature('some@email.com')
137
140
  end.to raise_error(Mifiel::BadRequestError)
@@ -140,11 +143,11 @@ describe Mifiel::Document do
140
143
 
141
144
  context 'when server error' do
142
145
  before do
143
- url = %r{mifiel.com\/api\/v1\/documents\/#{document.id}\/request_signature}
146
+ url = %r{mifiel.com/api/v1/documents/#{document.id}/request_signature}
144
147
  stub_request(:post, url).to_return(body: error_body, status: 500)
145
148
  end
146
149
 
147
- it '' do
150
+ it do
148
151
  expect do
149
152
  document.request_signature('some@email.com')
150
153
  end.to raise_error(Mifiel::ServerError)
@@ -4,35 +4,40 @@ describe Mifiel::Template do
4
4
  let!(:template_id) { 'bb7d65b4-47f1-470e-85e4-22ddae86f9ea' }
5
5
 
6
6
  shared_examples 'a valid template' do
7
- it { expect(template).to be_a(Mifiel::Template) }
7
+ it { expect(template).to be_a(described_class) }
8
8
  it { expect(template).to respond_to(:id) }
9
9
  it { expect(template).to respond_to(:name) }
10
10
  end
11
11
 
12
12
  describe '#create' do
13
- let!(:template) do
14
- Mifiel::Template.create(
13
+ let(:template) do
14
+ described_class.create(
15
15
  name: 'Some Template',
16
16
  content: '<div>Some <field name="name" type="string">NAME</field></div>',
17
17
  header: 'Genaros Header',
18
- footer: 'Genaros Footer'
18
+ footer: 'Genaros Footer',
19
19
  )
20
20
  end
21
+
21
22
  it_behaves_like 'a valid template'
22
23
  end
23
24
 
24
25
  describe '#find' do
25
- let!(:template) { Mifiel::Template.find(template_id) }
26
+ let!(:template) { described_class.find(template_id) }
26
27
 
27
28
  it_behaves_like 'a valid template'
28
29
  it { expect(template.id).to eq(template_id) }
29
30
  end
30
31
 
31
32
  describe '#all' do
32
- it 'should respond with many templates' do
33
- templates = Mifiel::Template.all
33
+ let(:templates) { described_class.all }
34
+
35
+ it 'responds with many templates' do
34
36
  expect(templates.count).to be > 0
35
- expect(templates.first).to be_a(Mifiel::Template)
37
+ end
38
+
39
+ it 'responds with a Template' do
40
+ expect(templates.first).to be_a(described_class)
36
41
  end
37
42
  end
38
43
  end
@@ -3,14 +3,14 @@
3
3
  describe Mifiel::User do
4
4
  describe '#setup_widget' do
5
5
  let(:user) do
6
- Mifiel::User.setup_widget(
6
+ described_class.setup_widget(
7
7
  email: 'user@email.com',
8
8
  tax_id: 'AAA010101AAA',
9
- callback_url: 'http://some-callback.url/mifiel'
9
+ callback_url: 'http://some-callback.url/mifiel',
10
10
  )
11
11
  end
12
12
 
13
13
  it { expect(user.success).to be_truthy }
14
- it { expect(user.widget_id).to_not be_nil }
14
+ it { expect(user.widget_id).not_to be_nil }
15
15
  end
16
16
  end
data/spec/spec_helper.rb CHANGED
@@ -26,7 +26,7 @@ RSpec.configure do |config|
26
26
  Dir.mkdir 'tmp' unless File.directory? 'tmp'
27
27
  end
28
28
 
29
- config.before(:each) do
29
+ config.before do
30
30
  stub_request(:any, /mifiel.com/).to_rack(FakeMifiel)
31
31
  end
32
32
  end
@@ -8,7 +8,7 @@ class FakeMifiel < Sinatra::Base # rubocop:disable Metrics/ClassLength
8
8
  status 200
9
9
  [
10
10
  key,
11
- key
11
+ key,
12
12
  ].to_json
13
13
  end
14
14
 
@@ -17,7 +17,7 @@ class FakeMifiel < Sinatra::Base # rubocop:disable Metrics/ClassLength
17
17
  status 200
18
18
  [
19
19
  template,
20
- template
20
+ template,
21
21
  ].to_json
22
22
  end
23
23
 
@@ -56,7 +56,7 @@ class FakeMifiel < Sinatra::Base # rubocop:disable Metrics/ClassLength
56
56
  status 200
57
57
  [
58
58
  document,
59
- document
59
+ document,
60
60
  ].to_json
61
61
  end
62
62
 
@@ -68,7 +68,7 @@ class FakeMifiel < Sinatra::Base # rubocop:disable Metrics/ClassLength
68
68
  original_hash: Digest::SHA256.hexdigest(params[:file][:tempfile].read),
69
69
  file_file_name: params[:file][:filename],
70
70
  signed: false,
71
- signed_at: nil
71
+ signed_at: nil,
72
72
  ).to_json
73
73
  end
74
74
 
@@ -76,7 +76,7 @@ class FakeMifiel < Sinatra::Base # rubocop:disable Metrics/ClassLength
76
76
  content_type :json
77
77
  status 200
78
78
  document(
79
- id: params[:id]
79
+ id: params[:id],
80
80
  ).to_json
81
81
  end
82
82
 
@@ -113,7 +113,7 @@ class FakeMifiel < Sinatra::Base # rubocop:disable Metrics/ClassLength
113
113
  {
114
114
  id: args[:id] || SecureRandom.uuid,
115
115
  name: 'some-template',
116
- content: '<div><field name="name">NAME</field></div>'
116
+ content: '<div><field name="name">NAME</field></div>',
117
117
  }
118
118
  end
119
119
 
@@ -126,7 +126,7 @@ class FakeMifiel < Sinatra::Base # rubocop:disable Metrics/ClassLength
126
126
  owner: 'JORGE MORALES MENDEZ',
127
127
  tax_id: 'MOMJ811012643',
128
128
  expires_at: '2017-04-28T19:43:23.000Z',
129
- expired: false
129
+ expired: false,
130
130
  }
131
131
  end
132
132
 
@@ -142,7 +142,7 @@ class FakeMifiel < Sinatra::Base # rubocop:disable Metrics/ClassLength
142
142
  status: [1, 'Firmado'],
143
143
  owner: {
144
144
  email: 'signer1@email.com',
145
- name: 'Jorge Morales'
145
+ name: 'Jorge Morales',
146
146
  },
147
147
  file: "/api/v1/documents/#{id}/file",
148
148
  file_download: "/api/v1/documents/#{id}/file?download=true",
@@ -158,9 +158,9 @@ class FakeMifiel < Sinatra::Base # rubocop:disable Metrics/ClassLength
158
158
  signature: '77cd5156779c..4e276ef1056c1de11b7f70bed28',
159
159
  user: {
160
160
  email: 'signer1@email.com',
161
- name: 'Jorge Morales'
162
- }
163
- }]
161
+ name: 'Jorge Morales',
162
+ },
163
+ }],
164
164
  }
165
165
  end
166
166
  end
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.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genaro Madrid
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-17 00:00:00.000000000 Z
11
+ date: 2022-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -28,16 +28,22 @@ dependencies:
28
28
  name: api-auth
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.4'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '2.5'
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - "~>"
41
+ - - ">="
39
42
  - !ruby/object:Gem::Version
40
43
  version: '1.4'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.5'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: flexirest
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -132,58 +138,44 @@ dependencies:
132
138
  name: rake
133
139
  requirement: !ruby/object:Gem::Requirement
134
140
  requirements:
135
- - - "~>"
141
+ - - ">="
136
142
  - !ruby/object:Gem::Version
137
- version: '13.0'
143
+ version: '0'
138
144
  type: :development
139
145
  prerelease: false
140
146
  version_requirements: !ruby/object:Gem::Requirement
141
147
  requirements:
142
- - - "~>"
148
+ - - ">="
143
149
  - !ruby/object:Gem::Version
144
- version: '13.0'
150
+ version: '0'
145
151
  - !ruby/object:Gem::Dependency
146
152
  name: rspec
147
153
  requirement: !ruby/object:Gem::Requirement
148
154
  requirements:
149
- - - "~>"
150
- - !ruby/object:Gem::Version
151
- version: '3.10'
152
- type: :development
153
- prerelease: false
154
- version_requirements: !ruby/object:Gem::Requirement
155
- requirements:
156
- - - "~>"
157
- - !ruby/object:Gem::Version
158
- version: '3.10'
159
- - !ruby/object:Gem::Dependency
160
- name: rubocop
161
- requirement: !ruby/object:Gem::Requirement
162
- requirements:
163
- - - "~>"
155
+ - - ">="
164
156
  - !ruby/object:Gem::Version
165
- version: '1.24'
157
+ version: '0'
166
158
  type: :development
167
159
  prerelease: false
168
160
  version_requirements: !ruby/object:Gem::Requirement
169
161
  requirements:
170
- - - "~>"
162
+ - - ">="
171
163
  - !ruby/object:Gem::Version
172
- version: '1.24'
164
+ version: '0'
173
165
  - !ruby/object:Gem::Dependency
174
166
  name: simplecov
175
167
  requirement: !ruby/object:Gem::Requirement
176
168
  requirements:
177
- - - "~>"
169
+ - - ">="
178
170
  - !ruby/object:Gem::Version
179
- version: '0.21'
171
+ version: '0'
180
172
  type: :development
181
173
  prerelease: false
182
174
  version_requirements: !ruby/object:Gem::Requirement
183
175
  requirements:
184
- - - "~>"
176
+ - - ">="
185
177
  - !ruby/object:Gem::Version
186
- version: '0.21'
178
+ version: '0'
187
179
  - !ruby/object:Gem::Dependency
188
180
  name: sinatra
189
181
  requirement: !ruby/object:Gem::Requirement
@@ -232,6 +224,7 @@ files:
232
224
  - bump
233
225
  - gemfiles/rails_5.gemfile
234
226
  - gemfiles/rails_6.gemfile
227
+ - gemfiles/rails_7.gemfile
235
228
  - lib/mifiel.rb
236
229
  - lib/mifiel/base.rb
237
230
  - lib/mifiel/certificate.rb
@@ -256,7 +249,8 @@ files:
256
249
  homepage: https://www.mifiel.com
257
250
  licenses:
258
251
  - MIT
259
- metadata: {}
252
+ metadata:
253
+ rubygems_mfa_required: 'true'
260
254
  post_install_message:
261
255
  rdoc_options: []
262
256
  require_paths:
@@ -265,7 +259,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
265
259
  requirements:
266
260
  - - ">="
267
261
  - !ruby/object:Gem::Version
268
- version: '2.3'
262
+ version: '2.6'
269
263
  required_rubygems_version: !ruby/object:Gem::Requirement
270
264
  requirements:
271
265
  - - ">="
@@ -276,14 +270,4 @@ rubygems_version: 3.1.6
276
270
  signing_key:
277
271
  specification_version: 4
278
272
  summary: Ruby SDK for mifiel.com.
279
- test_files:
280
- - spec/fixtures/FIEL_AAA010101AAA.cer
281
- - spec/fixtures/FIEL_AAA010101AAA.key
282
- - spec/fixtures/example.pdf
283
- - spec/mifiel/base_spec.rb
284
- - spec/mifiel/certificate_spec.rb
285
- - spec/mifiel/document_spec.rb
286
- - spec/mifiel/template_spec.rb
287
- - spec/mifiel/user_spec.rb
288
- - spec/spec_helper.rb
289
- - spec/support/fake_mifiel.rb
273
+ test_files: []