Module: HTTY::CLI::HTTPMethodCommand

Includes:
Display
Included in:
Commands::HttpDelete, Commands::HttpGet, Commands::HttpHead, Commands::HttpOptions, Commands::HttpPatch, Commands::HttpPost, Commands::HttpPut, Commands::HttpTrace
Defined in:
lib/htty/cli/http_method_command.rb

Overview

Encapsulates behavior common to all HTTP-method-oriented HTTY::CLI::Command subclasses.

Defined Under Namespace

Modules: ClassMethods

Constant Summary

Constant Summary

Constants included from Display

Display::FORMATS

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Display

#break, #format, #formatted_prompt_for, #indent, #logotype, #normal, #notice, #pluralize, #rescuing_from, #say, #say_goodbye, #say_header, #say_hello, #show_headers, #show_request, #show_response, #strong, #word_wrap, #word_wrap_indented

Class Method Details

+ (Object) included(other_module)

Extends other_module with ClassMethods.



28
29
30
# File 'lib/htty/cli/http_method_command.rb', line 28

def self.included(other_module)
  other_module.extend ClassMethods
end

Instance Method Details

- (Object) perform

Performs the command.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/htty/cli/http_method_command.rb', line 35

def perform
  add_request_if_new do |request|
    unless body? || request.body.to_s.empty?
      puts notice("The body of your #{method.to_s.upcase} request is not " +
                  'being sent')
    end

    begin
      request = request.send("#{method}!", *arguments)
    rescue OpenSSL::SSL::SSLError => e
      puts notice('Type '                                                      +
                  strong(HTTY::CLI::Commands::SslVerificationOff.command_line) +
                  ' to ignore SSL warnings and complete the request')
      raise e
    end

    notify_if_cookies
    notify_if_follow

    request
  end
  show_response session.last_response
  self
end