Class: AppUtils::BaseConfig
- Inherits:
-
Object
- Object
- AppUtils::BaseConfig
- Defined in:
- lib/ruby/app_utils.rb
Overview
base configuration class
Direct Known Subclasses
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#is_sandbox ⇒ Object
writeonly
Sets the attribute is_sandbox.
Instance Method Summary collapse
-
#initialize(is_sandbox: false) ⇒ BaseConfig
constructor
A new instance of BaseConfig.
-
#toggle_base_url ⇒ String
toggle between sandbox and production daraja API urls.
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
#connection ⇒ Object
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
8 9 10 |
# File 'lib/ruby/app_utils.rb', line 8 def is_sandbox=(value) @is_sandbox = value end |
Instance Method Details
#toggle_base_url ⇒ String
toggle between sandbox and production daraja API urls
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 |