mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
use space instead of tab
This commit is contained in:
parent
41e254e6c0
commit
9e05961278
1 changed files with 38 additions and 38 deletions
|
@ -6,17 +6,17 @@ require 'restclient'
|
|||
require "yaml"
|
||||
|
||||
def usage(why = nil)
|
||||
puts "failed for reason: #{why}" if why
|
||||
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)
|
||||
puts "failed for reason: #{why}" if why
|
||||
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
|
||||
if %w( get put post delete ).include? ARGV.first
|
||||
@verb = ARGV.shift
|
||||
else
|
||||
@verb = nil
|
||||
@verb = nil
|
||||
end
|
||||
|
||||
@url = ARGV.shift || 'http://localhost:4567'
|
||||
|
@ -24,61 +24,61 @@ end
|
|||
config = YAML.load(File.read(ENV['HOME'] + "/.restclient")) rescue {}
|
||||
|
||||
@url, @username, @password = if c = config[@url]
|
||||
[c['url'], c['username'], c['password']]
|
||||
[c['url'], c['username'], c['password']]
|
||||
else
|
||||
[@url, *ARGV]
|
||||
[@url, * ARGV]
|
||||
end
|
||||
|
||||
usage("invalid url '#{@url}") unless @url =~ /^https?/
|
||||
usage("too few args") unless ARGV.size < 3
|
||||
|
||||
def r
|
||||
@r ||= RestClient::Resource.new(@url, @username, @password)
|
||||
@r ||= RestClient::Resource.new(@url, @username, @password)
|
||||
end
|
||||
|
||||
r # force rc to load
|
||||
|
||||
if @verb
|
||||
begin
|
||||
if %w(put post).include? @verb
|
||||
puts r.send(@verb, STDIN.read)
|
||||
else
|
||||
puts r.send(@verb)
|
||||
end
|
||||
exit 0
|
||||
rescue RestClient::Exception => e
|
||||
puts e.response.body if e.respond_to? :response
|
||||
raise
|
||||
end
|
||||
begin
|
||||
if %w( put post ).include? @verb
|
||||
puts r.send(@verb, STDIN.read)
|
||||
else
|
||||
puts r.send(@verb)
|
||||
end
|
||||
exit 0
|
||||
rescue RestClient::Exception => e
|
||||
puts e.response.body if e.respond_to? :response
|
||||
raise
|
||||
end
|
||||
end
|
||||
|
||||
%w(get post put delete).each do |m|
|
||||
eval <<-end_eval
|
||||
def #{m}(path, *args, &b)
|
||||
r[path].#{m}(*args, &b)
|
||||
%w( get post put delete ).each do |m|
|
||||
eval <<-end_eval
|
||||
def #{m} (path, *args, &b)
|
||||
r[path]. #{m} (*args, &b)
|
||||
end
|
||||
end_eval
|
||||
end_eval
|
||||
end
|
||||
|
||||
def method_missing(s, *args, &b)
|
||||
super unless r.respond_to?(s)
|
||||
begin
|
||||
r.send(s, *args, &b)
|
||||
rescue RestClient::RequestFailed => e
|
||||
print STDERR, e.response.body
|
||||
raise e
|
||||
end
|
||||
def method_missing(s, * args, & b)
|
||||
super unless r.respond_to?(s)
|
||||
begin
|
||||
r.send(s, * args, & b)
|
||||
rescue RestClient::RequestFailed => e
|
||||
print STDERR, e.response.body
|
||||
raise e
|
||||
end
|
||||
end
|
||||
|
||||
require 'irb'
|
||||
require 'irb/completion'
|
||||
|
||||
if File.exists? ".irbrc"
|
||||
ENV['IRBRC'] = ".irbrc"
|
||||
ENV['IRBRC'] = ".irbrc"
|
||||
end
|
||||
|
||||
if File.exists?( File.expand_path(rcfile = "~/.restclientrc") )
|
||||
load(rcfile)
|
||||
if File.exists?(File.expand_path(rcfile = "~/.restclientrc"))
|
||||
load(rcfile)
|
||||
end
|
||||
|
||||
ARGV.clear
|
||||
|
|
Loading…
Reference in a new issue