Skip to content

Instantly share code, notes, and snippets.

@128keaton
Created January 9, 2018 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 128keaton/c617e2e649540cf9c0ad3b9cc105fdef to your computer and use it in GitHub Desktop.
Save 128keaton/c617e2e649540cf9c0ad3b9cc105fdef to your computer and use it in GitHub Desktop.
Talk to a Packsize printer with Ruby <3
#!/usr/bin/env ruby
# encoding: utf-8
require "rubygems"
require "bunny"
require "json"
def buildHash(width, height, length, orderNumber = "Mambo Test Print #9")
xValues = {:X1 => 2.1}
degreeZero = {:Allowed => 1}
allowedRotations = {:Degree0 => degreeZero}
data = {}
data[:Custom] = true
data[:Length] = length.to_i
data[:Width] = width.to_i
data[:Height] = height.to_i
data[:Quantity] = 1
data[:CorrugateQuality] = 1
data[:DesignId] = 2000100
data[:AllowedRotations] = allowedRotations
data[:MachineId] = "blahblah"
data[:CustomerUniqueId] = orderNumber
data[:XValues] = xValues
data[:UserName] = "api"
message = {}
message[:MessageType] = "CreateCustomCarton"
message[:Data] = data
message[:MachineGroupName] = "MG1"
message[:MachineGroupId] = "blahblah"
message[:UserName] = "api"
return message.to_json
end
def buildConnection()
bunnyConnection = Bunny.new(:host => "10.2.0.232", :user=>"username", :pass=>"password")
bunnyConnection.start
channel = bunnyConnection.create_channel
return channel.direct("PackNet-Direct", :durable => true)
end
def sendBox(box)
connection = buildConnection()
puts box
connection.publish(box, :routing_key => "Server", :content_type => "application/json", :persistent => true)
puts "Done"
end
def prompt(*args)
print(*args)
gets.gsub(/\n/,"")
end
width = prompt "Width: "
height = prompt "Height: "
length = prompt "Length: "
orderNumber = prompt "Order #: "
sendBox(buildHash(width, height, length, orderNumber))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment