class ResponseMate::Request

Responsible for keeping all logic related to a request defined in the requests manifest

Public Instance Methods

normalize!() click to toggle source

Make sure all defined requests in the manifest have complete information for {ResponseMate::Connection#fetch}

# File lib/response_mate/request.rb, line 8
def normalize! # rubocop:disable Metrics/AbcSize
  request[:verb] = begin
    (ResponseMate::HTTP_METHODS & [request.fetch(:verb, 'GET').downcase.to_sym]).first ||
    'GET'
  end

  if request[:url] !~ /{{.*?}}/  # Avoid encoding unprocessed mustache tags
    request[:url] = URI.encode(adjust_scheme(request[:url], request[:scheme]))
  end

  self
end
to_cli_format() click to toggle source

@return [String] Output string suitable for a terminal

# File lib/response_mate/request.rb, line 22
def to_cli_format # rubocop:disable Metrics/AbcSize
  out = ["[#{key.yellow}] ", request[:verb].to_s.upcase.colorize(:cyan).on_black.bold,
         " #{request[:url]}"].join
  out << "\tparams #{request[:params]}" if request[:params].present?
  out
end
to_hash() click to toggle source

@return [Hash] The Hash representation of the request

# File lib/response_mate/request.rb, line 30
def to_hash
  marshal_dump[:request]
end

Private Instance Methods

adjust_scheme(uri, scheme) click to toggle source
# File lib/response_mate/request.rb, line 36
def adjust_scheme(uri, scheme)
  scheme = %w[http https].include?(scheme) ? scheme : 'http'

  if uri !~ /\Ahttp(s)?/
    "#{scheme}://#{uri}"
  else
    uri
  end
end