Class: JoyUssdEngine::Core
- Inherits:
-
Object
- Object
- JoyUssdEngine::Core
- Includes:
- SessionManager
- Defined in:
- lib/joy_ussd_engine.rb
Instance Attribute Summary collapse
-
#current_menu ⇒ Object
Returns the value of attribute current_menu.
-
#expiration ⇒ Object
Returns the value of attribute expiration.
-
#last_menu ⇒ Object
Returns the value of attribute last_menu.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#selected_provider ⇒ Object
readonly
Returns the value of attribute selected_provider.
Instance Method Summary collapse
-
#initialize(params, provider, start_point: nil, end_point: nil, expiration: nil) ⇒ Core
constructor
A new instance of Core.
- #load_from_paginate_menu(name) ⇒ Object
- #load_menu(name) ⇒ Object
- #process ⇒ Object
Methods included from SessionManager
#expire_mins, #get_state, #reset_state, #set_state, #user_mobile_number
Constructor Details
#initialize(params, provider, start_point: nil, end_point: nil, expiration: nil) ⇒ Core
Returns a new instance of Core.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/joy_ussd_engine.rb', line 19 def initialize(params, provider, start_point: nil, end_point: nil, expiration: nil ) # gets provider currently in use and convert params to match ussd engines params @expiration = expiration @selected_provider = provider.new(self) convert_params = @selected_provider.send("request_params",params) @params = convert_params @last_menu = end_point.to_s @data = get_state # handles ending or terminating ussd based on provider response (HUBTEL, TWILIO, ETC.) # If a particular provider returns some sort of response that can terminate the app we do that check here return @current_menu = end_point.to_s if @selected_provider.send("app_terminator", params) || @data[:ClientState] == 'EndJoyUssdEngine' if(@selected_provider.send("app_initiator", params) ) @current_menu = start_point.to_s reset_state return end @current_menu = @data[:ClientState].blank? ? start_point.to_s : @data[:ClientState] end |
Instance Attribute Details
#current_menu ⇒ Object
Returns the value of attribute current_menu.
17 18 19 |
# File 'lib/joy_ussd_engine.rb', line 17 def @current_menu end |
#expiration ⇒ Object
Returns the value of attribute expiration.
17 18 19 |
# File 'lib/joy_ussd_engine.rb', line 17 def expiration @expiration end |
#last_menu ⇒ Object
Returns the value of attribute last_menu.
17 18 19 |
# File 'lib/joy_ussd_engine.rb', line 17 def @last_menu end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
16 17 18 |
# File 'lib/joy_ussd_engine.rb', line 16 def params @params end |
#selected_provider ⇒ Object (readonly)
Returns the value of attribute selected_provider.
16 17 18 |
# File 'lib/joy_ussd_engine.rb', line 16 def selected_provider @selected_provider end |
Instance Method Details
#load_from_paginate_menu(name) ⇒ Object
46 47 48 49 |
# File 'lib/joy_ussd_engine.rb', line 46 def (name) = name.constantize.new(self) .send("run") end |
#load_menu(name) ⇒ Object
41 42 43 44 |
# File 'lib/joy_ussd_engine.rb', line 41 def (name) = name.constantize.new(self) .send("execute") end |
#process ⇒ Object
51 52 53 |
# File 'lib/joy_ussd_engine.rb', line 51 def process (@current_menu) end |