Sha256: 969a47832cc776b1b9365860adaff8fe76356c293663cdd5e70d639e48f65fab

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 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){
            document = Base64.decode64(envelope.result[:data][:message]['document'])
            print_control = envelope.result[:data][:message]['print_control']
            document_number = envelope.result[:data][:message]['document_number']
            
            if reader.printer.print(document: document, print_control: print_control, document_number: document_number)
              puts "OK"
            else
              puts "Printer Error".red
            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)
      end        
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sapos-print-1.0.6 lib/sapos/print/q_reader.rb
sapos-print-1.0.5 lib/sapos/print/q_reader.rb
sapos-print-1.0.4 lib/sapos/print/q_reader.rb
sapos-print-1.0.3 lib/sapos/print/q_reader.rb
sapos-print-1.0.1 lib/sapos/print/q_reader.rb