9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/rest_client.rb', line 9
def main
valid_methods = ['GET', 'PUT', 'POST', 'DELETE']
@opts = Trollop::options do
version "UDP RestClient (c) 2016 @reednj"
banner "Usage: udp-rest [options] <url>"
opt :method, "HTTP Method (GET, POST etc)", :type => :string, :default => 'GET'
opt :headers, "Show the response headers", :default => false
end
Trollop::educate if ARGV.empty?
url = ARGV.last
url = "uhttp://" + url unless url.start_with? 'uhttp://'
begin
if !valid_methods.include? @opts[:method].upcase
raise "Invalid REST method '#{@opts[:method]}'"
end
r = UDPRest::Client.uhttp(@opts[:method], url)
print_response(r)
rescue => e
puts e
end
end
|