lib/sapos/print/q_reader.rb in sapos-print-1.0.10 vs lib/sapos/print/q_reader.rb in sapos-print-1.1.0

- old
+ new

@@ -5,11 +5,11 @@ class QReader class << self attr_accessor :printer_config, :verbose end - attr_accessor :pubnub, :printer, :config + attr_accessor :pubnub, :printer, :config, :printers def self.run! reader = QReader.new callback = Pubnub::SubscribeCallback.new( message: -> (envelope){ @@ -27,12 +27,18 @@ document_number = msg['document_number'] msg = msg['document'] end document = Base64.decode64(msg) - - if !reader.printer.print(document: document, print_control: print_control, document_number: document_number, id: msgid) + + current_printer = reader.printer + + if msg['printer'] && reader.printers[msg['printer']] + current_printer = reader.printers[msg['printer']] + end + + if !current_printer.print(document: document, print_control: print_control, document_number: document_number, id: msgid) puts "Printer Error" end rescue => e puts "Error: #{e.message}" end @@ -49,9 +55,15 @@ end def initialize @config = QReader.printer_config @printer = Printer.new(@config) + @printers = {} + @config.printers.each do |printer| + config = @config.dup + config.printer = printer + @printers[printer] = Printer.new(config) + end @pubnub = Pubnub.new(subscribe_key: @config.key, user_id: @config.user_id, ssl: true) end end end end \ No newline at end of file