sapos-print 1.0.6 → 1.0.8

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: aa9dbe51b563ee70ee2027c134a1bd153f324320b3de2fe8edeaf746cacf0074
4
- data.tar.gz: dbd27b3c96dbd8f3f16a1127380e863e7e39abd2281f9fbd0e661257e6f34628
3
+ metadata.gz: 6c6213f40144b180efcab3601be965bd4eb27538e24ce1061d5645294c7771d3
4
+ data.tar.gz: b6ebb3d3b2faa32eaff6c7f65b488582a79c6ca7e3006dc574baa0eea9d3a80c
5
5
  SHA512:
6
- metadata.gz: 1ede8347459232583ccdef4f6b7f9750272c566b79f4c019fdc7043e30c9e685759527b3c2a5d692130abf53c81d012c2cd694d1feb423fc4cf089077e437fa8
7
- data.tar.gz: d10655107cdad90e67da0e0a4ec2c97af27087e85b91e3859eb6edc23d1beb9c2381bc5a6311b1dd80960d4c103a4d3efedb9b8b72690c379e720f7bedc4d3fd
6
+ metadata.gz: f5c29e07f820962d25be97d733a566397ce59de91f6b0f9ab14b2735bcc392b9da026f887612db38e8a7e3e9325266814f4b22f2789d2f07efdc7572083cf49e
7
+ data.tar.gz: da79df111441d3512408add3a69fab610a07573ae7104a7ee16a84da4644684fcf5386971aa9a6367e47529a043cfe7316c72706f48723ad975a6470c8455ae5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sapos-print (1.0.6)
4
+ sapos-print (1.0.7)
5
5
  activesupport
6
6
  awesome_print
7
7
  json
@@ -12,29 +12,29 @@ PATH
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- activesupport (7.0.2)
15
+ activesupport (7.0.2.3)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
17
  i18n (>= 1.6, < 2)
18
18
  minitest (>= 5.1)
19
19
  tzinfo (~> 2.0)
20
- addressable (2.8.0)
21
- public_suffix (>= 2.0.2, < 5.0)
20
+ addressable (2.8.1)
21
+ public_suffix (>= 2.0.2, < 6.0)
22
22
  awesome_print (1.9.2)
23
- concurrent-ruby (1.1.9)
23
+ concurrent-ruby (1.1.10)
24
24
  concurrent-ruby-edge (0.5.0)
25
25
  concurrent-ruby (~> 1.1.5)
26
26
  domain_name (0.5.20190701)
27
27
  unf (>= 0.0.5, < 1.0.0)
28
- dry-configurable (0.14.0)
29
- concurrent-ruby (~> 1.0)
28
+ dry-configurable (0.16.1)
30
29
  dry-core (~> 0.6)
31
- dry-container (0.9.0)
30
+ zeitwerk (~> 2.6)
31
+ dry-container (0.11.0)
32
32
  concurrent-ruby (~> 1.0)
33
- dry-configurable (~> 0.13, >= 0.13.0)
34
- dry-core (0.7.1)
33
+ dry-core (0.9.1)
35
34
  concurrent-ruby (~> 1.0)
35
+ zeitwerk (~> 2.6)
36
36
  dry-inflector (0.2.1)
37
- dry-initializer (3.1.1)
37
+ dry-initializer (3.0.4)
38
38
  dry-logic (1.2.0)
39
39
  concurrent-ruby (~> 1.0)
40
40
  dry-core (~> 0.5, >= 0.5)
@@ -58,18 +58,18 @@ GEM
58
58
  dry-initializer (~> 3.0)
59
59
  dry-schema (~> 1.8, >= 1.8.0)
60
60
  http-accept (1.7.0)
61
- http-cookie (1.0.4)
61
+ http-cookie (1.0.5)
62
62
  domain_name (~> 0.5)
63
63
  httpclient (2.8.3)
64
- i18n (1.9.1)
64
+ i18n (1.12.0)
65
65
  concurrent-ruby (~> 1.0)
66
- json (2.6.1)
66
+ json (2.6.2)
67
67
  mime-types (3.4.1)
68
68
  mime-types-data (~> 3.2015)
69
69
  mime-types-data (3.2022.0105)
70
- minitest (5.15.0)
70
+ minitest (5.17.0)
71
71
  netrc (0.11.0)
72
- public_suffix (4.0.6)
72
+ public_suffix (5.0.1)
73
73
  pubnub (4.8.0)
74
74
  addressable (>= 2.0.0)
75
75
  concurrent-ruby (~> 1.1.5)
@@ -85,11 +85,12 @@ GEM
85
85
  netrc (~> 0.8)
86
86
  thor (1.2.1)
87
87
  timers (4.3.3)
