class Fawry::Connection

Constants

FAWRY_BASE_URL
FAWRY_SANDBOX_BASE_URL

Public Class Methods

delete(path, params, body, options) click to toggle source
# File lib/fawry/connection.rb, line 37
def delete(path, params, body, options)
  sandbox = Fawry.configuration.sandbox || TRUTH_VALUES.include?(ENV.fetch('FAWRY_SANDBOX', options[:sandbox]))
  conn =  sandbox ? sandbox_connection : connection

  conn.delete(path) do |request|
    request.params = params
    request.body = body.to_json
    # Fawry doesn't understand encoded params
    request.options = request.options.merge(params_encoder: ParamsSpecialEncoder)
  end
end
get(path, params, body, options) click to toggle source
# File lib/fawry/connection.rb, line 25
def get(path, params, body, options)
  sandbox = Fawry.configuration.sandbox || TRUTH_VALUES.include?(ENV.fetch('FAWRY_SANDBOX', options[:sandbox]))
  conn =  sandbox ? sandbox_connection : connection

  conn.get(path) do |request|
    request.params = params
    request.body = body.to_json
    # Fawry doesn't understand encoded params
    request.options = request.options.merge(params_encoder: ParamsSpecialEncoder)
  end
end
post(path, params, body, options) click to toggle source
# File lib/fawry/connection.rb, line 15
def post(path, params, body, options)
  sandbox = Fawry.configuration.sandbox || TRUTH_VALUES.include?(ENV.fetch('FAWRY_SANDBOX', options[:sandbox]))
  conn =  sandbox ? sandbox_connection : connection

  conn.post(path) do |request|
    request.params = params
    request.body = body.to_json
  end
end

Private Class Methods

connection() click to toggle source
# File lib/fawry/connection.rb, line 51
def connection
  @connection ||= Faraday.new(url: FAWRY_BASE_URL, headers: { 'Content-Type': 'application/json',
                                                              Accept: 'application/json' })
end
sandbox_connection() click to toggle source
# File lib/fawry/connection.rb, line 56
def sandbox_connection
  @sandbox_connection ||= Faraday.new(url: FAWRY_SANDBOX_BASE_URL, headers: { 'Content-Type': 'application/json',
                                                                              Accept: 'application/json' })
end