da_funk 0.28.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -112,11 +112,11 @@ class Device
112
112
 
113
113
  # Custom Attributes
114
114
  def self.tcp_recv_timeout
115
- Device::ParamsDat.file["tcp_recv_timeout"] || method_missing(:tcp_recv_timeout)
115
+ DaFunk::ParamsDat.file["tcp_recv_timeout"] || method_missing(:tcp_recv_timeout)
116
116
  end
117
117
 
118
118
  def self.attach_gprs_timeout
119
- value = (Device::ParamsDat.file["attach_gprs_timeout"] || method_missing(:attach_gprs_timeout))
119
+ value = (DaFunk::ParamsDat.file["attach_gprs_timeout"] || method_missing(:attach_gprs_timeout))
120
120
  value.to_s.empty? ? nil : value.to_s.to_i
121
121
  end
122
122
  end
data/out/da_funk.mrb CHANGED
Binary file
@@ -6,8 +6,8 @@ class MrbEvalTest < DaFunk::Test.case
6
6
  Device::Setting.company_name = "pc1"
7
7
  Device::Setting.logical_number = "1234"
8
8
 
9
- Device::Notification.start
10
- Device::Notification.check
9
+ DaFunk::Notification.start
10
+ DaFunk::Notification.check
11
11
 
12
12
  http = SimpleHttp.new('http', 'http://google.com', 443)
13
13
  http.socket = Device::Network.socket.call
@@ -33,4 +33,4 @@ EOF
33
33
 
34
34
  assert_equal 302, mrb_eval(command)
35
35
  end
36
- end
36
+ end
@@ -2,15 +2,15 @@
2
2
  class NotificationTest < DaFunk::Test.case
3
3
  def test_notification
4
4
  Device::Setting.company_name = "pc1"
5
- Device::Notification.setup
6
- notification = Device::Notification.new
5
+ DaFunk::Notification.setup
6
+ notification = DaFunk::Notification.new
7
7
 
8
8
  assert_equal nil, notification.check
9
9
  notification.check
10
10
  notification.check
11
11
  assert notification.close
12
12
  assert notification.closed?
13
- notification = Device::Notification.new
13
+ notification = DaFunk::Notification.new
14
14
  assert_equal nil, notification.check
15
15
  notification.check
16
16
  notification.check
@@ -21,12 +21,12 @@ class NotificationTest < DaFunk::Test.case
21
21
  def test_notification_SHOW_MESSAGE
22
22
  $status = nil
23
23
  Device::Setting.company_name = "pc1"
24
- Device::Notification.setup
25
- Device::NotificationCallback.new "SHOW_MESSAGE", :on => Proc.new { |message,datetime|
24
+ DaFunk::Notification.setup
25
+ DaFunk::NotificationCallback.new "SHOW_MESSAGE", :on => Proc.new { |message,datetime|
26
26
  $status = message
27
27
  }
28
28
 
29
- notification = Device::Notification.new
29
+ notification = DaFunk::Notification.new
30
30
 
31
31
  p "Must create message AAAA"
32
32
  p "Remember to Press Enter after message appears"
@@ -5,7 +5,7 @@ class ParamsDatTest < DaFunk::Test.case
5
5
  Device::Setting.host = Device::Setting::HOST_STAGING
6
6
  Device::Setting.company_name = "pc1"
7
7
  Device::Setting.logical_number = "1410"
8
- Device::ParamsDat.update_apps
9
- Device::ParamsDat.application_menu
8
+ DaFunk::ParamsDat.update_apps
9
+ DaFunk::ParamsDat.application_menu
10
10
  end
11
11
  end
@@ -11,17 +11,17 @@ class ApplicationTest < DaFunk::Test.case
11
11
  end
12
12
 
13
13
  def test_check_crc_true
14
- application = Device::Application.new("TTT", @file_path, "ruby", nil)
14
+ application = DaFunk::Application.new("TTT", @file_path, "ruby", nil)
15
15
  assert_equal true, application.outdated?
16
16
  end
17
17
 
18
18
  def test_check_crc_false
19
- application = Device::Application.new("TTT", @file_path, "ruby", @crc)
19
+ application = DaFunk::Application.new("TTT", @file_path, "ruby", @crc)
20
20
  assert_equal false, application.outdated?
21
21
  end
22
22
 
23
23
  def test_check_crc_non_file
24
- application = Device::Application.new("TTT", "./non_exists", "ruby", "1111")
24
+ application = DaFunk::Application.new("TTT", "./non_exists", "ruby", "1111")
25
25
  assert_equal true, application.outdated?
26
26
  end
27
27
 
@@ -8,7 +8,7 @@ class NotificationEventTest < DaFunk::Test.case
8
8
  "Name" => "pc1;0101",
9
9
  "Event" => "user"
10
10
  }
