Sha256: 6ee72b8e5ca45afa0ca7e391d0b491188b9a4f4906f4e51f3699b538f7338558

Contents?: true

Size: 1.82 KB

Versions: 52

Compression:

Stored size: 1.82 KB

Contents

#!/usr/bin/env ruby

$LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"

require 'rubygems'
require 'restclient'
require 'yaml'

def usage(why = nil)
  puts "failed for reason: #{why}" if why
  puts "usage: restclient [get|put|post|delete] url|name [username] [password]"
  puts "  The verb is optional, if you leave it off you'll get an interactive shell."
  puts "  put and post both take the input body on stdin."
  exit(1)
end

POSSIBLE_VERBS = ['get', 'put', 'post', 'delete']

if POSSIBLE_VERBS.include? ARGV.first
  @verb = ARGV.shift
else
  @verb = nil
end

@url = ARGV.shift || 'http://localhost:4567'

config = YAML.load(File.read(ENV['HOME'] + "/.restclient")) rescue {}

if (c = config[@url])
  @url, @username, @password = [c['url'], c['username'], c['password']]
else
  @url, @username, @password = [@url, * ARGV]
end

usage("invalid url '#{@url}") unless @url =~ /^https?/
usage("too few args") unless ARGV.size < 3

def r
  @r ||= RestClient::Resource.new(@url, @username, @password)
end

r # force rc to load

if @verb
  begin
    if %w( put post ).include? @verb
      puts r.send(@verb, STDIN.read)
    else
      puts r.send(@verb)
    end
    exit 0
  rescue RestClient::Exception => e
    puts e.response.body if e.respond_to?(:response) && e.response
    raise
  end
end

POSSIBLE_VERBS.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)
  if POSSIBLE_VERBS.include? s
    begin
      r.send(s, *args, & b)
    rescue RestClient::RequestFailed => e
      print STDERR, e.response.body
      raise e
    end
  else
    super
  end
end

require 'irb'
require 'irb/completion'

if File.exist? ".irbrc"
  ENV['IRBRC'] = ".irbrc"
end

rcfile = File.expand_path("~/.restclientrc")
if File.exist?(rcfile)
  load(rcfile)
end

ARGV.clear

IRB.start
exit!

Version data entries

52 entries across 50 versions & 8 rubygems

Version Path
mrcooper-logstash-output-azuresearch-0.2.2 vendor/jruby/2.5.0/gems/rest-client-1.8.0/bin/restclient
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/vendor/bundle/gems/rest-client-1.8.0/bin/restclient
tdiary-5.0.7 vendor/bundle/gems/rest-client-1.8.0/bin/restclient
tdiary-5.0.6 vendor/bundle/gems/rest-client-1.8.0/bin/restclient
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/rest-client-1.8.0/bin/restclient
tdiary-5.0.5 vendor/bundle/gems/rest-client-1.8.0/bin/restclient
tdiary-5.0.4 vendor/bundle/gems/rest-client-1.8.0/bin/restclient
tdiary-5.0.2 vendor/bundle/gems/rest-client-1.8.0/bin/restclient
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/gems/rest-client-1.8.0/bin/restclient
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/gems/rest-client-1.8.0/bin/restclient
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/gems/rest-client-1.8.0/bin/restclient
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/gems/rest-client-1.8.0/bin/restclient
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rest-client-1.8.0/bin/restclient
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rest-client-1.8.0/bin/restclient
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rest-client-1.8.0/bin/restclient
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rest-client-1.8.0/bin/restclient
tdiary-5.0.1 vendor/bundle/gems/rest-client-1.8.0/bin/restclient
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rest-client-1.8.0/bin/restclient
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/rest-client-1.8.0/bin/restclient
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/rest-client-1.8.0/bin/restclient