Class: JoyUssdEngine::HubtelTransformer

Inherits:
DataTransformer show all
Defined in:
lib/joy_ussd_engine/hubtel_transformer.rb

Instance Attribute Summary

Attributes inherited from DataTransformer

#context

Instance Method Summary collapse

Methods inherited from DataTransformer

#expiration, #initialize

Constructor Details

This class inherits a constructor from JoyUssdEngine::DataTransformer

Instance Method Details

#app_initiator(params) ⇒ Object



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

def app_initiator(params)
    params[:Type] == 'Initiation'
end

#app_terminator(params) ⇒ Object



20
21
22
# File 'lib/joy_ussd_engine/hubtel_transformer.rb', line 20

def app_terminator(params)
    params[:Type] == 'Release' || (params[:Type] != "Initiation" && @context.get_state.blank?)
end

#release(message) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/joy_ussd_engine/hubtel_transformer.rb', line 32

def release(message)
    {
        Type: "Release",
        Message: message,
        ClientState: "EndJoyUssdEngine"
    }
end

#request_params(params) ⇒ Object

Tranforms request and response payload between hubtel and our application



5
6
7
8
9
10
11
12
13
14
# File 'lib/joy_ussd_engine/hubtel_transformer.rb', line 5

def request_params(params)
    {
        session_id: params[:Mobile],
        message: params[:Message],
        Mobile: params[:Mobile],
        ClientState: params[:ClientState],
        Type: params[:Type],
        data: params
    }
end

#response(message, client_state) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/joy_ussd_engine/hubtel_transformer.rb', line 24

def response(message, client_state)
    {
        Type: "Response",
        Message: message,
        ClientState: client_state
    }
end