88
- tzinfo (2.0.4)
88
+ tzinfo (2.0.5)
89
89
  concurrent-ruby (~> 1.0)
90
90
  unf (0.1.4)
91
91
  unf_ext
92
- unf_ext (0.0.8)
92
+ unf_ext (0.0.8.2)
93
+ zeitwerk (2.6.6)
93
94
 
94
95
  PLATFORMS
95
96
  arm64-darwin-21
@@ -10,14 +10,31 @@ module Sapos
10
10
  config = {}
11
11
 
12
12
  url = ask("Configuration URL")
13
- response = RestClient.get(url)
14
- data = JSON.parse(response)
13
+ if url.eql?('manual')
14
+ data = {}
15
+ data["channel"] = ask("Channel:")
16
+ data["key"] = ask("Queue Key")
17
+ else
18
+ response = RestClient.get(url)
19
+ data = JSON.parse(response)
20
+ end
21
+
22
+ config_file = "#{Sapos::Print.app_directory}/config.yml"
23
+ user_id = nil
24
+ if File.exist?(config_file)
25
+ template = ERB.new(File.read(config_file))
26
+ result = YAML.load(template.result(binding))
27
+ user_id = result[:user_id]
28
+ end
29
+
30
+ user_id = SecureRandom.uuid if user_id.nil?
15
31
 
16
32
  config[:q] = data["channel"]
17
33
  config[:key] = data["key"]
18
34
  config[:printer] = ask("Printer Name: ")
19
35
  config[:adapter] = ask("Printer Adapter: ", limited_to: ["console", "cups", "windows"])
20
36
  config[:interface] = ask("Interface", limited_to: ["text", "escp"])
37
+ config[:user_id] = user_id
21
38
 
22
39
  if yes?("Are you sure that you want to write the configuration file?")
23
40
  Sapos::Print::Configuration.write(config)
@@ -27,16 +44,19 @@ module Sapos
27
44
  end
28
45
 
29
46
  desc "start", "run service"
47
+ option :verbose, type: :boolean
30
48
  def start
31
49
  info
32
50
  config = Sapos::Print.config
33
- puts ["Q=#{config.q.to_s}", "Printer=#{config.printer.to_s}", "Adapter=#{config.adapter.to_s}", "Interface=#{config.interface}"].join("\n")
51
+ puts ["Q=#{config.q.to_s}", "Printer=#{config.printer.to_s}", "Adapter=#{config.adapter.to_s}", "Interface=#{config.interface}"].join(";")
34
52
 
35
53
  print_dir = File.join(Sapos::Print.app_directory, 'print')
36
54
  if File.exists?(print_dir)
37
- FileUtils.rm_rf Dir.glob("#{print_dir}/*")
55
+ Dir.glob("#{print_dir}/*.print").each do |x|
56
+ FileUtils.rm_rf(x) if File.ctime(x) < Time.now - 3600
57
+ end
38
58
  end
39
-
59
+ config.verbose = options[:verbose]
40
60
  Sapos::Print::QReader.printer_config = config
41
61
  Sapos::Print::QReader.verbose = options[:verbose]
42
62
  Sapos::Print::QReader.run!
@@ -50,6 +70,7 @@ module Sapos
50
70
  printer.print(document: "This is a test\nprint page\nwithno special commands", document_number: "test", print_control: true)
51
71
  end
52
72
 
73
+ desc "windows_test_print", "test printer"
53
74
  def windows_test_print
54
75
  info
55
76
 
@@ -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
9
+ attr_accessor :printer, :adapter, :interface, :q, :key, :emv_path, :emv_terminal, :user_id, :verbose
10
10
 
11
11
  def self.write(args = {})
12
12
  config_file = "#{Sapos::Print.app_directory}/config.yml"
@@ -18,7 +18,6 @@ module Sapos
18
18
  if File.exist?(config_file)
19
19
  template = ERB.new(File.read(config_file))
20
20
  result = YAML.load(template.result(binding))
21
- ap result
22
21
  @printer = result[:printer]
23
22
  @adapter = result[:adapter]
24
23
  @interface = result[:interface]
@@ -26,6 +25,7 @@ module Sapos
26
25
  @key = result[:key]
27
26
  @emv_path = result[:emv_path]
28
27
  @emv_terminal = result[:emv_terminal]
28
+ @user_id = result[:user_id]
29
29
  else
30
30
  raise Sapos::Print::Error, "Configuration is missing. Make sure to create this file: #{config_file}"
31
31
  end
@@ -44,7 +44,7 @@ module Sapos
44
44
  end
45
45
 
46
46
  def to_h
47
- {printer: @printer, adapter: @adapter, interface: @interface, q: @q, key: @key, emv_path: @emv_path, emv_terminal: @emv_terminal }
47
+ {printer: @printer, adapter: @adapter, interface: @interface, q: @q, key: @key, emv_path: @emv_path, emv_terminal: @emv_terminal, user_id: @user_id }
48
48
  end
