diff --git a/README b/README index 09b7718..1e6b809 100644 --- a/README +++ b/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 diff --git a/Rakefile b/Rakefile index b5f1fa8..ef70004 100644 --- a/Rakefile +++ b/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 diff --git a/bin/restclient b/bin/restclient new file mode 100755 index 0000000..94f9910 --- /dev/null +++ b/bin/restclient @@ -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! diff --git a/rest-client.gemspec b/rest-client.gemspec index a8b21a0..08fcb64 100644 --- a/rest-client.gemspec +++ b/rest-client.gemspec @@ -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 \ No newline at end of file