11
- @event = Device::NotificationEvent.new(@stream_event)
11
+ @event = DaFunk::NotificationEvent.new(@stream_event)
12
12
  end
13
13
 
14
14
  def test_attr_coalesce
@@ -59,14 +59,14 @@ class NotificationEventTest < DaFunk::Test.case
59
59
  def test_attr_one_parameter
60
60
  stream_event = @stream_event.dup
61
61
  stream_event["Payload"].gsub!("a", "|")
62
- event = Device::NotificationEvent.new(stream_event)
62
+ event = DaFunk::NotificationEvent.new(stream_event)
63
63
  assert_equal ["ge 62"], event.parameters
64
64
  end
65
65
 
66
66
  def test_attr_multiple_parameters
67
67
  stream_event = @stream_event.dup
68
68
  stream_event["Payload"].gsub!("e", "|")
69
- event = Device::NotificationEvent.new(stream_event)
69
+ event = DaFunk::NotificationEvent.new(stream_event)
70
70
  assert_equal ["ssag", " 62"], event.parameters
71
71
  end
72
72
  end
@@ -1,7 +1,7 @@
1
1
 
2
2
  class NotificationTest < DaFunk::Test.case
3
3
  def setup
4
- @notification = Device::Notification.new(15, 10)
4
+ @notification = DaFunk::Notification.new(15, 10)
5
5
  end
6
6
 
7
7
  def test_interval_last_check_blank
@@ -1,11 +1,11 @@
1
1
 
2
2
  class ParamsDatTest < DaFunk::Test.case
3
3
  def test_params_dat_not_nil_file
4
- assert_equal false, Device::ParamsDat.file.nil?
4
+ assert_equal false, DaFunk::ParamsDat.file.nil?
5
5
  end
6
6
 
7
7
  def test_params_dat_initialize_calling_file
8
- assert Device::ParamsDat.file.hash.is_a? Hash
8
+ assert DaFunk::ParamsDat.file.hash.is_a? Hash
9
9
  end
10
10
  end
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: da_funk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.28.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thiago Scalone
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-07 00:00:00.000000000 Z
11
+ date: 2018-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -152,6 +152,7 @@ files:
152
152
  - guides/sample_transaction_iso8583.rb
153
153
  - imgs/daft-punk-da-funk.jpg
154
154
  - lib/da_funk.rb
155
+ - lib/da_funk/application.rb
155
156
  - lib/da_funk/callback_flow.rb
156
157
  - lib/da_funk/engine.rb
157
158
  - lib/da_funk/event_handler.rb
@@ -162,33 +163,30 @@ files:
162
163
  - lib/da_funk/i18n.rb
163
164
  - lib/da_funk/i18n_error.rb
164
165
  - lib/da_funk/iso8583.rb
166
+ - lib/da_funk/notification.rb
167
+ - lib/da_funk/notification_callback.rb
168
+ - lib/da_funk/notification_event.rb
169
+ - lib/da_funk/params_dat.rb
165
170
  - lib/da_funk/rake_task.rb
166
171
  - lib/da_funk/screen.rb
167
172
  - lib/da_funk/screen_flow.rb
168
173
  - lib/da_funk/struct.rb
169
174
  - lib/da_funk/test.rb
175
+ - lib/da_funk/transaction/download.rb
176
+ - lib/da_funk/transaction/iso.rb
170
177
  - lib/da_funk/version.rb
