Skip to content

Instantly share code, notes, and snippets.

@shigeya
Created February 26, 2014 08:40
Show Gist options
  • Save shigeya/9225898 to your computer and use it in GitHub Desktop.
Save shigeya/9225898 to your computer and use it in GitHub Desktop.
minimum code for EPCIS repository capture interface
#!/usr/bin/env ruby
require 'nokogiri'
require 'optparse'
require 'net/http'
require 'uri'
opts = {
capture_url: "http://127.0.0.1:3000/epcis/capture",
verbose: false,
timeout: 300,
}
ARGV.options do |o|
o.banner = "#{$0} [options] [type:param]"
o.separator "Options:"
o.on("-C", "--capture_url capture", "Destination URL for capture") {|url| opts[:capture_url] = url }
o.parse!
end
def run_capture(xml, url, timeout)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.read_timeout = timeout
request = Net::HTTP::Post.new(uri.request_uri)
request["Content-Type"] = 'text/xml'
request.body = xml
response = nil
response = http.request(request)
puts response.code
end
event_xml = ARGF.read
if event_xml.size != 0
run_capture(event_xml, opts[:capture_url], opts[:timeout])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment