ussd_engine 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57122947aff50821a4a6ec61d38501ce9f525e516be998874590d6104bb1a754
4
- data.tar.gz: 581faff4ae10681400a32c21cc72fc5b94525a8e0f7e7a4f1867b7916838238e
3
+ metadata.gz: d0fb2383f970ce505d57f02fcc5ccb2a186f2f91897f5352eaba61495342c6e7
4
+ data.tar.gz: 0ff16e29fc1f74924a656f9e1ded9a6b46b48f867bea55b3d9bca48d33b8e620
5
5
  SHA512:
6
- metadata.gz: a8f7753521a5405026b20c78072c5009bdb952d79599ec735bd0fcd79d9ed6de96f61975a7c89310da9956ef43ea89055416e881e0214094d10b68e7037e75d2
7
- data.tar.gz: 1b67596120f200d6a1f9f830f83052d4d444df48fb77a0719cf2b5fdfd6dae3dcae2e12c92f7043916831ec6013c0bbb91da1965d3d554760bb78044ada96012
6
+ metadata.gz: '0482d00e9a9add76c19817453b70b6d4df14d7f117e21d278ffa3919116d27ee67c5b288663aba2dd3b226e5ddc7cbac349522e8735505cc753b168cd30767e7'
7
+ data.tar.gz: 40cf67d5f8177a9137d61f7dab22857e61d6b6341df0bd813cbb756eb19b948313c610c65a998c2dcfff2301036a31dfd2c886ed3b246ee5f977c249825962bd
@@ -0,0 +1,48 @@
1
+ module UssdEngine
2
+ module Controller
3
+ module Forkable
4
+ protected
5
+
6
+ def self.included(base)
7
+ base.stores :forkable_stack
8
+ end
9
+
10
+ def create_fork(source_screen, forked_screen, destination_screen, input = nil)
11
+ Config.logger&.debug "UssdEngine::Controller::Forkable :: Creating fork: #{source_screen} -> #{forked_screen} -> #{destination_screen}"
12
+
13
+ self.forkable_stack ||= []
14
+ self.forkable_stack.append({
15
+ source: source_screen,
16
+ fork: forked_screen,
17
+ destination: destination_screen,
18
+ })
19
+
20
+ display forked_screen, input
21
+ end
22
+
23
+ def refork(forked_screen, destination_screen, input = nil)
24
+ raise "You cannot refork outside of a fork" unless forkable_stack.size.positive?
25
+ Config.logger&.debug "UssdEngine::Controller::Forkable :: Creating refork: #{forked_screen} -> #{destination_screen}"
26
+
27
+ create_fork :forkable_refork, forked_screen, destination_screen, input
28
+ end
29
+
30
+ def abort_fork(input = nil)
31
+ branch = self.forkable_stack.pop
32
+ while branch[:source].to_sym == :forkable_refork
33
+ branch = self.forkable_stack.pop
34
+ end
35
+ Config.logger&.debug "UssdEngine::Controller::Forkable :: Aborting fork: #{branch[:fork]} -> #{branch[:source]} #{self.forkable_stack}"
36
+ Config.logger&.debug "#{forkable_stack}"
37
+ display branch[:source], input
38
+ end
39
+
40
+ def join_fork(input = nil)
41
+ branch = self.forkable_stack.pop
42
+ Config.logger&.debug "UssdEngine::Controller::Forkable :: Joining fork: #{branch[:fork]} -> #{branch[:destination]}"
43
+ Config.logger&.debug "#{forkable_stack}"
44
+ display branch[:destination], input
45
+ end
46
+ end
47
+ end
48
+ end
@@ -2,6 +2,7 @@ require "ussd_engine/controller/io"
2
2
  require "ussd_engine/controller/options"
3
3
  require "ussd_engine/controller/params"
4
4
  require "ussd_engine/controller/storable"
5
+ require "ussd_engine/controller/forkable"
5
6
 
6
7
  module UssdEngine
7
8
  module Controller
@@ -12,6 +13,7 @@ module UssdEngine
12
13
 
13
14
  def self.included(base)
14
15
  base.send :include, UssdEngine::Controller::Storable
16
+ base.send :include, UssdEngine::Controller::Forkable
15
17
  base.send :skip_before_action, :verify_authenticity_token, only: :ussd_controller, raise: false
