lib/sapos/print/q_reader.rb in sapos-print-1.0.6 vs lib/sapos/print/q_reader.rb in sapos-print-1.0.7
- old
+ new
@@ -11,14 +11,22 @@
def self.run!
reader = QReader.new
callback = Pubnub::SubscribeCallback.new(
message: -> (envelope){
- document = Base64.decode64(envelope.result[:data][:message]['document'])
- print_control = envelope.result[:data][:message]['print_control']
- document_number = envelope.result[:data][:message]['document_number']
+ msg = envelope.result[:data][:message]
+ print_control = nil
+ document_number = nil
+ if msg.is_a?(Hash)
+ msg = msg['document']
+ print_control = msg['print_control']
+ document_number = msg['document_number']
+ end
+
+ document = Base64.decode64(msg)
+
if reader.printer.print(document: document, print_control: print_control, document_number: document_number)
puts "OK"
else
puts "Printer Error".red
end
@@ -35,10 +43,10 @@
end
def initialize
@config = QReader.printer_config
@printer = Printer.new(@config)
- @pubnub = Pubnub.new(subscribe_key: @config.key)
+ @pubnub = Pubnub.new(subscribe_key: @config.key, user_id: @config.user_id)
end
end
end
end
\ No newline at end of file