Class: JoyUssdEngine::Core

Inherits:
Object
  • Object
show all
Includes:
SessionManager
Defined in:
lib/joy_ussd_engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_menuObject

Returns the value of attribute current_menu.



17
18
19
# File 'lib/joy_ussd_engine.rb', line 17

def current_menu
  @current_menu
end

#expirationObject

Returns the value of attribute expiration.



17
18
19
# File 'lib/joy_ussd_engine.rb', line 17

def expiration
  @expiration
end

#last_menuObject

Returns the value of attribute last_menu.



17
18
19
# File 'lib/joy_ussd_engine.rb', line 17

def last_menu
  @last_menu
end

#paramsObject (readonly)

Returns the value of attribute params.



16
17
18
# File 'lib/joy_ussd_engine.rb', line 16

def params
  @params
end

#selected_providerObject (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 load_from_paginate_menu(name)
  menu_name =  name.constantize.new(self) 
  menu_name.send("run")
end

#load_menu(name) ⇒ Object



41
42
43
44
# File 'lib/joy_ussd_engine.rb', line 41

def load_menu(name)
    menu_name =  name.constantize.new(self) 
    menu_name.send("execute")
end

#processObject



51
52
53
# File 'lib/joy_ussd_engine.rb', line 51

def process
    load_menu(@current_menu)
end