Class: AppUtils::BaseConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/app_utils.rb

Overview

base configuration class

Direct Known Subclasses

DarajaAuthProvider, Pay::AppConfig

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(is_sandbox: false) ⇒ BaseConfig

Returns a new instance of BaseConfig.



10
11
12
13
14
15
16
# File 'lib/ruby/app_utils.rb', line 10

def initialize(is_sandbox: false)
  @is_sandbox = is_sandbox
  @connection = Faraday.new(url: toggle_base_url, headers: { 'Content-Type' => 'application/json' }) do |f|
    f.request :url_encoded
    f.adapter Faraday.default_adapter
  end
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



7
8
9
# File 'lib/ruby/app_utils.rb', line 7

def connection
  @connection
end

#is_sandbox=(value) ⇒ Object (writeonly)

Sets the attribute is_sandbox

Parameters:

  • value

    the value to set the attribute is_sandbox to.



8
9
10
# File 'lib/ruby/app_utils.rb', line 8

def is_sandbox=(value)
  @is_sandbox = value
end

Instance Method Details

#toggle_base_urlString

toggle between sandbox and production daraja API urls

Returns:

  • (String)

    url



20
21
22
23
24
25
26
# File 'lib/ruby/app_utils.rb', line 20

def toggle_base_url
  if @is_sandbox
    'https://sandbox.safaricom.co.ke/'
  else
    'https://api.safaricom.co.ke/'
  end
end