quickets 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +84 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/config.ru +13 -0
- data/config/quickets.yml.example +6 -0
- data/config/warble.rb +183 -0
- data/exe/quickets +9 -0
- data/lib/jars/ticket_printer-1.2.0-jar-with-dependencies.jar +0 -0
- data/lib/quickets.rb +51 -0
- data/lib/quickets/available_printers.rb +17 -0
- data/lib/quickets/config.rb +32 -0
- data/lib/quickets/logger.rb +9 -0
- data/lib/quickets/ticket_printer.rb +34 -0
- data/lib/quickets/version.rb +3 -0
- data/quickets.gemspec +37 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cb51c53cf7c45631e9ea838a70c070d6d72bc2f1
|
4
|
+
data.tar.gz: db4552b195345ab0a58e15e472f333f0f3e3965f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e2cb0654b8a960f80d9b6cc088568e86d1ad5bda9a9e9993adade58f69e2146b88e1fb518b7bcf7ab93f4accb32c13df2cbf3a268291bfabe5d8a510d621bba
|
7
|
+
data.tar.gz: 34cb44a967ce5fb9bf1db9c636f968fbc38d57af75a54a528fdfc6b2ec5f420e73d5ee232d8d7014f21a179ddc8f0ea5dae7582135fc1c56a221be192051b178
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
jruby-9.0.1.0
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Adam Davies
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Quickets
|
2
|
+
|
3
|
+
Ticket printing web service -- useful for printing from the browser
|
4
|
+
directly from javascript.
|
5
|
+
|
6
|
+
Exposes the following http API:
|
7
|
+
|
8
|
+
GET / Returns a string
|
9
|
+
GET /printers Returns a list of printer names
|
10
|
+
POST /print-tickets Prints the given tickets to the specifically
|
11
|
+
named printer
|
12
|
+
|
13
|
+
In all but the simple "/" path, an api_key is required.
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
This is a jruby gem and require Java 1.7+.
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'quickets'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
Or install it yourself as:
|
30
|
+
|
31
|
+
$ gem install quickets
|
32
|
+
|
33
|
+
## Running
|
34
|
+
|
35
|
+
The QUICKETS_DIR env var must be set, which points to the directory
|
36
|
+
holding the configuration file.
|
37
|
+
|
38
|
+
QUICKETS_DIR=./config bundle exec puma
|
39
|
+
|
40
|
+
The puma cli has been copy-pasted to exe/quickets to allow simpler gem
|
41
|
+
install then run.
|
42
|
+
|
43
|
+
Warbler is also configured which will package up the jruby app along
|
44
|
+
with the jetty web server -- to use it:
|
45
|
+
|
46
|
+
warble executable war
|
47
|
+
QUICKETS_DIR=~/quickets/config java -jar quickets.war
|
48
|
+
|
49
|
+
Note that the java web server can't use a relative QUICKETS_DIR since it
|
50
|
+
will unpack the jar into a tmp directory.
|
51
|
+
|
52
|
+
## Configuration
|
53
|
+
|
54
|
+
Configuration is through a quickets.yml file which should be in the
|
55
|
+
directory specified by QUICKETS_DIR.
|
56
|
+
|
57
|
+
This file contains a map where the keys are api keys, and the values are
|
58
|
+
printer names. An examples:
|
59
|
+
|
60
|
+
wharf-api12345ZSDFLKJSFD:
|
61
|
+
- Front Counter Printer
|
62
|
+
- Ticket Office Printer
|
63
|
+
|
64
|
+
The printer names given should match exactly as defined in your systems
|
65
|
+
printer configuration.
|
66
|
+
|
67
|
+
## Development
|
68
|
+
|
69
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
70
|
+
|
71
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
72
|
+
|
73
|
+
Depends on [sealink/ticket_printer](https://github.com/sealink/ticket_printer)
|
74
|
+
which is compiled, then built into a single jar, and exists in lib/jars.
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/quickets. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
79
|
+
|
80
|
+
|
81
|
+
## License
|
82
|
+
|
83
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
84
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "quickets"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/config.ru
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "bundler/setup"
|
3
|
+
require "rack/cors"
|
4
|
+
require "quickets"
|
5
|
+
|
6
|
+
use Rack::Cors do
|
7
|
+
allow do
|
8
|
+
origins '*'
|
9
|
+
resource '/*', :headers => :any, :methods => [:get, :post, :options]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
run Quickets::App.freeze.app
|
data/config/warble.rb
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
# Disable Rake-environment-task framework detection by uncommenting/setting to false
|
2
|
+
# Warbler.framework_detection = false
|
3
|
+
|
4
|
+
# Warbler web application assembly configuration file
|
5
|
+
Warbler::Config.new do |config|
|
6
|
+
# Features: additional options controlling how the jar is built.
|
7
|
+
# Currently the following features are supported:
|
8
|
+
# - gemjar: package the gem repository in a jar file in WEB-INF/lib
|
9
|
+
# - executable: embed a web server and make the war executable
|
10
|
+
# - compiled: compile .rb files to .class files
|
11
|
+
# config.features = %w(gemjar)
|
12
|
+
|
13
|
+
# Application directories to be included in the webapp.
|
14
|
+
# config.dirs = %w(app config db lib log script vendor tmp)
|
15
|
+
|
16
|
+
# Additional files/directories to include, above those in config.dirs
|
17
|
+
# config.includes = FileList["db"]
|
18
|
+
|
19
|
+
# Additional files/directories to exclude
|
20
|
+
# config.excludes = FileList["lib/tasks/*"]
|
21
|
+
|
22
|
+
# Additional Java .jar files to include. Note that if .jar files are placed
|
23
|
+
# in lib (and not otherwise excluded) then they need not be mentioned here.
|
24
|
+
# JRuby and JRuby-Rack are pre-loaded in this list. Be sure to include your
|
25
|
+
# own versions if you directly set the value
|
26
|
+
# config.java_libs += FileList["lib/java/*.jar"]
|
27
|
+
|
28
|
+
# Loose Java classes and miscellaneous files to be included.
|
29
|
+
# config.java_classes = FileList["target/classes/**.*"]
|
30
|
+
|
31
|
+
# One or more pathmaps defining how the java classes should be copied into
|
32
|
+
# the archive. The example pathmap below accompanies the java_classes
|
33
|
+
# configuration above. See http://rake.rubyforge.org/classes/String.html#M000017
|
34
|
+
# for details of how to specify a pathmap.
|
35
|
+
# config.pathmaps.java_classes << "%{target/classes/,}p"
|
36
|
+
|
37
|
+
# Bundler support is built-in. If Warbler finds a Gemfile in the
|
38
|
+
# project directory, it will be used to collect the gems to bundle
|
39
|
+
# in your application. If you wish to explicitly disable this
|
40
|
+
# functionality, uncomment here.
|
41
|
+
# config.bundler = false
|
42
|
+
|
43
|
+
# An array of Bundler groups to avoid including in the war file.
|
44
|
+
# Defaults to ["development", "test", "assets"].
|
45
|
+
# config.bundle_without = []
|
46
|
+
|
47
|
+
# Other gems to be included. If you don't use Bundler or a gemspec
|
48
|
+
# file, you need to tell Warbler which gems your application needs
|
49
|
+
# so that they can be packaged in the archive.
|
50
|
+
# For Rails applications, the Rails gems are included by default
|
51
|
+
# unless the vendor/rails directory is present.
|
52
|
+
# config.gems += ["activerecord-jdbcmysql-adapter", "jruby-openssl"]
|
53
|
+
# config.gems << "tzinfo"
|
54
|
+
|
55
|
+
# Uncomment this if you don't want to package rails gem.
|
56
|
+
# config.gems -= ["rails"]
|
57
|
+
|
58
|
+
# The most recent versions of gems are used.
|
59
|
+
# You can specify versions of gems by using a hash assignment:
|
60
|
+
# config.gems["rails"] = "2.3.10"
|
61
|
+
|
62
|
+
# You can also use regexps or Gem::Dependency objects for flexibility or
|
63
|
+
# finer-grained control.
|
64
|
+
# config.gems << /^merb-/
|
65
|
+
# config.gems << Gem::Dependency.new("merb-core", "= 0.9.3")
|
66
|
+
|
67
|
+
# Include gem dependencies not mentioned specifically. Default is
|
68
|
+
# true, uncomment to turn off.
|
69
|
+
# config.gem_dependencies = false
|
70
|
+
|
71
|
+
# Array of regular expressions matching relative paths in gems to be
|
72
|
+
# excluded from the war. Defaults to empty, but you can set it like
|
73
|
+
# below, which excludes test files.
|
74
|
+
# config.gem_excludes = [/^(test|spec)\//]
|
75
|
+
|
76
|
+
# Pathmaps for controlling how application files are copied into the archive
|
77
|
+
# config.pathmaps.application = ["WEB-INF/%p"]
|
78
|
+
|
79
|
+
# Name of the archive (without the extension). Defaults to the basename
|
80
|
+
# of the project directory.
|
81
|
+
# config.jar_name = "mywar"
|
82
|
+
|
83
|
+
# File extension for the archive. Defaults to either 'jar' or 'war'.
|
84
|
+
# config.jar_extension = "jar"
|
85
|
+
|
86
|
+
# Destionation for the created archive. Defaults to project's root directory.
|
87
|
+
# config.autodeploy_dir = "dist/"
|
88
|
+
|
89
|
+
# Name of the MANIFEST.MF template for the war file. Defaults to a simple
|
90
|
+
# MANIFEST.MF that contains the version of Warbler used to create the war file.
|
91
|
+
# config.manifest_file = "config/MANIFEST.MF"
|
92
|
+
|
93
|
+
# When using the 'compiled' feature and specified, only these Ruby
|
94
|
+
# files will be compiled. Default is to compile all \.rb files in
|
95
|
+
# the application.
|
96
|
+
# config.compiled_ruby_files = FileList['app/**/*.rb']
|
97
|
+
|
98
|
+
# Determines if ruby files in supporting gems will be compiled.
|
99
|
+
# Ignored unless compile feature is used.
|
100
|
+
# config.compile_gems = false
|
101
|
+
|
102
|
+
# When set it specify the bytecode version for compiled class files
|
103
|
+
# config.bytecode_version = "1.6"
|
104
|
+
|
105
|
+
# When set to true, Warbler will override the value of ENV['GEM_HOME'] even it
|
106
|
+
# has already been set. When set to false it will use any existing value of
|
107
|
+
# GEM_HOME if it is set.
|
108
|
+
# config.override_gem_home = true
|
109
|
+
|
110
|
+
# Allows for specifing custom executables
|
111
|
+
# config.executable = ["rake", "bin/rake"]
|
112
|
+
|
113
|
+
# Sets default (prefixed) parameters for the executables
|
114
|
+
# config.executable_params = "do:something"
|
115
|
+
|
116
|
+
# If set to true, moves jar files into WEB-INF/lib. Prior to version 1.4.2 of Warbler this was done
|
117
|
+
# by default. But since 1.4.2 this config defaults to false. It may need to be set to true for
|
118
|
+
# web servers that do not explode the WAR file.
|
119
|
+
# Alternatively, this option can be set to a regular expression, which will
|
120
|
+
# act as a jar selector -- only jar files that match the pattern will be
|
121
|
+
# included in the archive.
|
122
|
+
# config.move_jars_to_webinf_lib = false
|
123
|
+
|
124
|
+
# === War files only below here ===
|
125
|
+
|
126
|
+
# Path to the pre-bundled gem directory inside the war file. Default
|
127
|
+
# is 'WEB-INF/gems'. Specify path if gems are already bundled
|
128
|
+
# before running Warbler. This also sets 'gem.path' inside web.xml.
|
129
|
+
# config.gem_path = "WEB-INF/vendor/bundler_gems"
|
130
|
+
|
131
|
+
# Files for WEB-INF directory (next to web.xml). This contains
|
132
|
+
# web.xml by default. If there is an .erb-File it will be processed
|
133
|
+
# with webxml-config. You may want to exclude this file via
|
134
|
+
# config.excludes.
|
135
|
+
# config.webinf_files += FileList["jboss-web.xml"]
|
136
|
+
|
137
|
+
# Files to be included in the root of the webapp. Note that files in public
|
138
|
+
# will have the leading 'public/' part of the path stripped during staging.
|
139
|
+
# config.public_html = FileList["public/**/*", "doc/**/*"]
|
140
|
+
|
141
|
+
# Pathmaps for controlling how public HTML files are copied into the .war
|
142
|
+
# config.pathmaps.public_html = ["%{public/,}p"]
|
143
|
+
|
144
|
+
# Embedded webserver to use with the 'executable' feature. Currently supported
|
145
|
+
# webservers are:
|
146
|
+
# * <tt>winstone</tt> (default) - Winstone 0.9.10 from sourceforge
|
147
|
+
# * <tt>jenkins-ci.winstone</tt> - Improved Winstone from Jenkins CI
|
148
|
+
# * <tt>jetty</tt> - Embedded Jetty from Eclipse
|
149
|
+
# config.webserver = 'jetty'
|
150
|
+
|
151
|
+
# Value of RAILS_ENV for the webapp -- default as shown below
|
152
|
+
# config.webxml.rails.env = ENV['RAILS_ENV'] || 'production'
|
153
|
+
|
154
|
+
# Application booter to use, one of :rack, :rails, or :merb (autodetected by default)
|
155
|
+
# config.webxml.booter = :rails
|
156
|
+
|
157
|
+
# Set JRuby to run in 1.9 mode.
|
158
|
+
# config.webxml.jruby.compat.version = "1.9"
|
159
|
+
|
160
|
+
# When using the :rack booter, "Rackup" script to use.
|
161
|
+
# - For 'rackup.path', the value points to the location of the rackup
|
162
|
+
# script in the web archive file. You need to make sure this file
|
163
|
+
# gets included in the war, possibly by adding it to config.includes
|
164
|
+
# or config.webinf_files above.
|
165
|
+
# - For 'rackup', the rackup script you provide as an inline string
|
166
|
+
# is simply embedded in web.xml.
|
167
|
+
# The script is evaluated in a Rack::Builder to load the application.
|
168
|
+
# Examples:
|
169
|
+
# config.webxml.rackup.path = 'WEB-INF/hello.ru'
|
170
|
+
# config.webxml.rackup = %{require './lib/demo'; run Rack::Adapter::Camping.new(Demo)}
|
171
|
+
# config.webxml.rackup = require 'cgi' && CGI::escapeHTML(File.read("config.ru"))
|
172
|
+
|
173
|
+
# Control the pool of Rails runtimes. Leaving unspecified means
|
174
|
+
# the pool will grow as needed to service requests. It is recommended
|
175
|
+
# that you fix these values when running a production server!
|
176
|
+
# If you're using threadsafe! mode, you probably don't want to set these values,
|
177
|
+
# since 1 runtime(default for threadsafe mode) will be enough.
|
178
|
+
# config.webxml.jruby.min.runtimes = 2
|
179
|
+
# config.webxml.jruby.max.runtimes = 4
|
180
|
+
|
181
|
+
# JNDI data source name
|
182
|
+
# config.webxml.jndi = 'jdbc/rails'
|
183
|
+
end
|
data/exe/quickets
ADDED
Binary file
|
data/lib/quickets.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require "roda"
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
require "quickets/config"
|
5
|
+
require "quickets/logger"
|
6
|
+
|
7
|
+
require "quickets/ticket_printer"
|
8
|
+
require "quickets/available_printers"
|
9
|
+
|
10
|
+
# Config
|
11
|
+
Quickets.logger.error "No QUICKETS_DIR set" if ENV['QUICKETS_DIR'].nil?
|
12
|
+
quickets_dir = Pathname.new ENV['QUICKETS_DIR']
|
13
|
+
Quickets.configure(quickets_dir.join("quickets.yml"))
|
14
|
+
|
15
|
+
module Quickets
|
16
|
+
class App < Roda
|
17
|
+
plugin :json_parser # request parse
|
18
|
+
plugin :json # response to_json
|
19
|
+
plugin :error_handler
|
20
|
+
|
21
|
+
route do |r|
|
22
|
+
r.root do
|
23
|
+
"Hello I am Quickets"
|
24
|
+
end
|
25
|
+
|
26
|
+
r.on do
|
27
|
+
Quickets.config.check_api_key!(r['api_key'])
|
28
|
+
|
29
|
+
r.on 'printers' do
|
30
|
+
AvailablePrinters.all(r['api_key'])
|
31
|
+
end
|
32
|
+
|
33
|
+
r.post "print-tickets" do
|
34
|
+
ticket_printer = TicketPrinter.new(r.params)
|
35
|
+
if ticket_printer.can_print?
|
36
|
+
Thread.new { ticket_printer.print }
|
37
|
+
{status: 'ok'}
|
38
|
+
else
|
39
|
+
response.status = 500
|
40
|
+
{error: "Unknown printer: [#{ticket_printer.printer_name}]"}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
error do |e|
|
47
|
+
Quickets.logger.error e
|
48
|
+
{ error: e.message }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Interface to java lib
|
2
|
+
require "java"
|
3
|
+
require "jars/ticket_printer-1.2.0-jar-with-dependencies.jar"
|
4
|
+
|
5
|
+
java_import com.quicktravel.ticket_printer.PrintServiceLocator
|
6
|
+
|
7
|
+
module Quickets
|
8
|
+
class AvailablePrinters
|
9
|
+
def self.all(api_key)
|
10
|
+
installed_printers = PrintServiceLocator.new.all.map(&:name)
|
11
|
+
|
12
|
+
# Return only printers configured AND installed
|
13
|
+
# ...and retain ordering as defined in config
|
14
|
+
Quickets.config.printers_for(api_key) & installed_printers
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Quickets
|
4
|
+
def self.configure(file_name)
|
5
|
+
@config = Config.new(YAML.load_file(file_name))
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.config
|
9
|
+
@config
|
10
|
+
end
|
11
|
+
|
12
|
+
class Config
|
13
|
+
attr_reader :printers
|
14
|
+
|
15
|
+
def initialize(printers_by_api_key)
|
16
|
+
@printers_by_api_key = printers_by_api_key
|
17
|
+
end
|
18
|
+
|
19
|
+
def check_api_key!(api_key)
|
20
|
+
return if valid_api_key? api_key
|
21
|
+
fail ArgumentError, 'Invalid API key'
|
22
|
+
end
|
23
|
+
|
24
|
+
def valid_api_key?(api_key)
|
25
|
+
@printers_by_api_key.key? api_key
|
26
|
+
end
|
27
|
+
|
28
|
+
def printers_for(api_key)
|
29
|
+
@printers_by_api_key.fetch(api_key)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Interface to java lib
|
2
|
+
require "java"
|
3
|
+
require "jars/ticket_printer-1.2.0-jar-with-dependencies.jar"
|
4
|
+
java_import com.quicktravel.ticket_printer.TicketPrintCommand
|
5
|
+
|
6
|
+
require 'quickets/available_printers'
|
7
|
+
|
8
|
+
module Quickets
|
9
|
+
class TicketPrinter
|
10
|
+
attr_reader :printer_name
|
11
|
+
|
12
|
+
def initialize(params)
|
13
|
+
@api_key = params.fetch('api_key')
|
14
|
+
@printer_name = params.fetch('printer_name')
|
15
|
+
@page_format = params.fetch('page_format')
|
16
|
+
@tickets = params.fetch('tickets')
|
17
|
+
end
|
18
|
+
|
19
|
+
def can_print?
|
20
|
+
AvailablePrinters.all(@api_key).include? @printer_name
|
21
|
+
end
|
22
|
+
|
23
|
+
def print
|
24
|
+
ticket_print_command = TicketPrintCommand.new
|
25
|
+
ticket_print_command.printer_name = @printer_name
|
26
|
+
ticket_print_command.ticket_page_settings_from_map = @page_format
|
27
|
+
ticket_print_command.tickets_from_data_list = @tickets
|
28
|
+
|
29
|
+
Thread.new do
|
30
|
+
ticket_print_command.execute
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/quickets.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'quickets/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "quickets"
|
8
|
+
spec.version = Quickets::VERSION
|
9
|
+
spec.authors = ["Adam Davies"]
|
10
|
+
spec.email = ["adzdavies@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Quickets}
|
13
|
+
spec.description = %q{Print quickets}
|
14
|
+
spec.homepage = "http://github.com/adz/quickets"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_dependency "roda"
|
31
|
+
spec.add_dependency "puma"
|
32
|
+
spec.add_dependency "rack-cors"
|
33
|
+
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "rspec"
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quickets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Davies
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
name: roda
|
20
|
+
prerelease: false
|
21
|
+
type: :runtime
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
name: puma
|
34
|
+
prerelease: false
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
name: rack-cors
|
48
|
+
prerelease: false
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.10'
|
61
|
+
name: bundler
|
62
|
+
prerelease: false
|
63
|
+
type: :development
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '10.0'
|
75
|
+
name: rake
|
76
|
+
prerelease: false
|
77
|
+
type: :development
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
name: rspec
|
90
|
+
prerelease: false
|
91
|
+
type: :development
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Print quickets
|
98
|
+
email:
|
99
|
+
- adzdavies@gmail.com
|
100
|
+
executables:
|
101
|
+
- quickets
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".ruby-version"
|
108
|
+
- ".travis.yml"
|
109
|
+
- CODE_OF_CONDUCT.md
|
110
|
+
- Gemfile
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- config.ru
|
117
|
+
- config/quickets.yml.example
|
118
|
+
- config/warble.rb
|
119
|
+
- exe/quickets
|
120
|
+
- lib/jars/ticket_printer-1.2.0-jar-with-dependencies.jar
|
121
|
+
- lib/quickets.rb
|
122
|
+
- lib/quickets/available_printers.rb
|
123
|
+
- lib/quickets/config.rb
|
124
|
+
- lib/quickets/logger.rb
|
125
|
+
- lib/quickets/ticket_printer.rb
|
126
|
+
- lib/quickets/version.rb
|
127
|
+
- quickets.gemspec
|
128
|
+
homepage: http://github.com/adz/quickets
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
metadata:
|
132
|
+
allowed_push_host: https://rubygems.org
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.4.8
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: Quickets
|
153
|
+
test_files: []
|