Module: CurlHelper

Included in:
LabClient::Klass, LabClient::LabStruct, LabClient::PaginatedResponse, Typhoeus::Response
Defined in:
lib/labclient/curl.rb

Overview

Generate a curl example

Instance Method Summary collapse

Instance Method Details

#curlObject

rubocop:disable Metrics/AbcSize



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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