Class: Fawry::Connection

Inherits:
Object
  • Object
show all
Extended by:
Utils
Defined in:
lib/fawry/connection.rb

Defined Under Namespace

Classes: ParamsSpecialEncoder

Constant Summary collapse

FAWRY_BASE_URL =
'https://www.atfawry.com/ECommerceWeb/Fawry/'
FAWRY_SANDBOX_BASE_URL =
'https://atfawry.fawrystaging.com//ECommerceWeb/Fawry/'

Constants included from Utils

Utils::TRUTH_VALUES

Class Method Summary collapse

Methods included from Utils

enrich_object

Class Method Details

.delete(path, params, body, options) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# 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) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# 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) ⇒ Object



15
16
17
18
19
20
21
22
23
# 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