Sha256: 676b8e1b7370c187c0389b81ea35ba468d8edb79b1c6689489432d9cf6455efc
Contents?: true
Size: 1.71 KB
Versions: 2
Compression:
Stored size: 1.71 KB
Contents
require_relative 'printer' module Sapos module Print class QReader class << self attr_accessor :printer_config, :verbose end attr_accessor :pubnub, :printer, :config def self.run! reader = QReader.new callback = Pubnub::SubscribeCallback.new( message: -> (envelope){ begin msg = envelope.result[:data][:message] msgid = envelope.result.dig(:data, :publish_time_object, :timetoken) print_control = nil document_number = nil puts msg.inspect if reader.config.verbose if msg.is_a?(Hash) print_control = msg['print_control'] 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) puts "Printer Error" end rescue => e puts "Error: #{e.message}" end }, presence: ->(envelope){}, status: ->(envelope){} ) reader.pubnub.add_listener(callback: callback) reader.pubnub.subscribe(channels: [reader.config.q]) ARGV.clear while line = gets do #Wait forever ;-) end end def initialize @config = QReader.printer_config @printer = Printer.new(@config) @pubnub = Pubnub.new(subscribe_key: @config.key, user_id: @config.user_id, ssl: true) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sapos-print-1.0.10 | lib/sapos/print/q_reader.rb |
sapos-print-1.0.9 | lib/sapos/print/q_reader.rb |