Class: ResponseMate::Request

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/response_mate/request.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#normalize!Object

Make sure all defined requests in the manifest have complete information for Connection#fetch



8
9
10
11
12
13
14
15
16
17
18
19
# 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_formatString

Returns Output string suitable for a terminal.

Returns:

  • (String)

    Output string suitable for a terminal



22
23
24
25
26
27
# 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_hashHash

Returns The Hash representation of the request.

Returns:

  • (Hash)

    The Hash representation of the request



30
31
32
# File 'lib/response_mate/request.rb', line 30

def to_hash
  marshal_dump[:request]
end