Class: Erede::Services::Base
- Inherits:
-
Object
- Object
- Erede::Services::Base
- Defined in:
- lib/erede/services/base.rb
Direct Known Subclasses
CancelTransaction, CaptureTransaction, CreateTransaction, GetTransaction
Constant Summary collapse
- POST =
Net::HTTP::Post
- GET =
Net::HTTP::Get
- PUT =
Net::HTTP::Put
Instance Attribute Summary collapse
-
#store ⇒ Object
Returns the value of attribute store.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(store) ⇒ Base
constructor
A new instance of Base.
- #send_request(method, body = '') ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(store) ⇒ Base
Returns a new instance of Base.
10 11 12 |
# File 'lib/erede/services/base.rb', line 10 def initialize(store) self.store = store end |
Instance Attribute Details
#store ⇒ Object
Returns the value of attribute store.
8 9 10 |
# File 'lib/erede/services/base.rb', line 8 def store @store end |
Instance Method Details
#execute ⇒ Object
18 19 20 |
# File 'lib/erede/services/base.rb', line 18 def execute raise NotImplementedError end |
#send_request(method, body = '') ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/erede/services/base.rb', line 22 def send_request(method, body = '') uri = URI(url) 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.verify_mode = 0 #=> OpenSSL::SSL::VERIFY_NONE end .request( method.new(uri.path + query_string, { 'Content-Type': 'application/json', 'Transaction-Response': 'brand-return-opened' }) .tap do |request| request.body = body request.basic_auth store.filiation, store.token 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.response = JSON.parse(response.body) end end |
#url ⇒ Object
14 15 16 |
# File 'lib/erede/services/base.rb', line 14 def url "#{store.environment.endpoint}/transactions" end |