16
18
  end
17
19
 
@@ -17,10 +17,18 @@ module UssdEngine
17
17
  end
18
18
 
19
19
  def resolve_option(input, options)
20
- return unless input.match? /^[1-9](\d)?$/
20
+ return unless input.to_s.match? /^[1-9](\d)?$/
21
21
 
22
22
  options.keys[input.to_i - 1]
23
23
  end
24
+
25
+ def back_option
26
+ { back: "Back" }
27
+ end
28
+
29
+ def cancel_option
30
+ { cancel: "Cancel" }
31
+ end
24
32
  end
25
33
  end
26
34
  end
@@ -7,24 +7,40 @@ module UssdEngine
7
7
  protected
8
8
 
9
9
  def ussd_request_id
10
+ return unless request.env["ussd_engine.request"].present?
11
+
10
12
  request.env["ussd_engine.request"][:id]
11
13
  end
12
14
 
13
15
  def ussd_request_type
16
+ return unless request.env["ussd_engine.request"].present?
17
+
14
18
  request.env["ussd_engine.request"][:type]
15
19
  end
16
20
 
17
21
  def ussd_request_msisdn
22
+ return unless request.env["ussd_engine.request"].present?
23
+
18
24
  request.env["ussd_engine.request"][:msisdn]
19
25
  end
20
26
 
21
27
  def ussd_request_provider
28
+ return unless request.env["ussd_engine.request"].present?
29
+
22
30
  request.env["ussd_engine.request"][:provider]
23
31
  end
24
32
 
25
33
  def ussd_user_input
34
+ return unless request.env["ussd_engine.request"].present?
35
+
26
36
  request.env["ussd_engine.request"][:input]
27
37
  end
38
+
39
+ def ussd_request_network
40
+ return unless request.env["ussd_engine.request"].present?
41
+
42
+ request.env["ussd_engine.request"][:network]
43
+ end
28
44
  end
29
45
  end
30
46
  end
@@ -19,6 +19,7 @@ module UssdEngine
19
19
  msisdn: Phonelib.parse(params["MSISDN"]).e164,
20
20
  type: params["MSGTYPE"] ? :initial : :response,
21
21
  input: params["USERDATA"].presence,
22
+ network: nil,
22
23
  }
23
24
  end
24
25
  end
@@ -20,6 +20,7 @@ module UssdEngine
20
20
  msisdn: Phonelib.parse(params["msisdn"]).e164,
21
21
  type: Config.cache&.read(request_id).present? ? :response : :initial,
22
22
  input: params["msg"].presence,
23
+ network: params["network"],
23
24
  }
24
25
  end
25
26
  end
@@ -1,3 +1,3 @@
1
1
  module UssdEngine
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -162,6 +162,7 @@
162
162
 
163
163
  function reset(shouldRender) {
164
164
  state.isRunning = false
165
+ state.request_id = btoa(Math.random().toString()).substr(10, 10)
165
166
  state.provider = $provider.value
166
167
  state.endpoint = $endpoint.value
167
168
  state.msisdn = $msisdn.value
@@ -181,7 +182,7 @@
181
182
  switch (state.provider) {
182
183
  case "nalo":
183
184
  data = {
184
- USERID: '12345678',
185
+ USERID: state.request_id,
185
186
  MSISDN: state.msisdn,
186
187
  USERDATA: $data.value,
187
188
  MSGTYPE: !state.isRunning,
@@ -192,7 +193,7 @@
192
193
  network: 'MTN',
193
194
  msisdn: state.msisdn,
194
195
  msg: $data.value,
195
- UserSessionID: "12345",
196
+ UserSessionID: state.request_id,
196
197
  }
197
198
  break;
198
199
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ussd_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Froelich
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-27 00:00:00.000000000 Z
11
+ date: 2022-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -84,6 +84,7 @@ files:
84
84
  - bin/setup
85
85
  - lib/ussd_engine.rb
86
86
  - lib/ussd_engine/config.rb
87
+ - lib/ussd_engine/controller/forkable.rb
87
88
  - lib/ussd_engine/controller/io.rb
88
89
  - lib/ussd_engine/controller/mixin.rb
89
90
  - lib/ussd_engine/controller/options.rb