mifiel 1.3.0 → 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: 30f7aeb18c7ac08adcaf698ef656976b80e6d0224252f1ae6b4b17798d973c6c
4
- data.tar.gz: 7cf15f910e58163c971cc6a215dda296ece97db1a0bc11e6c4d37212284b9b9e
3
+ metadata.gz: 7808cc60c36b233e6dc0ad9a8150e50c7125696a6e7ee71b66c7819196c36c5f
4
+ data.tar.gz: 7a9ecaeec4311683bdf5b5f878ab871895d83cc810cc4b4164006b731b9b3f54
5
5
  SHA512:
6
- metadata.gz: 45d708a1dcf7f74580e1bffb8f954992068e70cec202e3826aaf28da5909d533df49068ad368169b5b2c48576180d8ea34177480dc2e25d41fc4f8c125b1832b
7
- data.tar.gz: 20fbd3b40b3b0ecabc40185f240a0810e3029585ad9a075bcd66b852ca8a23a77b9923ac8688080280730cb3e7b241eb34d699c9f5394fb5a7d9c267a896a882
6
+ metadata.gz: fcb6a68adf72928f3a6db46f4894b8878c023a0ac11cbccd6daca422cfe428288402964661170ef381606d41b5f3fe53c0c2ac3c1aafab335722e213fbce9f7b
7
+ data.tar.gz: 8088355a100b92b8b793351165c37e710477d61ad112d4da44e1d2c9c26223832190d47ffc9b75cdabf15b776e3e6b897b14431a8a566480c90f248f4f42e0c1
data/.gitignore CHANGED
@@ -18,3 +18,4 @@ rubocop.html
18
18
  *.sublime-workspace
19
19
  vendor
