Class: FlowChat::Ussd::Gateway::Nsano
- Inherits:
-
Object
- Object
- FlowChat::Ussd::Gateway::Nsano
- Defined in:
- lib/flow_chat/ussd/gateway/nsano.rb
Instance Method Summary collapse
- #call(context) ⇒ Object
-
#initialize(app) ⇒ Nsano
constructor
A new instance of Nsano.
Constructor Details
#initialize(app) ⇒ Nsano
Returns a new instance of Nsano.
7 8 9 |
# File 'lib/flow_chat/ussd/gateway/nsano.rb', line 7 def initialize(app) @app = app end |
Instance Method Details
#call(context) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/flow_chat/ussd/gateway/nsano.rb', line 11 def call(context) controller = context["controller"] request = controller.request # input = context["rack.input"].read # context["rack.input"].rewind # if input.present? # params = JSON.parse input # if params["network"].present? && params["UserSessionID"].present? # request_id = "nsano::request_id::#{params["UserSessionID"]}" # context["ussd.request"] = { # provider: :nsano, # network: params["network"].to_sym, # msisdn: Phonelib.parse(params["msisdn"]).e164, # type: Config.cache&.read(request_id).present? ? :response : :initial, # input: params["msg"].presence, # network: params["network"] # } # end # end # status, headers, response = @app.call(context) # if context["ussd.response"].present? && context["ussd.request"][:provider] == :nsano # if context["ussd.response"][:type] == :terminal # Config.cache&.write(request_id, nil) # else # Config.cache&.write(request_id, 1) # end # status = 200 # response = # { # USSDResp: { # action: (context["ussd.response"][:type] == :terminal) ? :prompt : :input, # menus: "", # title: context["ussd.response"][:body] # } # }.to_json # headers = headers.merge({"Content-Type" => "application/json", "Content-Length" => response.bytesize.to_s}) # response = [response] # end # [status, headers, response] end |