Sha256: 3c7f47f5365c7b34bf1b505b11db6a01c925bbbf1f58e6210e4b379af3a52c82

Contents?: true

Size: 1.31 KB

Versions: 9

Compression:

Stored size: 1.31 KB

Contents

#!/usr/bin/env ruby

# httpclient shell command.
#
# Usage: 1) % httpclient get https://www.google.co.jp/ q=ruby
# Usage: 2) % httpclient
#
# For 1) it issues a GET request to the given URI and shows the wiredump and
# the parsed result.  For 2) it invokes irb shell with the binding that has a
# HTTPClient as 'self'.  You can call HTTPClient instance methods like;
# > get "https://www.google.co.jp/", :q => :ruby
require 'httpclient'

METHODS = ['head', 'get', 'post', 'put', 'patch', 'delete', 'options', 'propfind', 'proppatch', 'trace']
if ARGV.size >= 2 && METHODS.include?(ARGV[0])
  client = HTTPClient.new
  client.debug_dev = STDERR
  $DEBUG = true
  require 'pp'
  pp client.send(*ARGV)
  exit
end

require 'irb'
require 'irb/completion'

class Runner
  def initialize
    @httpclient = HTTPClient.new
  end

  def method_missing(msg, *a, &b)
    debug, $DEBUG = $DEBUG, true
    begin
      @httpclient.send(msg, *a, &b)
    ensure
      $DEBUG = debug
    end
  end

  def run
    IRB.setup(nil)
    ws = IRB::WorkSpace.new(binding)
    irb = IRB::Irb.new(ws)
    IRB.conf[:MAIN_CONTEXT] = irb.context

    trap("SIGINT") do
      irb.signal_handle
    end

    begin
      catch(:IRB_EXIT) do
        irb.eval_input
      end
    ensure
      IRB.irb_at_exit
    end
  end

  def to_s
    'HTTPClient'
  end
end

Runner.new.run

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
glebtv-httpclient-3.3.0 bin/httpclient
glebtv-httpclient-3.2.8 bin/httpclient
glebtv-httpclient-3.2.7 bin/httpclient
glebtv-httpclient-3.2.6 bin/httpclient
glebtv-httpclient-3.2.4 bin/httpclient
glebtv-httpclient-3.2.3 bin/httpclient
glebtv-httpclient-3.2.2 bin/httpclient
glebtv-httpclient-3.2.1 bin/httpclient
glebtv-httpclient-3.2.0 bin/httpclient