diff --git a/README b/README index 428987c..f11de08 100644 --- a/README +++ b/README @@ -44,6 +44,24 @@ 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. +You can also create a ~/.restclient file and store named sessions as: + +name: + :url: http://mydomain.com + :username: myusername + :password: supersecret + +anothername: + ... + +The use like: + +mycpu:~ adamwiggins$ restclient anothername +>>r +=> # +>>get '/' +=> Hey! + == Meta Written by Adam Wiggins (adam at heroku dot com) diff --git a/bin/restclient b/bin/restclient index 2cf02e4..565f3e5 100755 --- a/bin/restclient +++ b/bin/restclient @@ -3,19 +3,29 @@ $:.unshift File.dirname(__FILE__) + "/../lib" require 'rest_client' +require "yaml" + def usage(why = nil) puts "failed for reason: #{why}" if why - puts "usage: restclient url [username] [password]" + puts "usage: restclient url|name [username] [password]" exit(1) end @url = ARGV.shift || 'http://localhost:4567' +config = YAML.load(File.read(ENV['HOME'] + "/.restclient")) rescue {} + +@url, @username, @password = if c = config[@url] + [c[:url], c[:username], c[:password]] +else + [@url, *ARGV] +end + usage("invalid url '#{@url}") unless @url =~ /^https?/ usage("to few args") unless ARGV.size < 3 def r - @r ||= RestClient::Resource.new(@url, *ARGV) + @r ||= RestClient::Resource.new(@url, @username, @password) end r # force rc to load