Skip to content

Commit

Permalink
Pull out AvailablePrinters
Browse files Browse the repository at this point in the history
  • Loading branch information
adz committed Sep 15, 2015
1 parent 32ef4f2 commit 9af5d41
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/quickets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Web framework
require "roda"
require "quickets/available_printers"

# Interface to java lib
require "java"
Expand All @@ -28,8 +29,7 @@ class App < Roda
fail ArgumentError, 'Invalid API key' if config.api_key != r['api_key']

r.on 'printers' do
installed_printers = PrintServiceLocator.new.all.map(&:name)
config.printers & installed_printers # retains ordering of config
AvailablePrinters.all(r['api_key'])
end

r.post "print-tickets" do
Expand Down
17 changes: 17 additions & 0 deletions lib/quickets/available_printers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Interface to java lib
require "java"
require "jars/ticket_printer-1.2.0-jar-with-dependencies.jar"

java_import com.quicktravel.ticket_printer.PrintServiceLocator

module Quickets
class AvailablePrinters
def self.all(api_key)
installed_printers = PrintServiceLocator.new.all.map(&:name)

# Return only printers configured AND installed
# ...and retain ordering as defined in config
Quickets.config.printers_for(api_key) & installed_printers
end
end
end

0 comments on commit 9af5d41

Please sign in to comment.