class MercadoPago::Base

Attributes

access_token[R]

Public Class Methods

new(access_token: '', sandbox: true) click to toggle source
# File lib/mercadopago/base.rb, line 12
def initialize(access_token: '', sandbox: true)
  @access_token = access_token
  @sandbox = sandbox
end

Public Instance Methods

service_url() click to toggle source
# File lib/mercadopago/base.rb, line 17
def service_url
  raise NotImplementedError
end

Private Instance Methods

connection() click to toggle source
# File lib/mercadopago/base.rb, line 23
def connection
  @connection ||= Faraday.new(service_url) do |config|
    config.request :json
    config.response :raise_error
    config.response :json, content_type: /\bjson$/
    config.use :instrumentation
    config.options[:timeout] = 10
    config.use Faraday::RequestId
    config.adapter Faraday.default_adapter
  end
end
process_response(response) click to toggle source
# File lib/mercadopago/base.rb, line 35
def process_response(response)
  if response.success?
    body = response.body
    if body.empty?
      {}
    elsif body.is_a?(Array)
      body.map(&:deep_symbolize_keys)
    else
      body.deep_symbolize_keys
    end
  end
end