sapos-print 1.0.9 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -4
- data/lib/sapos/print/cli.rb +23 -9
- data/lib/sapos/print/configuration.rb +9 -2
- data/lib/sapos/print/printer.rb +14 -3
- data/lib/sapos/print/q_reader.rb +15 -3
- data/lib/sapos/print/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc0f0e2c23bfce7306d2f9ad61b8c22133ea9a899bfbe7715ad412742e3dc0d1
|
4
|
+
data.tar.gz: 50c06d2cc61e089350ac62b05317d1ad894cf25debe67aba26baa6ddf0b14e35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfe1ac23eb6b6696a3f97ee41d5574014e7979fc73735b3befec56c39c5e189d5175111da32e488cda1d9e7525d45a6950cbde53865fcfdfdfd7912714711ab5
|
7
|
+
data.tar.gz: 0fd6bd0aa7a28908221f6ed4a8f08666138542be8d6ae5d728840ede8a06da3f8c9d1e1a9a06a0696862a083a70b8503721ee0caf30c19940deff0e2f9eace03
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sapos-print (1.0.
|
4
|
+
sapos-print (1.0.10)
|
5
5
|
activesupport
|
6
6
|
awesome_print
|
7
7
|
json
|
@@ -12,7 +12,7 @@ PATH
|
|
12
12
|
GEM
|
13
13
|
remote: https://rubygems.org/
|
14
14
|
specs:
|
15
|
-
activesupport (7.0.
|
15
|
+
activesupport (7.0.3)
|
16
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
17
|
i18n (>= 1.6, < 2)
|
18
18
|
minitest (>= 5.1)
|
@@ -34,7 +34,7 @@ GEM
|
|
34
34
|
concurrent-ruby (~> 1.0)
|
35
35
|
zeitwerk (~> 2.6)
|
36
36
|
dry-inflector (0.2.1)
|
37
|
-
dry-initializer (3.
|
37
|
+
dry-initializer (3.1.1)
|
38
38
|
dry-logic (1.2.0)
|
39
39
|
concurrent-ruby (~> 1.0)
|
40
40
|
dry-core (~> 0.5, >= 0.5)
|
@@ -63,7 +63,7 @@ GEM
|
|
63
63
|
httpclient (2.8.3)
|
64
64
|
i18n (1.12.0)
|
65
65
|
concurrent-ruby (~> 1.0)
|
66
|
-
json (2.6.
|
66
|
+
json (2.6.3)
|
67
67
|
mime-types (3.4.1)
|
68
68
|
mime-types-data (~> 3.2015)
|
69
69
|
mime-types-data (3.2022.0105)
|
data/lib/sapos/print/cli.rb
CHANGED
@@ -3,17 +3,17 @@ module Sapos
|
|
3
3
|
module Print
|
4
4
|
include Thor::Actions
|
5
5
|
class CLI < Thor
|
6
|
-
|
6
|
+
|
7
7
|
desc "setup", "Setup Wizard"
|
8
8
|
def setup
|
9
9
|
info
|
10
10
|
config = {}
|
11
11
|
|
12
|
-
url = ask("
|
12
|
+
url = ask("URL de Configuración: ")
|
13
13
|
if url.eql?('manual')
|
14
14
|
data = {}
|
15
|
-
data["channel"] = ask("
|
16
|
-
data["key"] = ask("
|
15
|
+
data["channel"] = ask("Canal:")
|
16
|
+
data["key"] = ask("Llave de la Cola:")
|
17
17
|
else
|
18
18
|
response = RestClient.get(url)
|
19
19
|
data = JSON.parse(response)
|
@@ -31,15 +31,21 @@ module Sapos
|
|
31
31
|
|
32
32
|
config[:q] = data["channel"]
|
33
33
|
config[:key] = data["key"]
|
34
|
-
config[:printer] = ask("
|
35
|
-
config[:adapter] = ask("
|
34
|
+
config[:printer] = ask("Nombre de la impresora default: ")
|
35
|
+
config[:adapter] = ask("Adaptador: ", limited_to: ["console", "cups", "windows"])
|
36
36
|
config[:interface] = ask("Interface", limited_to: ["text", "escp"])
|
37
37
|
config[:user_id] = user_id
|
38
|
+
config[:duplicate_control] = ask("¿Control Duplicados por MSGID?", limited_to: ["si", "no"])
|
39
|
+
config[:printers] = [config[:printer]]
|
38
40
|
|
39
|
-
|
41
|
+
while yes?("¿Tiene impresoras adicionales?")
|
42
|
+
name = ask("Nombre de la impresora adicional: ")
|
43
|
+
config[:printers] << name
|
44
|
+
end
|
45
|
+
if yes?("¿Esta seguro que desea guardar la configuración?")
|
40
46
|
Sapos::Print::Configuration.write(config)
|
41
47
|
ap config
|
42
|
-
say "
|
48
|
+
say "La configuración ha sido guardada!"
|
43
49
|
end
|
44
50
|
end
|
45
51
|
|
@@ -48,7 +54,7 @@ module Sapos
|
|
48
54
|
def start
|
49
55
|
info
|
50
56
|
config = Sapos::Print.config
|
51
|
-
puts ["Q=#{config.q.to_s}", "Printer=#{config.printer.to_s}", "Adapter=#{config.adapter.to_s}", "Interface=#{config.interface}"].join(";")
|
57
|
+
puts ["Q=#{config.q.to_s}", "Printer=#{config.printer.to_s}", "Adapter=#{config.adapter.to_s}", "Interface=#{config.interface}", "DC=#{config.duplicate_control?}"].join(";")
|
52
58
|
|
53
59
|
print_dir = File.join(Sapos::Print.app_directory, 'print')
|
54
60
|
if File.exists?(print_dir)
|
@@ -63,9 +69,17 @@ module Sapos
|
|
63
69
|
end
|
64
70
|
|
65
71
|
desc "print", "demo print"
|
72
|
+
option :printer_name, type: :string
|
66
73
|
def print
|
67
74
|
info
|
68
75
|
config = Sapos::Print.config
|
76
|
+
printer_name = options[:printer_name]
|
77
|
+
if printer_name.present?
|
78
|
+
if config.printers.any? && config.printers.include?(printer_name)
|
79
|
+
config.printer = printer_name
|
80
|
+
end
|
81
|
+
end
|
82
|
+
puts "Printing to: #{config.printer}"
|
69
83
|
printer = Printer.new(config)
|
70
84
|
printer.print(document: "This is a test\nprint page\nwithno special commands", document_number: "test", print_control: true)
|
71
85
|
end
|
@@ -6,7 +6,7 @@ module Sapos
|
|
6
6
|
module Print
|
7
7
|
class Configuration
|
8
8
|
|
9
|
-
attr_accessor :printer, :adapter, :interface, :q, :key, :emv_path, :emv_terminal, :user_id, :verbose
|
9
|
+
attr_accessor :printer, :adapter, :interface, :q, :key, :emv_path, :emv_terminal, :user_id, :verbose, :duplicate_control, :cache, :printers
|
10
10
|
|
11
11
|
def self.write(args = {})
|
12
12
|
config_file = "#{Sapos::Print.app_directory}/config.yml"
|
@@ -19,6 +19,7 @@ module Sapos
|
|
19
19
|
template = ERB.new(File.read(config_file))
|
20
20
|
result = YAML.load(template.result(binding))
|
21
21
|
@printer = result[:printer]
|
22
|
+
@printers = result[:printers] || []
|
22
23
|
@adapter = result[:adapter]
|
23
24
|
@interface = result[:interface]
|
24
25
|
@q = result[:q]
|
@@ -26,6 +27,8 @@ module Sapos
|
|
26
27
|
@emv_path = result[:emv_path]
|
27
28
|
@emv_terminal = result[:emv_terminal]
|
28
29
|
@user_id = result[:user_id]
|
30
|
+
@duplicate_control = result[:duplicate_control]
|
31
|
+
@cache = []
|
29
32
|
else
|
30
33
|
raise Sapos::Print::Error, "Configuration is missing. Make sure to create this file: #{config_file}"
|
31
34
|
end
|
@@ -42,9 +45,13 @@ module Sapos
|
|
42
45
|
def verify?
|
43
46
|
@verify == true
|
44
47
|
end
|
48
|
+
|
49
|
+
def duplicate_control?
|
50
|
+
@duplicate_control.to_s.downcase.eql?("si")
|
51
|
+
end
|
45
52
|
|
46
53
|
def to_h
|
47
|
-
{printer: @printer, adapter: @adapter, interface: @interface, q: @q, key: @key, emv_path: @emv_path, emv_terminal: @emv_terminal, user_id: @user_id }
|
54
|
+
{printer: @printer, adapter: @adapter, interface: @interface, q: @q, key: @key, emv_path: @emv_path, emv_terminal: @emv_terminal, user_id: @user_id, duplicate_control: @duplicate_control, printers: @printers }
|
48
55
|
end
|
49
56
|
end
|
50
57
|
end
|
data/lib/sapos/print/printer.rb
CHANGED
@@ -10,11 +10,18 @@ module Sapos
|
|
10
10
|
def print(args = {})
|
11
11
|
raw_message = args[:document]
|
12
12
|
|
13
|
-
log_text = "id=#{args[:id]},doc=#{args[:document_number]},control=#{args[:print_control] ? "SI" : "NO"}\t"
|
13
|
+
log_text = "id=#{args[:id]},doc=#{args[:document_number]},control=#{args[:print_control] ? "SI" : "NO"},cache=0\t"
|
14
14
|
filename = "#{args[:document_number]}.print" if args[:document_number]
|
15
15
|
filename = SecureRandom.hex if filename.nil?
|
16
16
|
result = false
|
17
17
|
raw = raw_message.force_encoding("UTF-8")
|
18
|
+
msgid = args[:id]
|
19
|
+
if @config.duplicate_control? && @config.cache.include?(msgid)
|
20
|
+
log_text += " => DUPLICADO (DC)"
|
21
|
+
log_text.gsub!("cache=0", "cache=#{@config.cache.size}")
|
22
|
+
puts log_text
|
23
|
+
return true
|
24
|
+
end
|
18
25
|
begin
|
19
26
|
if args[:print_control] && args[:document_number]
|
20
27
|
print_dir = File.join(Sapos::Print.app_directory, 'print')
|
@@ -39,6 +46,11 @@ module Sapos
|
|
39
46
|
#puts "Result: #{result}"
|
40
47
|
log_text += " => OK"
|
41
48
|
end
|
49
|
+
if @config.duplicate_control?
|
50
|
+
@config.cache << msgid
|
51
|
+
@config.cache.shift if @config.cache.size > 30
|
52
|
+
log_text.gsub!("cache=0", "cache=#{@config.cache.size}")
|
53
|
+
end
|
42
54
|
puts log_text
|
43
55
|
rescue => e
|
44
56
|
puts "#{e.message}"
|
@@ -47,8 +59,7 @@ module Sapos
|
|
47
59
|
ensure
|
48
60
|
#File.delete(filename) if File.exists?(filename)
|
49
61
|
return result
|
50
|
-
end
|
51
|
-
|
62
|
+
end
|
52
63
|
end
|
53
64
|
|
54
65
|
def data(raw_message)
|
data/lib/sapos/print/q_reader.rb
CHANGED
@@ -7,7 +7,7 @@ module Sapos
|
|
7
7
|
attr_accessor :printer_config, :verbose
|
8
8
|
end
|
9
9
|
|
10
|
-
attr_accessor :pubnub, :printer, :config
|
10
|
+
attr_accessor :pubnub, :printer, :config, :printers
|
11
11
|
|
12
12
|
def self.run!
|
13
13
|
reader = QReader.new
|
@@ -29,8 +29,14 @@ module Sapos
|
|
29
29
|
end
|
30
30
|
|
31
31
|
document = Base64.decode64(msg)
|
32
|
-
|
33
|
-
|
32
|
+
|
33
|
+
current_printer = reader.printer
|
34
|
+
|
35
|
+
if msg['printer'] && reader.printers[msg['printer']]
|
36
|
+
current_printer = reader.printers[msg['printer']]
|
37
|
+
end
|
38
|
+
|
39
|
+
if !current_printer.print(document: document, print_control: print_control, document_number: document_number, id: msgid)
|
34
40
|
puts "Printer Error"
|
35
41
|
end
|
36
42
|
rescue => e
|
@@ -51,6 +57,12 @@ module Sapos
|
|
51
57
|
def initialize
|
52
58
|
@config = QReader.printer_config
|
53
59
|
@printer = Printer.new(@config)
|
60
|
+
@printers = {}
|
61
|
+
@config.printers.each do |printer|
|
62
|
+
config = @config.dup
|
63
|
+
config.printer = printer
|
64
|
+
@printers[printer] = Printer.new(config)
|
65
|
+
end
|
54
66
|
@pubnub = Pubnub.new(subscribe_key: @config.key, user_id: @config.user_id, ssl: true)
|
55
67
|
end
|
56
68
|
end
|
data/lib/sapos/print/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sapos-print
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josef Sauter
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|