171
178
  - lib/device.rb
172
- - lib/device/application.rb
173
179
  - lib/device/audio.rb
174
180
  - lib/device/crypto.rb
175
181
  - lib/device/display.rb
176
- - lib/device/helper.rb
177
182
  - lib/device/io.rb
178
183
  - lib/device/magnetic.rb
179
184
  - lib/device/network.rb
180
- - lib/device/notification.rb
181
- - lib/device/notification_callback.rb
182
- - lib/device/notification_event.rb
183
- - lib/device/params_dat.rb
184
185
  - lib/device/printer.rb
185
186
  - lib/device/runtime.rb
186
187
  - lib/device/setting.rb
187
188
  - lib/device/support.rb
188
189
  - lib/device/system.rb
189
- - lib/device/transaction/download.rb
190
- - lib/device/transaction/emv.rb
191
- - lib/device/transaction/iso.rb
192
190
  - lib/device/version.rb
193
191
  - lib/ext/array.rb
194
192
  - lib/ext/float.rb
@@ -206,11 +204,6 @@ files:
206
204
  - lib/iso8583/message.rb
207
205
  - lib/iso8583/util.rb
208
206
  - lib/iso8583/version.rb
209
- - lib/serfx.rb
210
- - lib/serfx/commands.rb
211
- - lib/serfx/connection.rb
212
- - lib/serfx/exceptions.rb
213
- - lib/serfx/response.rb
214
207
  - lib/zip.rb
215
208
  - out/da_funk.mrb
216
209
  - test/integration/getc_test.rb
