Created
February 26, 2014 08:40
-
-
Save shigeya/9225898 to your computer and use it in GitHub Desktop.
minimum code for EPCIS repository capture interface
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
#!/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