Skip to content

Commit

Permalink
General fixes and refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrofurtado committed May 22, 2022
1 parent c72b1a3 commit 362ef16
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ SDK Ruby de integração eRede.
```ruby
# Configuração do ambiente
store = Erede::Models::Store.new
store.token = '123'
store.filiation = '456'
store.token = '6069a026cf454706990a801ab5fe8e36'
store.filiation = '73854967'
store.environment = Erede::Environment.sandbox | Erede::Environment.production

# Inicialização da SDK
Expand Down
4 changes: 3 additions & 1 deletion lib/erede.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'json'
require 'net/http'

require 'erede/errors/cielo_error'
require 'erede/errors/erede_error'

require 'erede/responses/erede_response'

require 'erede/environment'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Erede
module Errors
class CieloError < StandardError
class EredeError < StandardError
end
end
end
8 changes: 8 additions & 0 deletions lib/erede/responses/erede_response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Erede
module Responses
class EredeResponse
attr_accessor :code,
:response
end
end
end
7 changes: 4 additions & 3 deletions lib/erede/services/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ def send_request(method, body = '')
end
)

raise(Erede::Errors::CieloError, "Something goes wrong: #{response.code} #{response.body}") if response.code.to_i >= 400

JSON.parse(response.body)
Erede::Responses::EredeResponse.new.tap do |erede_response|
erede_response.code = response.code
erede_response.response = JSON.parse(response.body)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/erede/services/get_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class GetTransaction < ::Erede::Services::Base
:reference

def url
raise(Erede::Errors::CieloError, 'You need to specify one: the tid or the reference') if !tid && !reference
raise(Erede::Errors::EredeError, 'You need to specify one: the tid or the reference') if !tid && !reference
return "#{super}?reference=#{reference}" if reference
return "#{super}/#{tid}/refunds#{refundId ? '/' + refundId.to_s : ''}" if refunds
"#{super}/#{tid}"
Expand Down
3 changes: 3 additions & 0 deletions spec/errors/erede_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RSpec.describe Erede::Errors::EredeError do
it { expect(described_class).to be < StandardError }
end
10 changes: 10 additions & 0 deletions spec/responses/erede_response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RSpec.describe Erede::Responses::EredeResponse do
let(:model) { described_class.new }

context 'has defined' do
it 'response attributes' do
expect(subject).to respond_to :code
expect(subject).to respond_to :response
end
end
end

0 comments on commit 362ef16

Please sign in to comment.