data/lib/device/helper.rb DELETED
@@ -1,5 +0,0 @@
1
- class Device
2
- # Backward compatibility
3
- Helper = DaFunk::Helper
4
- end
5
-
@@ -1,173 +0,0 @@
1
-
2
- class Device
3
- class Notification
4
- DEFAULT_TIMEOUT = 20
5
- DEFAULT_INTERVAL = 10
6
- DEFAULT_STREAM_TIMEOUT = 0
7
- DEFAULT_CREATION_INTERVAL = 180
8
-
9
- class << self
10
- attr_accessor :callbacks, :current, :last_creation, :creation_interval, :last_event
11
- end
12
-
13
- self.callbacks = Hash.new
14
- self.creation_interval = DEFAULT_CREATION_INTERVAL
15
-
16
- attr_reader :fiber, :timeout, :interval, :last_check, :stream_timeout
17
-
18
- def self.check
19
- self.current.check if self.current
20
- end
21
-
22
- def self.execute(event)
23
- calls = self.callbacks[event.callback]
24
- return unless calls
25
- [:before, :on, :after].each do |moment|
26
- calls.each{|callback| callback.call(event, moment)}
27
- end
28
- end
29
-
30
- def self.schedule(callback)
31
- self.callbacks[callback.description] ||= []
32
- self.callbacks[callback.description] << callback
33
- end
34
-
35
- def self.config
36
- self.creation_interval = Device::Setting.notification_socket_timeout.empty? ? DEFAULT_CREATION_INTERVAL : Device::Setting.notification_socket_timeout.to_i
37
- notification_timeout = Device::Setting.notification_timeout.empty? ? DEFAULT_TIMEOUT : Device::Setting.notification_timeout.to_i
38
- notification_interval = Device::Setting.notification_interval.empty? ? DEFAULT_INTERVAL : Device::Setting.notification_interval.to_i
39
- notification_stream_timeout = Device::Setting.notification_stream_timeout.empty? ? DEFAULT_STREAM_TIMEOUT : Device::Setting.notification_stream_timeout.to_i
40
- [notification_timeout, notification_interval, notification_stream_timeout]
41
- end
42
-
43
- def self.start
44
- if create_fiber? && Device::Network.connected?
45
- unless Device::Notification.current && Device::Notification.current.closed?
46
- self.new(*self.config)
47
- end
48
- end
49
- end
50
-
51
- def self.create_fiber?(force = false)
52
- (! Device::Setting.company_name.empty?) &&
53
- (! Device::Setting.logical_number.empty?) &&
54
- (force || self.valid_creation_interval?) &&
55
- Device::ParamsDat.file["notification_enabled"] == "1"
56
- end
57
-
58
- def self.valid_creation_interval?
59
- if @last_creation
60
- (@last_creation + self.creation_interval) < Time.now
61
- else
62
- true
63
- end
64
- end
65
-
66
- def initialize(timeout = DEFAULT_TIMEOUT, interval = DEFAULT_INTERVAL, stream_timeout = DEFAULT_STREAM_TIMEOUT)
67
- @timeout = timeout
68
- @stream_timeout = stream_timeout
69
- @interval = interval
70
- Device::Notification.current = self
71
- @fiber = create_fiber
72
- end
73
-
74
- # Check if there is any notification
75
- def check
76
- # TODO check if should execute this(because of connection exception)
77
- if valid_check_interval? && Device::Network.connected?
78
- if @fiber.alive?
79
- if (notification = @fiber.resume)
80
- Notification.execute(NotificationEvent.new(notification))
81
- end
82
- else
83
- if Device::Notification.create_fiber?(true)
84
- self.close
85
- @fiber = create_fiber
86
- end
87
- end
88
- @last_check = Time.now
89
- end
90
- end
91
-
92
- # Close socket and finish Fiber execution
93
- def close
94
- if closed?
95
- true
96
- else
97
- ! @fiber.resume "close"
98
- end
99
- end
100
-
101
- def closed?
102
- ! @fiber.alive?
103
- end
104
-
105
- def valid_check_interval?
106
- if @last_check
107
- (@last_check + self.interval) < Time.now
108
- else
109
- true
110
- end
111
- end
112
-
113
- def valid_event_interval?
114
- if @last_event
115
- (@last_event + Notification.creation_interval) < Time.now
116
- else
117
- true
118
- end
119
- end
120
-
121
- private
122
- def reply(conn, ev)
123
- if ev.is_a?(Hash)
124
- if ev["Event"] == "user" && ev["Payload"] && ev["Payload"].include?("Id")
125
- index = ev["Payload"].index("\"Id")
126
- id = ev["Payload"][(index+7)..(index+38)]
127
- @last_event = Time.now
128
- conn.event(event_name, "{\"Id\"=>\"#{id}\"}", false)
129
- end
130
- elsif ev.nil?
131
- if self.valid_event_interval?
132
- @last_event = Time.now
133
- conn.event(event_name, "", false)
134
- end
135
- end
136
- end
137
-
138
- def check_errors(exception)
139
- case exception.message
140
- when "Invalid authentication token"
141
- Device::Setting.cw_pos_timezone = "" # Clear timezone if authentication error
142
- when "Socket closed"
143
- else
144
- end
145
- false
146
- end
147
-
148
- def create_fiber
149
- Fiber.new do
150
- begin
151
- Serfx.connect(socket_block: Device::Network.socket, timeout: timeout, stream_timeout: stream_timeout) do |conn|
152
- @last_event = Time.now
153
- conn.auth(CloudwalkTOTP.at)
154
- Device::Notification.last_creation = Time.now
155
- conn.stream(subscription) { |ev| reply(conn, ev) }
156
- end
157
- true
158
- rescue => exception
159
- check_errors(exception)
160
- end
161
- end
162
- end
163
-
164
- def subscription
165
- "user:#{event_name}"
166
- end
167
-
168
- def event_name
169
- "#{Device::Setting.company_name};#{Device::Setting.logical_number}"
170
- end
171
- end
172
- end
173
-
@@ -1,39 +0,0 @@
1
- class Device
2
- class NotificationEvent
3
- attr_reader :values, :coalesce, :ltime, :payload, :name, :event, :message, :value, :body, :callback, :parameters
4
-
5
- def initialize(values)
6
- @values = values
7
- parse(values)
8
- end
9
-
10
- def type
11
- @event
12
- end
13
-
14
- private
15
- def parse(values)
16
- @coalesce = values["Coalesce"]
17
- @ltime = values["LTime"]
18
- @payload = values["Payload"]
19
- @name = values["Name"]
20
- @event = values["Event"]
21
-
22
- @message = payload.to_s.gsub("=>", " : ")
23
- @value = JSON.parse(@message) unless @message.empty?
24
- @body = extract_body(value)
25
-
26
- @callback, *@parameters = @body.to_s.split("|")
27
- end
28
-
29
- def extract_body(value)
30
- unless value.nil?
31
- return value["Body"] if value["Body"]
32
- # TODO: For some reason the JSON parse has a problem
33
- # and extract "B" from "Body"
34
- return value["ody"] if value["ody"]
35
- end
36
- end
37
- end
38
- end
39
-
@@ -1,45 +0,0 @@
1
-
2
- class Device
3
- class Transaction
4
- class EMV
5
- class << self
6
- attr_accessor :status, :mk_slot, :pinpad_type, :pinpad_wk, :show_amout
7
- end
8
-
9
- attr_accessor :data, :info
10
-
11
- def self.open(mk_slot, pinpad_type, pinpad_wk, show_amout)
12
- end
13
-
14
- def self.close
15
- end
16
-
17
- def self.load_tables(acquirer)
18
- end
19
-
20
- def clean
21
- @data = {:init => {}, :process => {}, :finish => {}}
22
- @info = {:init => {}, :process => {}, :finish => {}}
23
- end
24
-
25
- def init
26
- end
27
-
28
- def response
29
- end
30
-
31
- def parameters
32
- end
33
-
34
- def timeout=(seconds)
35
- end
36
-
37
- def timeout
38
- end
39
-
40
- def remove_card
41
- end
42
- end
43
- end
44
- end
45
-
@@ -1,193 +0,0 @@
1
- module Serfx
2
- # Implements all of Serf's rpc commands using
3
- # Serfx::Connection#request method
4
- module Commands
5
- # performs initial hanshake of an RPC session. Handshake has to be the
6
- # first command to be invoked during an RPC session.
7
- #
8
- # @return [Response]
9
- def handshake
10
- tcp_send(:handshake, 'Version' => 1, 'SerialNumber' => Device::System.serial)
11
- read_response(:handshake)
12
- end
13
-
14
- # authenticate against the serf agent. if RPC credentials are setup, then
15
- # `auth` has to be second command, immediately after `handshake`.
16
- #
17
- # @return [Response]
18
- def auth(key = @authkey)
19
- tcp_send(:auth, 'AuthKey' => key)
20
- read_response(:auth)
21
- end
22
- # fires an user event
23
- #
24
- # @param name [String] a string representing name of the event
25
- # @param payload [String] payload, default is nil
26
- # @param coalesce [Boolena] whether serf should coalesce events within
27
- # same name during similar time frame
28
- # @return [Response]
29
- def event(name, payload = nil, coalesce = true)
30
- event = {
31
- 'Name' => name,
32
- 'Coalesce' => coalesce
33
- }
34
- event['Payload'] = payload unless payload.nil?
35
- request(:event, event)
36
- end
37
-
38
- # force a failed node to leave the cluster
39
- #
40
- # @param node [String] name of the failed node
41
- # @return [Response]
42
- def force_leave(node)
43
- request(:force_leave, 'Node' => node)
44
- end
45
-
46
- # join an existing cluster.
47
- #
48
- # @param existing [Array] an array of existing serf agents
49
- # @param replay [Boolean] Whether events should be replayed upon joining
50
- # @return [Response]
51
- def join(existing, replay = false)
52
- request(:join, 'Existing' => existing, 'Replay' => replay)
53
- end
54
-
55
- # obtain the list of existing members
56
- #
57
- # @return [Response]
58
- def members
59
- request(:members)
60
- end
61
-
62
- # obatin the list of cluster members, filtered by tags.
63
- #
64
- # @param tags [Array] an array of tags for filter
65
- # @param status [Boolean] filter members based on their satatus
66
- # @param name [String] filter based on exact name or pattern.
67
- #
68
- # @return [Response]
69
- def members_filtered(tags, status = 'alive', name = nil)
70
- filter = {
71
- 'Tags' => tags,
72
- 'Status' => status
73
- }
74
- filter['Name'] = name unless name.nil?
75
- request(:members_filtered, filter)
76
- end
77
-
78
- # alter the tags on a Serf agent while it is running. A member-update
79
- # event will be triggered immediately to notify the other agents in the
80
- # cluster of the change. The tags command can add new tags, modify
81
- # existing tags, or delete tags
82
- #
83
- # @param tags [Hash] a hash representing tags as key-value pairs
84
- # @param delete_tags [Array] an array of tags to be deleted
85
- # @return [Response]
86
- def tags(tags, delete_tags = [])
87
- request(:tags, 'Tags' => tags, 'DeleteTags' => delete_tags)
88
- end
89
-
90
- # subscribe to a stream of all events matching a given type filter.
91
- # Events will continue to be sent until the stream is stopped
92
- #
93
- # @param types [String] comma separated list of events
94
- # @return [Thread, Response]
95
- def stream(types, &block)
96
- res = request(:stream, {'Type' => types})
97
- loop do
98
- header, ev = read_data(self.stream_timeout)
99
- check_rpc_error!(header)
100
- block.call(ev) if block_given?
101
- break unless fiber_yield!(ev)
102
- end
103
- res
104
- end
105
-
106
- # monitor is similar to the stream command, but instead of events it
107
- # subscribes the channel to log messages from the agent
108
- #
109
- # @param loglevel [String]
110
- # @return [Response]
111
- def monitor(loglevel = 'debug')
112
- request(:monitor, 'LogLevel' => loglevel.upcase)
113
- end
114
-
115
- # stop is used to stop either a stream or monitor
116
- def stop(sequence_number)
117
- tcp_send(:stop, 'Stop' => sequence_number)
118
- end
119
-
120
- # leave is used trigger a graceful leave and shutdown of the current agent
121
- #
122
- # @return [Response]
123
- def leave
124
- request(:leave)
125
- end
126
-
127
- # query is used to issue a new query
128
- #
129
- # @param name [String] name of the query
130
- # @param payload [String] payload for this query event
131
- # @param opts [Hash] additional query options
132
- # @return [Response]
133
- def query(name, payload, opts = {}, &block)
134
- params = { 'Name' => name, 'Payload' => payload }
135
- params.merge!(opts)
136
- res = request(:query, params)
137
- loop do
138
- header, ev = read_data
139
- check_rpc_error!(header)
140
- block.call(ev) if block_given?
141
- break unless fiber_yield!(ev)
142
- end
143
- res
144
- end
145
-
146
- # respond is used with `stream` to subscribe to queries and then respond.
147
- #
148
- # @param id [Integer] an opaque value that is assigned by the IPC layer
149
- # @param payload [String] payload for the response event
150
- # @return [Response]
151
- def respond(id, payload)
152
- request(:respond, 'ID' => id, 'Payload' => payload)
153
- end
154
-
155
- # install a new encryption key onto the cluster's keyring
156
- #
157
- # @param key [String] 16 bytes of base64-encoded data.
158
- # @return [Response]
159
- def install_key(key)
160
- request(:install_key, 'Key' => key)
161
- end
162
-
163
- # change the primary key, which is used to encrypt messages
164
- #
165
- # @param key [String] 16 bytes of base64-encoded data.
166
- # @return [Response]
167
- def use_key(key)
168
- request(:use_key, 'Key' => key)
169
- end
170
-
171
- # remove a key from the cluster's keyring
172
- #
173
- # @param key [String] 16 bytes of base64-encoded data.
174
- # @return [Response]
175
- def remove_key(key)
176
- request(:remove_key, 'Key' => key)
177
- end
178
-
179
- # return a list of all encryption keys currently in use on the cluster
180
- #
181
- # @return [Response]
182
- def list_keys
183
- request(:list_keys)
184
- end
185
-
186
- # obtain stats about the agent(same as info command)
187
- #
188
- # @return [Response]
189
- def stats
190
- request(:stats)
191
- end
192
- end
193
- end