Created
May 2, 2017 17:27
-
-
Save SethWilson/e3d7609f6b95614f66eaea228b49bd84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'uri' | |
require 'net/http' | |
require 'net/https' | |
zpl = ARGF.read | |
uri = URI.parse( 'http://api.labelary.com/v1/printers/8dpmm/labels/4x6/0/' ) | |
https = Net::HTTP.new(uri.host,uri.port) | |
https.use_ssl = false | |
req = Net::HTTP::Post.new(uri.path, initheader = {'Accept' =>'image/png'}) | |
req.body = zpl | |
puts "Requestiong" | |
res = https.request(req) | |
case res | |
when Net::HTTPSuccess then | |
puts "Success" | |
File.open "/tmp/zpl.png", 'wb' do |f| # change file name for PNG images | |
f.write res.body | |
end | |
`qlmanage -p /tmp/zpl.png ` | |
else | |
puts "Error: #{res.body}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An Automator script that will create a png of any selected ZPL