49
49
  end
50
50
  end
@@ -10,7 +10,7 @@ module Sapos
10
10
  def print(args = {})
11
11
  raw_message = args[:document]
12
12
 
13
- log_text = "Print #{args[:document_number]},#{args[:print_control]}"
13
+ log_text = "id=#{args[:id]},doc=#{args[:document_number]},control=#{args[:print_control] ? "SI" : "NO"}\t"
14
14
  filename = "#{args[:document_number]}.print" if args[:document_number]
15
15
  filename = SecureRandom.hex if filename.nil?
16
16
  result = false
@@ -27,6 +27,9 @@ module Sapos
27
27
  result = send_to_printer({file: filename})
28
28
  #puts "Result: #{result}"
29
29
  log_text += " => OK"
30
+ else
31
+ result = true
32
+ log_text += " => DUPLICADO"
30
33
  end
31
34
  else
32
35
  printable = data(raw_message)
@@ -49,7 +52,6 @@ module Sapos
49
52
  end
50
53
 
51
54
  def data(raw_message)
52
- puts "data: #{@config.interface}"
53
55
  case @config.interface
54
56
  when 'text'
55
57
  return raw_message
@@ -71,9 +73,9 @@ module Sapos
71
73
  def send_to_printer(opts = {})
72
74
  case @config.adapter
73
75
  when 'console'
74
- puts "=> CONSOLE: file: #{opts[:file]}<="
76
+ puts "=> CONSOLE: file: #{opts[:file]}<=\n\n"
75
77
  puts File.read(opts[:file])
76
- puts "=> END CONSOLE =<"
78
+ puts "\n=> END CONSOLE =<"
77
79
  return true
78
80
  when 'cups'
79
81
  file = opts.delete(:file)
@@ -81,7 +83,7 @@ module Sapos
81
83
  command_options << "-d #{@printer_name}"
82
84
  command_options << "-o raw" if opts[:raw].present?
83
85
  command = "lp #{command_options.join(" ")} #{file}"
84
- puts "CMD => #{command}"
86
+ puts "CMD => #{command}" if @config.verbose
85
87
  if !system(command)
86
88
  puts "Not executed"
87
89
  return false
@@ -13,21 +13,35 @@ module Sapos
13
13
  reader = QReader.new
14
14
  callback = Pubnub::SubscribeCallback.new(
15
15
  message: -> (envelope){
16
- document = Base64.decode64(envelope.result[:data][:message]['document'])
17
- print_control = envelope.result[:data][:message]['print_control']
18
- document_number = envelope.result[:data][:message]['document_number']
16
+ begin
17
+
18
+ msg = envelope.result[:data][:message]
19
+ msgid = envelope.result.dig(:data, :publish_time_object, :timetoken)
20
+ print_control = nil
21
+ document_number = nil
22
+
23
+ puts msg.inspect if reader.config.verbose
24
+
25
+ if msg.is_a?(Hash)
26
+ print_control = msg['print_control']
27
+ document_number = msg['document_number']
28
+ msg = msg['document']
29
+ end
19
30
 
20
- if reader.printer.print(document: document, print_control: print_control, document_number: document_number)
21
- puts "OK"
22
- else
23
- puts "Printer Error".red
31
+ document = Base64.decode64(msg)
32
+
33
+ if !reader.printer.print(document: document, print_control: print_control, document_number: document_number, id: msgid)
34
+ puts "Printer Error"
35
+ end
36
+ rescue => e
37
+ puts "Error: #{e.message}"
24
38
  end
25
39
  },
26
40
  presence: ->(envelope){},
27
41
  status: ->(envelope){}
28
42
  )
29
43
  reader.pubnub.add_listener(callback: callback)
30
- reader.pubnub.subscribe(channels: reader.config.q)
44
+ reader.pubnub.subscribe(channels: [reader.config.q])
31
45
  ARGV.clear
32
46
  while line = gets do
33
47
  #Wait forever ;-)
@@ -37,7 +51,7 @@ module Sapos
37
51
  def initialize
38
52
  @config = QReader.printer_config
39
53
  @printer = Printer.new(@config)
40
- @pubnub = Pubnub.new(subscribe_key: @config.key)
54
+ @pubnub = Pubnub.new(subscribe_key: @config.key, user_id: @config.user_id)
41
55
  end
42
56
  end
43
57
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sapos
4
4
  module Print
5
- VERSION = "1.0.6"
5
+ VERSION = "1.0.8"
6
6
  end
7
7
  end
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.6
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josef Sauter
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-09 00:00:00.000000000 Z
11
+ date: 2023-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor