1
0
Fork 0
mirror of https://github.com/rest-client/rest-client.git synced 2022-11-09 13:49:40 -05:00

Save named settings for restclient in ~/.restclient

~/.restclient spec:

  name:
    :url: http://mydomain.com
    :username: myusername
    :password: supersecret
This commit is contained in:
bmizerany 2008-07-16 16:15:26 -07:00
parent 91881489d5
commit f24d45cb52
2 changed files with 30 additions and 2 deletions

18
README
View file

@ -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
=> #<RestClient::Resource:0x557bac @password="supersecret", @user="myusername", @url="http://mydomain.com">
>>get '/'
=> Hey!
== Meta
Written by Adam Wiggins (adam at heroku dot com)

View file

@ -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