mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
restclient shell accepts get/put/post/delete for curl-style access
This commit is contained in:
parent
74e81c12b1
commit
a6de091a94
2 changed files with 25 additions and 2 deletions
6
README
6
README
|
@ -65,6 +65,12 @@ Then invoke:
|
|||
|
||||
$ restclient private_site
|
||||
|
||||
Use as a one-off, curl-style:
|
||||
|
||||
$ restclient get http://example.com/resource > output_body
|
||||
|
||||
$ restclient put http://example.com/resource < input_body
|
||||
|
||||
== Logging
|
||||
|
||||
Write calls to a log filename (can also be "stdout" or "stderr"):
|
||||
|
|
|
@ -7,10 +7,18 @@ require "yaml"
|
|||
|
||||
def usage(why = nil)
|
||||
puts "failed for reason: #{why}" if why
|
||||
puts "usage: restclient url|name [username] [password]"
|
||||
puts "usage: restclient [get|put|post|delete] url|name [username] [password]"
|
||||
puts " The verb is optional, if you leave it off you'll get an interactive shell."
|
||||
puts " put and post both take the input body on stdin."
|
||||
exit(1)
|
||||
end
|
||||
|
||||
if %w(get put post delete).include? ARGV.first
|
||||
@verb = ARGV.shift
|
||||
else
|
||||
@verb = nil
|
||||
end
|
||||
|
||||
@url = ARGV.shift || 'http://localhost:4567'
|
||||
|
||||
config = YAML.load(File.read(ENV['HOME'] + "/.restclient")) rescue {}
|
||||
|
@ -22,7 +30,7 @@ else
|
|||
end
|
||||
|
||||
usage("invalid url '#{@url}") unless @url =~ /^https?/
|
||||
usage("to few args") unless ARGV.size < 3
|
||||
usage("too few args") unless ARGV.size < 3
|
||||
|
||||
def r
|
||||
@r ||= RestClient::Resource.new(@url, @username, @password)
|
||||
|
@ -30,6 +38,15 @@ end
|
|||
|
||||
r # force rc to load
|
||||
|
||||
if @verb
|
||||
if %w(put post).include? @verb
|
||||
puts r.send(@verb, STDIN.read)
|
||||
else
|
||||
puts r.send(@verb)
|
||||
end
|
||||
exit 0
|
||||
end
|
||||
|
||||
%w(get post put delete).each do |m|
|
||||
eval <<-end_eval
|
||||
def #{m}(path, *args, &b)
|
||||
|
|
Loading…
Reference in a new issue