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
# File 'lib/response_mate/request.rb', line 8

def normalize!
  unless ResponseMate::HTTP_METHODS.include? request[:verb]
    request[:verb] = '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


21
22
23
24
25
# File 'lib/response_mate/request.rb', line 21

def to_cli_format
  out = "[#{key}] #{request[:verb]}".cyan_on_black.bold << " #{request[:url]}"
  out << "\tparams #{request[:params]}" if request[:params].present?
  out
end

#to_hashHash


28
29
30
# File 'lib/response_mate/request.rb', line 28

def to_hash
  marshal_dump[:request]
end