module CurlHelper

Generate a curl example

Public Instance Methods

curl() click to toggle source

rubocop:disable Metrics/AbcSize

# File lib/labclient/curl.rb, line 4
def curl
  output = 'curl '
  output += '-k ' unless client.settings[:ssl_verify]

  method = response.request.options[:method]
  output += "-X #{method.upcase} "

  # output = "-H "
  response.request.options[:headers].each do |key, value|
    # Hide JSON if GET
    next if key == 'User-Agent' # Don't bother with agent
    next if key == 'Expect' # Typheous Specific
    next if key == 'Content-Type' && method == :get

    output += "-H \"#{key}: #{value}\" "
  end

  output += "-d '#{response.request.options[:body]}' " if method != :get

  output += "\"#{response.request.url}\""
  puts output
end