Skip to content

Commit

Permalink
Merge branch 'release/v1.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
genaromadrid committed Nov 11, 2016
2 parents cb9cdee + 7bf0ecf commit 63d603d
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 23 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ notifications:
on_failure: always
script:
- mkdir ./tmp/
- bundle exec rubocop
- bundle exec rspec spec
2 changes: 1 addition & 1 deletion lib/mifiel.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'active_rest_client'
require 'flexirest'

module Mifiel
require 'mifiel/errors'
Expand Down
4 changes: 2 additions & 2 deletions lib/mifiel/base.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'rest-client'

module Mifiel
class Base < ActiveRestClient::Base
class Base < Flexirest::Base
after_request :rescue_errors

def rescue_errors(_name, response)
if (400..499).cover?(response.status)
result = JSON.load(response.body)
result = JSON.parse(response.body)
message = result['errors'] || [result['error']]
raise BadRequestError, message.to_a.join(', ')
elsif (500..599).cover?(response.status)
Expand Down
2 changes: 1 addition & 1 deletion lib/mifiel/certificate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.create(cer_file)
ssl_version: 'SSLv23'
)
req = ApiAuth.sign!(rest_request, Mifiel.config.app_id, Mifiel.config.app_secret)
JSON.load(req.execute)
Mifiel::Certificate.new(JSON.parse(req.execute))
end
end
end
6 changes: 3 additions & 3 deletions lib/mifiel/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def base_url=(base_url)
private

def set_api_auth_credentials
ActiveRestClient::Base.base_url = base_url
ActiveRestClient::Base.api_auth_credentials(app_id, app_secret)
ActiveRestClient::Base.request_body_type = :json
Flexirest::Base.base_url = base_url
Flexirest::Base.api_auth_credentials(app_id, app_secret)
Flexirest::Base.request_body_type = :json
end
end

Expand Down
12 changes: 10 additions & 2 deletions lib/mifiel/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ class Document < Mifiel::Base
put :save, '/documents/:id'
delete :delete, '/documents/:id'

def self.create(signatories:, file: nil, hash: nil, name: nil, callback_url: nil)
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def self.create(args)
signatories = args[:signatories]
file = args[:file]
hash = args[:hash]
name = args[:name]
callback_url = args[:callback_url]
raise ArgumentError, 'Either file or hash must be provided' if !file && !hash
raise ArgumentError, 'Only one of file or hash must be provided' if file && hash
payload = {
Expand All @@ -17,9 +23,11 @@ def self.create(signatories:, file: nil, hash: nil, name: nil, callback_url: nil
original_hash: hash,
name: name
}
payload = args.merge(payload)
response = process_request('/documents', :post, payload)
JSON.load(response)
Mifiel::Document.new(JSON.parse(response))
end
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize

def request_signature(email, cc: nil)
params = { email: email }
Expand Down
2 changes: 1 addition & 1 deletion lib/mifiel/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Mifiel
VERSION = '1.1.2'.freeze
VERSION = '1.1.3'.freeze
end
13 changes: 9 additions & 4 deletions mifiel.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'mifiel/version'

# rubocop:disable Metrics/BlockLength
Gem::Specification.new do |spec|
spec.name = 'mifiel'
spec.version = Mifiel::VERSION
Expand All @@ -19,10 +20,14 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '~> 2.1'

spec.add_runtime_dependency 'rest-client', '~> 1.7'
spec.add_runtime_dependency 'json', '~> 1.8'
spec.add_runtime_dependency 'api-auth', '~> 1.4'
spec.add_runtime_dependency 'activesupport', '~> 4.2.7'
spec.add_runtime_dependency 'active_rest_client', '~> 1.2'
spec.add_runtime_dependency 'json', '> 0'
spec.add_runtime_dependency 'api-auth', '> 1.4'
if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('2.2.2')
spec.add_runtime_dependency 'activesupport'
else
spec.add_runtime_dependency 'activesupport', '~> 4.2.7'
end
spec.add_runtime_dependency 'flexirest'

spec.add_development_dependency 'bundler', '~> 1.6'
spec.add_development_dependency 'rake', '~> 10.0'
Expand Down
2 changes: 1 addition & 1 deletion spec/mifiel/certificate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
)
end

it { expect(certificate).to be_a(Hash) }
it { expect(certificate).to be_a(Mifiel::Certificate) }
end

end
14 changes: 7 additions & 7 deletions spec/mifiel/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
)
end

it { expect(document).to be_a(Hash) }
it { expect(document).to be_a(Mifiel::Document) }
end
end

describe 'working with a document' do
let!(:document) { Mifiel::Document.all.first }

describe '#save_file' do
let!(:path) {'tmp/the-file.pdf' }
before { File.unlink(path) if File.exist?(path)}
let!(:path) { 'tmp/the-file.pdf' }
before { File.unlink(path) if File.exist?(path) }

it 'should get the file' do
document.save_file(path)
Expand All @@ -33,8 +33,8 @@
end

describe '#save_file_signed' do
let!(:path) {'tmp/the-file-signed.pdf' }
before { File.unlink(path) if File.exist?(path)}
let!(:path) { 'tmp/the-file-signed.pdf' }
before { File.unlink(path) if File.exist?(path) }

it 'should get the file' do
document.save_file_signed(path)
Expand All @@ -43,8 +43,8 @@
end

describe '#save_xml' do
let!(:path) {'tmp/the-xml.xml' }
before { File.unlink(path) if File.exist?(path)}
let!(:path) { 'tmp/the-xml.xml' }
before { File.unlink(path) if File.exist?(path) }

it 'should get the file' do
document.save_xml(path)
Expand Down
2 changes: 1 addition & 1 deletion spec/support/fake_mifiel.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'sinatra/base'

# rubocop:disable Metrics/ClassLength
class FakeMifiel < Sinatra::Base
get '/api/v1/keys' do
content_type :json
Expand Down

0 comments on commit 63d603d

Please sign in to comment.