Skip to content

Commit

Permalink
Configuration of Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrofurtado committed May 22, 2022
1 parent 362ef16 commit 7017cdc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SDK Ruby de integração eRede.
store = Erede::Models::Store.new
store.token = '6069a026cf454706990a801ab5fe8e36'
store.filiation = '73854967'
store.logger = Logger.new(STDOUT)
store.environment = Erede::Environment.sandbox | Erede::Environment.production

# Inicialização da SDK
Expand Down Expand Up @@ -50,7 +51,7 @@ sdk.capture(capture_transaction)
# POST /v1/transactions/{tid}/refunds
# https://developer.userede.com.br/e-rede#swagger_operations-Cancelamento-cancelarTransacao
callback_url = Erede::Models::Url.new
callback_url.kind = Erede::Models::Url::CALLBACK | Erede::Models::Url::THREE_D_SECURE_FAILURE | Erede::Models::Url::THREE_D_SECURE_SUCCESS
callback_url.kind = 'callback'
callback_url.url = 'https://cliente.callback.com.br'
cancel_transaction = Erede::Models::Transaction.new
cancel_transaction.tid = 123
Expand Down
3 changes: 2 additions & 1 deletion lib/erede/models/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class Store < ::Erede::Models::Base
:filiation
]

attr_accessor :environment
attr_accessor :environment,
:logger
end
end
end
11 changes: 6 additions & 5 deletions lib/erede/services/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ def send_request(method, body = '')
query_string = uri && uri.query && !uri.query.nil? && !uri.query.empty? ? "?#{uri.query}" : ''

response = Net::HTTP.new(uri.host, uri.port)
.tap do |net_http|
net_http.use_ssl = uri.scheme == 'https'
net_http.set_debug_output($stdout)
end
.tap { |net_http| net_http.use_ssl = uri.scheme == 'https' }
.request(
method.new(uri.path + query_string, { 'Content-Type': 'application/json', 'Transaction-Response': 'brand-return-opened' })
.tap do |request|
Expand All @@ -37,8 +34,12 @@ def send_request(method, body = '')
end
)

if store.logger
store.logger.info("RedeRequest - #{method.to_s.split('::').last.upcase} #{uri} - Response #{response.code} #{response.body}")
end

Erede::Responses::EredeResponse.new.tap do |erede_response|
erede_response.code = response.code
erede_response.code = response.code
erede_response.response = JSON.parse(response.body)
end
end
Expand Down

0 comments on commit 7017cdc

Please sign in to comment.