Class: ResponseMate::Request
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- ResponseMate::Request
- 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
-
#normalize! ⇒ Object
Make sure all defined requests in the manifest have complete information for Connection#fetch.
-
#to_cli_format ⇒ String
Output string suitable for a terminal.
-
#to_hash ⇒ Hash
The Hash representation of the request.
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_format ⇒ String
Returns 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_hash ⇒ Hash
Returns The Hash representation of the request.
30 31 32 |
# File 'lib/response_mate/request.rb', line 30 def to_hash marshal_dump[:request] end |