sapos-print 1.0.7 → 1.0.9

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: 6676d897cee608283071d8a13da6989e1db58cbbab4f4ba819be4b6fc9f80b30
4
- data.tar.gz: 7c59412ee4b5d748389662823f5b9502d2aee835d1261c21c9673cee0d561da2
3
+ metadata.gz: 1cf330a4cbd6cebe38d5f2c8226e11527f7f498670988f8803ad2ca36338cb7f
4
+ data.tar.gz: 7339239ef96714e6f0b7599072eb5b2aa55b9f69f8fa8614a6d9cf78fbf508f9
5
5
  SHA512:
6
- metadata.gz: cc05e1cdecdca5672a07e874afe94dce4232af5ab3c159352897e61222a24a91a25cbf894fca48cd464fbbbe12d166815e6828fbebece534c12bf27b2b020937
7
- data.tar.gz: c1300e4a85fb10fdcba5b1df562b3bcdbb73f612dccea867590ce0fd492fb32b9002c10483c451500a9c8861168f9e97838dc6511f15d76dbd88d5f201924805
6
+ metadata.gz: 8e740b34123da68ec66c0ba165e9f9e06818e46620aed83796ebfc73bea3aef09dbb970d6ce6b9a7914846d9c3316f0cc17b04e1db93a757746235cd2a208585
7
+ data.tar.gz: 3cfeb286303fbd876f7e45986d857c022315efeace92f2140bb2d90daa05293025df96601359f765c213d4311aa5d3794e001baa14265ba939828be5dfe9c0b3
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,8 +10,14 @@ 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
15
21
 
16
22
  config_file = "#{Sapos::Print.app_directory}/config.yml"
17
23
  user_id = nil
@@ -38,16 +44,19 @@ module Sapos
38
44
  end
39
45
 
40
46
  desc "start", "run service"
47
+ option :verbose, type: :boolean
41
48
  def start
42
49
  info
43
50
  config = Sapos::Print.config
44
- 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(";")
45
52
 
46
53
  print_dir = File.join(Sapos::Print.app_directory, 'print')
47
54
  if File.exists?(print_dir)
48
- 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
49
58
  end
50
-
59
+ config.verbose = options[:verbose]
51
60
  Sapos::Print::QReader.printer_config = config
52
61
  Sapos::Print::QReader.verbose = options[:verbose]
53
62
  Sapos::Print::QReader.run!
@@ -61,6 +70,7 @@ module Sapos
61
70
  printer.print(document: "This is a test\nprint page\nwithno special commands", document_number: "test", print_control: true)
62
71
  end
63
72
 
73
+ desc "windows_test_print", "test printer"
64
74
  def windows_test_print
65
75
  info
66
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, :user_id
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]
@@ -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,29 +13,35 @@ module Sapos
13
13
  reader = QReader.new
14
14
  callback = Pubnub::SubscribeCallback.new(
15
15
  message: -> (envelope){
16
- msg = envelope.result[:data][:message]
17
- print_control = nil
18
- document_number = nil
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 msg.is_a?(Hash)
21
- msg = msg['document']
22
- print_control = msg['print_control']
23
- document_number = msg['document_number']
24
- end
25
-
26
- document = Base64.decode64(msg)
31
+ document = Base64.decode64(msg)
27
32
 
28
- if reader.printer.print(document: document, print_control: print_control, document_number: document_number)
29
- puts "OK"
30
- else
31
- puts "Printer Error".red
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}"
32
38
  end
33
39
  },
34
40
  presence: ->(envelope){},
35
41
  status: ->(envelope){}
36
42
  )
37
43
  reader.pubnub.add_listener(callback: callback)
38
- reader.pubnub.subscribe(channels: reader.config.q)
44
+ reader.pubnub.subscribe(channels: [reader.config.q])
39
45
  ARGV.clear
40
46
  while line = gets do
41
47
  #Wait forever ;-)
@@ -45,7 +51,7 @@ module Sapos
45
51
  def initialize
46
52
  @config = QReader.printer_config
47
53
  @printer = Printer.new(@config)
48
- @pubnub = Pubnub.new(subscribe_key: @config.key, user_id: @config.user_id)
54
+ @pubnub = Pubnub.new(subscribe_key: @config.key, user_id: @config.user_id, ssl: true)
49
55
  end
50
56
  end
51
57
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sapos
4
4
  module Print
5
- VERSION = "1.0.7"
5
+ VERSION = "1.0.9"
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.7
4
+ version: 1.0.9
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-02-08 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
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
140
  requirements: []
141
- rubygems_version: 3.1.4
141
+ rubygems_version: 3.2.3
142
142
  signing_key:
143
143
  specification_version: 4
144
144
  summary: SAPOSCLOUD PRINT