20
20
  gemfiles/*.lock
21
+ .idea
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,12 +5,13 @@ 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
12
+ - 2.7
13
+ - 3.0
14
+ - 3.1
14
15
 
15
16
  notifications:
16
17
  email:
@@ -24,8 +25,14 @@ script:
24
25
 
25
26
  matrix:
26
27
  exclude:
27
- - rvm: 2.3
28
- gemfile: gemfiles/rails_6.gemfile
29
- - rvm: 2.4
30
- 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
31
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,153 +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>'
34
+ # remove the next line when you wish to use the prod environment
35
+ config.base_url = 'https://app-sandbox.mifiel.com/api/v1'
41
36
  end
42
37
  ```
43
38
 
44
- Document methods:
45
-
46
- - Find:
47
-
48
- ```ruby
49
- document = Mifiel::Document.find('id')
50
- document.original_hash
51
- document.file
52
- document.file_signed
53
- # ...
54
- ```
55
-
56
- - Find all:
57
-
58
- ```ruby
59
- documents = Mifiel::Document.all
60
- ```
61
-
62
- - Create:
63
-
64
- > Use only **hash** if you dont want us to have the file.<br>
65
- > Either **file** or **hash** must be provided.
66
-
67
- ```ruby
68
- document = Mifiel::Document.create(
69
- file: 'path/to/my-file.pdf',
70
- signatories: [
71
- { name: 'Signer 1', email: 'signer1@email.com', tax_id: 'AAA010101AAA' },
72
- { name: 'Signer 2', email: 'signer2@email.com', tax_id: 'AAA010102AAA' }
73
- ]
74
- )
75
- # if you dont want us to have the PDF, you can just send us
76
- # the original_hash and the name of the document. Both are required
77
- document = Mifiel::Document.create(
78
- hash: Digest::SHA256.hexdigest(File.read('path/to/my-file.pdf')),
79
- name: 'my-file.pdf',
80
- signatories: [...]
81
- )
82
- ```
83
-
84
- - Save Document related files
85
-
86
- ```ruby
87
- # save the original file
88
- document.save_file('path/to/save/file.pdf')
89
- # save the signed file (original file + signatures page)
90
- document.save_file_signed('path/to/save/file-signed.pdf')
91
- # save the signed xml file
92
- document.save_xml('path/to/save/xml.xml')
93
- ```
94
-
95
- - Sign:
96
- + With a pre-created Certificate
97
-
98
- ```ruby
99
- certificate = Mifiel::Certificate.find('cert-id')
100
- document.sign(certificate_id: certificate.id)
101
- ```
102
-
103
- + With a new one
104
-
105
- ```ruby
106
- document.sign(certificate: File.read('FIEL_AAA010101AAA.cer'))
107
- ```
108
-
109
- - Delete
110
-
111
- ```ruby
112
- document.delete
113
- ```
114
-
115
- Certificate methods:
116
-
117
- - Sat Certificates
118
-
119
- ```ruby
120
- sat_certificates = Mifiel::Certificate.sat
121
- ```
122
-
123
- - Find:
124
-
125
- ```ruby
126
- certificate = Mifiel::Certificate.find('id')
127
- certificate.cer_hex
128
- certificate.type_of
129
- # ...
130
- ```
131
-
132
- - Find all:
133
-
134
- ```ruby
135
- certificates = Mifiel::Certificate.all
136
- ```
137
-
138
- - Create
139
-
140
- ```ruby
141
- certificate = Mifiel::Certificate.create(
142
- file: 'path/to/my-certificate.cer'
143
- )
144
- ```
145
-
146
- - Delete
147
-
148
- ```ruby
149
- certificate.delete
150
- ```
151
-
152
- User methods
153
-
154
- - Setup Widget
155
-
156
- ```ruby
157
- args = {
158
- email: 'some@email.com',
159
- tax_id: 'AAA010101AAA',
160
- callback_url: 'http://some-callback.url'
161
- }
162
-
163
- user = Mifiel::User.setup_widget(args)
164
- user.widget_id
165
- ```
166
-
167
- Filtering Results
168
-
169
- 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):
170
-
171
- ```ruby
172
- document = Mifiel::Document.find('id')
173
- document.signers.where(field: /receiver|issuer/, email: 'some@email.com')
174
- ```
175
-
176
39
  ## Contributing
177
40
 
178
41
  1. Fork it ( https://github.com/[my-github-username]/mifiel/fork )
@@ -181,15 +44,9 @@ Our API returns a JSON list of items, this result can be filtered using a `where
181
44
  4. Push to the branch (`git push origin my-new-feature`)
182
45
  5. Create a new Pull Request
183
46
 
184
-
185
47
  [gem-version-image]: https://badge.fury.io/rb/mifiel.svg
186
48
  [gem-version-url]: https://badge.fury.io/rb/mifiel
187
-
188
- [security-url]: https://hakiri.io/github/Mifiel/ruby-api-client/master
189
- [security-image]: https://hakiri.io/github/Mifiel/ruby-api-client/master.svg
190
-
191
49
  [travis-image]: https://travis-ci.org/Mifiel/ruby-api-client.svg?branch=master
192
50
  [travis-url]: https://travis-ci.org/Mifiel/ruby-api-client
193
-
194
51
  [coveralls-image]: https://coveralls.io/repos/github/Mifiel/ruby-api-client/badge.svg?branch=master
195
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,45 +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)
52
+ Mifiel::Base.process_request("/documents/#{id}/request_signature", :post, payload: params)
43
53
  end
44
54
 
45
55
  def save_file(path)
46
- response = Mifiel::Document.process_request("/documents/#{id}/file", :get)
47
- File.open(path, 'wb') { |file| file.write(response) }
56
+ File.binwrite(path, raw_file)
48
57
  end
49
58
 
50
59
  def save_file_signed(path)
51
- response = Mifiel::Document.process_request("/documents/#{id}/file_signed", :get)
52
- File.open(path, 'wb') { |file| file.write(response) }
60
+ File.binwrite(path, raw_file_signed)
53
61
  end
54
62
 
55
63
  def save_xml(path)
56
- response = Mifiel::Document.process_request("/documents/#{id}/xml", :get)
57
- File.open(path, 'w') { |file| file.write(response) }
58
- end
59
-
60
- def self.process_request(path, method, payload = nil)
61
- rest_request = RestClient::Request.new(
62
- url: "#{Mifiel.config.base_url}/#{path.gsub(%r{^\/}, '')}",
63
- method: method,
64
- payload: payload,
65
- ssl_version: 'SSLv23'
66
- )
67
- req = ApiAuth.sign!(rest_request, Mifiel.config.app_id, Mifiel.config.app_secret)
68
- req.execute
64
+ File.write(path, raw_xml)
69
65
  end
70
66
 
71
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.0'
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,12 +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 'byebug', '~> 9.0', '< 9.0.6'
33
- spec.add_development_dependency 'pry-byebug', '~> 3.4', '>= 3.3.0'
34
- spec.add_development_dependency 'rake', '~> 10.0'
35
- spec.add_development_dependency 'rspec', '~> 3.1', '>= 3.1.7'
36
- spec.add_development_dependency 'rubocop', '~> 0.79.0'
37
- spec.add_development_dependency 'simplecov', '~> 0.15'
34
+ spec.add_development_dependency 'rake'
35
+ spec.add_development_dependency 'rspec'
36
+ spec.add_development_dependency 'simplecov'
38
37
  spec.add_development_dependency 'sinatra'
39
38
  spec.add_development_dependency 'webmock'
39
+ spec.metadata['rubygems_mfa_required'] = 'true'
40
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,13 +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
+
73
+ describe '#raw_file' do
74
+ let(:document_content) { 'some-pdf-formatted-string' }
75
+
76
+ it 'gets the file raw data' do
77
+ expect(document.raw_file).to eq document_content
78
+ end
79
+ end
80
+
81
+ describe '#raw_file_signed' do
82
+ let(:document_content) { 'some-pdf-formatted-string' }
83
+
84
+ it 'gets the file raw signed data' do
85
+ expect(document.raw_file_signed).to eq document_content
86
+ end
87
+ end
72
88
 
73
89
  describe '#save_file' do
74
90
  let!(:path) { 'tmp/the-file.pdf' }
75
- before { File.unlink(path) if File.exist?(path) }
76
91
 
77
- it 'should get the file' do
92
+ before { FileUtils.rm_f(path) }
93
+
94
+ it 'gets the file' do
78
95
  document.save_file(path)
79
96
  expect(File.exist?(path)).to be true
80
97
  end
@@ -82,9 +99,10 @@ describe Mifiel::Document do
82
99
 
83
100
  describe '#save_file_signed' do
84
101
  let!(:path) { 'tmp/the-file-signed.pdf' }
85
- before { File.unlink(path) if File.exist?(path) }
86
102
 
87
- it 'should get the file' do
103
+ before { FileUtils.rm_f(path) }
104
+
105
+ it 'gets the file' do
88
106
  document.save_file_signed(path)
89
107
  expect(File.exist?(path)).to be true
90
108
  end
@@ -92,9 +110,10 @@ describe Mifiel::Document do
92
110
 
93
111
  describe '#save_xml' do
94
112
  let!(:path) { 'tmp/the-xml.xml' }
95
- before { File.unlink(path) if File.exist?(path) }
96
113
 
97
- it 'should get the file' do
114
+ before { FileUtils.rm_f(path) }
115
+
116
+ it 'gets the file' do
98
117
  document.save_xml(path)
99
118
  expect(File.exist?(path)).to be true
100
119
  end
@@ -103,7 +122,7 @@ describe Mifiel::Document do
103
122
  describe '#request_signature' do
104
123
  let!(:error_body) { { errors: ['some error'] }.to_json }
105
124
 
106
- it '' do
125
+ it do
107
126
  expect do
108
127
  document.request_signature('some@email.com')
109
128
  end.not_to raise_error
@@ -111,11 +130,11 @@ describe Mifiel::Document do
111
130
 
112
131
  context 'when bad request' do
113
132
  before do
114
- url = %r{mifiel.com\/api\/v1\/documents\/#{document.id}\/request_signature}
133
+ url = %r{mifiel.com/api/v1/documents/#{document.id}/request_signature}
115
134
  stub_request(:post, url).to_return(body: error_body, status: 404)
116
135
  end
117
136
 
118
- it '' do
137
+ it do
119
138
  expect do
120
139
  document.request_signature('some@email.com')
121
140
  end.to raise_error(Mifiel::BadRequestError)
@@ -124,11 +143,11 @@ describe Mifiel::Document do
124
143
 
125
144
  context 'when server error' do
126
145
  before do
127
- url = %r{mifiel.com\/api\/v1\/documents\/#{document.id}\/request_signature}
146
+ url = %r{mifiel.com/api/v1/documents/#{document.id}/request_signature}
128
147
  stub_request(:post, url).to_return(body: error_body, status: 500)
129
148
  end
130
149
 
131
- it '' do
150
+ it do
132
151
  expect do
133
152
  document.request_signature('some@email.com')
134
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
@@ -1,16 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'pry'
4
- require 'byebug'
5
- require 'pry-byebug'
6
4
  require 'mifiel'
7
5
  require 'webmock/rspec'
8
-
9
6
  require 'simplecov'
10
7
  require 'coveralls'
8
+
11
9
  SimpleCov.start do
12
10
  add_filter '/spec/'
13
11
  end
12
+
14
13
  Coveralls.wear!
15
14
 
16
15
  Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
@@ -22,9 +21,12 @@ RSpec.configure do |config|
22
21
  conf.app_secret = 'APP_SECRET'
23
22
  conf.base_url = 'http://www.mifiel.com/api/v1'
24
23
  end
24
+
25
+ # Creates ruby-api-client/tmp folder so signed files can be saved correctly
26
+ Dir.mkdir 'tmp' unless File.directory? 'tmp'
25
27
  end
26
28
 
27
- config.before(:each) do
29
+ config.before do
28
30
  stub_request(:any, /mifiel.com/).to_rack(FakeMifiel)
29
31
  end
30
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.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genaro Madrid
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-19 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
@@ -129,107 +135,47 @@ dependencies:
129
135
  - !ruby/object:Gem::Version
130
136
  version: '0'
131
137
  - !ruby/object:Gem::Dependency
132
- name: byebug
133
- requirement: !ruby/object:Gem::Requirement
134
- requirements:
135
- - - "~>"
136
- - !ruby/object:Gem::Version
137
- version: '9.0'
138
- - - "<"
139
- - !ruby/object:Gem::Version
140
- version: 9.0.6
141
- type: :development
142
- prerelease: false
143
- version_requirements: !ruby/object:Gem::Requirement
144
- requirements:
145
- - - "~>"
146
- - !ruby/object:Gem::Version
147
- version: '9.0'
148
- - - "<"
149
- - !ruby/object:Gem::Version
150
- version: 9.0.6
151
- - !ruby/object:Gem::Dependency
152
- name: pry-byebug
138
+ name: rake
153
139
  requirement: !ruby/object:Gem::Requirement
154
140
  requirements:
155
141
  - - ">="
156
142
  - !ruby/object:Gem::Version
157
- version: 3.3.0
158
- - - "~>"
159
- - !ruby/object:Gem::Version
160
- version: '3.4'
143
+ version: '0'
161
144
  type: :development
162
145
  prerelease: false
163
146
  version_requirements: !ruby/object:Gem::Requirement
164
147
  requirements:
165
148
  - - ">="
166
149
  - !ruby/object:Gem::Version
167
- version: 3.3.0
168
- - - "~>"
169
- - !ruby/object:Gem::Version
170
- version: '3.4'
171
- - !ruby/object:Gem::Dependency
172
- name: rake
173
- requirement: !ruby/object:Gem::Requirement
174
- requirements:
175
- - - "~>"
176
- - !ruby/object:Gem::Version
177
- version: '10.0'
178
- type: :development
179
- prerelease: false
180
- version_requirements: !ruby/object:Gem::Requirement
181
- requirements:
182
- - - "~>"
183
- - !ruby/object:Gem::Version
184
- version: '10.0'
150
+ version: '0'
185
151
  - !ruby/object:Gem::Dependency
186
152
  name: rspec
187
153
  requirement: !ruby/object:Gem::Requirement
188
154
  requirements:
189
- - - "~>"
190
- - !ruby/object:Gem::Version
191
- version: '3.1'
192
155
  - - ">="
193
156
  - !ruby/object:Gem::Version
194
- version: 3.1.7
157
+ version: '0'
195
158
  type: :development
196
159
  prerelease: false
197
160
  version_requirements: !ruby/object:Gem::Requirement
198
161
  requirements:
199
- - - "~>"
200
- - !ruby/object:Gem::Version
201
- version: '3.1'
202
162
  - - ">="
203
163
  - !ruby/object:Gem::Version
204
- version: 3.1.7
205
- - !ruby/object:Gem::Dependency
206
- name: rubocop
207
- requirement: !ruby/object:Gem::Requirement
208
- requirements:
209
- - - "~>"
210
- - !ruby/object:Gem::Version
211
- version: 0.79.0
212
- type: :development
213
- prerelease: false
214
- version_requirements: !ruby/object:Gem::Requirement
215
- requirements:
216
- - - "~>"
217
- - !ruby/object:Gem::Version
218
- version: 0.79.0
164
+ version: '0'
219
165
  - !ruby/object:Gem::Dependency
220
166
  name: simplecov
221
167
  requirement: !ruby/object:Gem::Requirement
222
168
  requirements:
223
- - - "~>"
169
+ - - ">="
224
170
  - !ruby/object:Gem::Version
225
- version: '0.15'
171
+ version: '0'
226
172
  type: :development
227
173
  prerelease: false
228
174
  version_requirements: !ruby/object:Gem::Requirement
229
175
  requirements:
230
- - - "~>"
176
+ - - ">="
231
177
  - !ruby/object:Gem::Version
232
- version: '0.15'
178
+ version: '0'
233
179
  - !ruby/object:Gem::Dependency
234
180
  name: sinatra
235
181
  requirement: !ruby/object:Gem::Requirement
@@ -258,7 +204,7 @@ dependencies:
258
204
  - - ">="
259
205
  - !ruby/object:Gem::Version
260
206
  version: '0'
261
- description:
207
+ description:
262
208
  email:
263
209
  - genmadrid@gmail.com
264
210
  executables: []
@@ -278,6 +224,7 @@ files:
278
224
  - bump
279
225
  - gemfiles/rails_5.gemfile
280
226
  - gemfiles/rails_6.gemfile
227
+ - gemfiles/rails_7.gemfile
281
228
  - lib/mifiel.rb
282
229
  - lib/mifiel/base.rb
283
230
  - lib/mifiel/certificate.rb
@@ -302,34 +249,25 @@ files:
302
249
  homepage: https://www.mifiel.com
303
250
  licenses:
304
251
  - MIT
305
- metadata: {}
306
- post_install_message:
252
+ metadata:
253
+ rubygems_mfa_required: 'true'
254
+ post_install_message:
307
255
  rdoc_options: []
308
256
  require_paths:
309
257
  - lib
310
258
  required_ruby_version: !ruby/object:Gem::Requirement
311
259
  requirements:
312
- - - "~>"
260
+ - - ">="
313
261
  - !ruby/object:Gem::Version
314
- version: '2.3'
262
+ version: '2.6'
315
263
  required_rubygems_version: !ruby/object:Gem::Requirement
316
264
  requirements:
317
265
  - - ">="
318
266
  - !ruby/object:Gem::Version
319
267
  version: '0'
320
268
  requirements: []
321
- rubygems_version: 3.0.6
322
- signing_key:
269
+ rubygems_version: 3.1.6
270
+ signing_key:
323
271
  specification_version: 4
324
272
  summary: Ruby SDK for mifiel.com.
325
- test_files:
326
- - spec/fixtures/FIEL_AAA010101AAA.cer
327
- - spec/fixtures/FIEL_AAA010101AAA.key
328
- - spec/fixtures/example.pdf
329
- - spec/mifiel/base_spec.rb
330
- - spec/mifiel/certificate_spec.rb
331
- - spec/mifiel/document_spec.rb
332
- - spec/mifiel/template_spec.rb
333
- - spec/mifiel/user_spec.rb
334
- - spec/spec_helper.rb
335
- - spec/support/fake_mifiel.rb
273
+ test_files: []