mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
Easy to use shell!
This commit is contained in:
parent
3f871d3340
commit
7e3df03d65
4 changed files with 62 additions and 5 deletions
8
README
8
README
|
@ -39,10 +39,10 @@ See RestClient::Resource docs for details.
|
|||
|
||||
== Shell
|
||||
|
||||
Require rest_client from within irb to access RestClient interactively, like
|
||||
using curl at the command line. Better yet, require gem from within your
|
||||
~/.rush/env.rb and have instant access to it from within your rush
|
||||
(http://rush.heroku.com) sessions.
|
||||
Run:
|
||||
restclient resource_url [username] [password]
|
||||
|
||||
or require the gem from within your ~/.rush/env.rb and have instant access to it from within your rush (http://rush.heroku.com) sessions.
|
||||
|
||||
== Meta
|
||||
|
||||
|
|
1
Rakefile
1
Rakefile
|
@ -48,6 +48,7 @@ spec = Gem::Specification.new do |s|
|
|||
s.has_rdoc = true
|
||||
|
||||
s.files = %w(Rakefile) + Dir.glob("{lib,spec}/**/*")
|
||||
s.executables = ['restclient']
|
||||
|
||||
s.require_path = "lib"
|
||||
end
|
||||
|
|
54
bin/restclient
Executable file
54
bin/restclient
Executable file
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
$:.unshift File.dirname(__FILE__) + "/../lib"
|
||||
require 'rest_client'
|
||||
|
||||
def usage
|
||||
puts "usage: restclient url [username] [password]"
|
||||
exit(1)
|
||||
end
|
||||
|
||||
@url = ARGV.first || 'http://localhost:4567'
|
||||
|
||||
usage unless @url =~ /^https?/
|
||||
usage unless ARGV.size < 3
|
||||
|
||||
def r
|
||||
@r ||= RestClient::Resource.new(*[@url, ARGV])
|
||||
end
|
||||
|
||||
r # force rc to load
|
||||
|
||||
%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
|
||||
|
||||
def method_missing(s, *args, &b)
|
||||
super unless r.respond_to?(s)
|
||||
begin
|
||||
r.send(s, *args, &b)
|
||||
rescue RestClient::RequestFailed => e
|
||||
puts e.response.body
|
||||
raise e
|
||||
end
|
||||
end
|
||||
|
||||
require 'irb'
|
||||
require 'irb/completion'
|
||||
|
||||
if File.exists? ".irbrc"
|
||||
ENV['IRBRC'] = ".irbrc"
|
||||
end
|
||||
|
||||
if File.exists?(rcfile = "~/.restclientrc")
|
||||
load(rcfile)
|
||||
end
|
||||
|
||||
ARGV.clear
|
||||
|
||||
IRB.start
|
||||
exit!
|
|
@ -11,6 +11,8 @@ Gem::Specification.new do |s|
|
|||
s.platform = Gem::Platform::RUBY
|
||||
s.files = %w(Rakefile README rest-client.gemspec
|
||||
lib/request_errors.rb lib/resource.rb lib/rest_client.rb
|
||||
spec/base.rb spec/request_errors_spec.rb spec/resource_spec.rb spec/rest_client_spec.rb)
|
||||
spec/base.rb spec/request_errors_spec.rb spec/resource_spec.rb spec/rest_client_spec.rb
|
||||
bin/restclient)
|
||||
s.executables = ['restclient']
|
||||
s.require_path = "lib"
|
||||
end
|
Loading…
Reference in a new issue