Sha256: b77df2b7d58bc554cd38339d53c4163f3ce85113b61634b6079143a2ec25b2f2

Contents?: true

Size: 1.12 KB

Versions: 22

Compression:

Stored size: 1.12 KB

Contents

#!/usr/bin/env ruby

$:.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|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, @username, @password)
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!

Version data entries

22 entries across 22 versions & 3 rubygems

Version Path
entp-astrotrain-0.2.0 lib/vendor/rest-client/bin/restclient
entp-astrotrain-0.2.1 lib/vendor/rest-client/bin/restclient
entp-astrotrain-0.3.0 lib/vendor/rest-client/bin/restclient
entp-astrotrain-0.3.1 lib/vendor/rest-client/bin/restclient
entp-astrotrain-0.4.0 lib/vendor/rest-client/bin/restclient
entp-astrotrain-0.4.1 lib/vendor/rest-client/bin/restclient
entp-astrotrain-0.4.2 lib/vendor/rest-client/bin/restclient
entp-astrotrain-0.4.3 lib/vendor/rest-client/bin/restclient
astrotrain-0.5.4 lib/vendor/rest-client/bin/restclient
astrotrain-0.5.3 lib/vendor/rest-client/bin/restclient
astrotrain-0.5.2 lib/vendor/rest-client/bin/restclient
astrotrain-0.5.1 lib/vendor/rest-client/bin/restclient
astrotrain-0.5.0 lib/vendor/rest-client/bin/restclient
astrotrain-0.4.5 lib/vendor/rest-client/bin/restclient
astrotrain-0.4.4 lib/vendor/rest-client/bin/restclient
astrotrain-0.4.3 lib/vendor/rest-client/bin/restclient
astrotrain-0.4.2 lib/vendor/rest-client/bin/restclient
astrotrain-0.4.1 lib/vendor/rest-client/bin/restclient
astrotrain-0.4.0 lib/vendor/rest-client/bin/restclient
astrotrain-0.3.1 lib/vendor/rest-client/bin/restclient