#! /usr/local/bin/ruby

## Perl module sample
## 1998 by yoshidam
##

require 'perl'

## create Perl object
perl = Perl.new("-MLWP::UserAgent",
                "-MHTTP::Request",
                "-e", "0")

## create LWP::UserAgent obejct
ua = perl.send("LWP::UserAgent", "new");

## check proxy
if !ENV['http_proxy'].nil?
  ua.proxy("http", ENV['http_proxy'])
end

## create HTTP::Request object
request = perl.send("HTTP::Request", "new", "GET", ARGV[0])

## issue the request
r = ua.request(request)
if !r.is_success || r.code.to_s != '200'
  raise "#{r.code} #{r.message}"
end

## result
print r.content
