Module: HTTY::CLI::HTTPMethodCommand

Overview

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

Defined Under Namespace

Modules: ClassMethods

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

.included(other_module) ⇒ Object

Extends other_module with ClassMethods.



20
21
22
# File 'lib/htty/cli/http_method_command.rb', line 20

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

Instance Method Details

#performObject

Performs the command.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/htty/cli/http_method_command.rb', line 27

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