class RspecApiDocumentation::Curl
Attributes
host[RW]
Public Instance Methods
delete()
click to toggle source
# File lib/rspec_api_documentation/curl.rb, line 30 def delete "curl \"#{url}\" #{post_data} -X DELETE #{headers}" end
get()
click to toggle source
# File lib/rspec_api_documentation/curl.rb, line 18 def get "curl -g \"#{url}#{get_data}\" -X GET #{headers}" end
get_data()
click to toggle source
# File lib/rspec_api_documentation/curl.rb, line 52 def get_data "?#{data}" unless data.blank? end
head()
click to toggle source
# File lib/rspec_api_documentation/curl.rb, line 22 def head "curl \"#{url}#{get_data}\" -X HEAD #{headers}" end
headers()
click to toggle source
Calls superclass method
# File lib/rspec_api_documentation/curl.rb, line 42 def headers filter_headers(super).map do |k, v| if k =~ /authorization/i && v =~ /^Basic/ "\\\n\t-u #{format_auth_header(v)}" else "\\\n\t-H \"#{format_full_header(k, v)}\"" end end.join(" ") end
output(config_host, config_headers_to_filer = nil)
click to toggle source
# File lib/rspec_api_documentation/curl.rb, line 8 def output(config_host, config_headers_to_filer = nil) self.host = config_host @config_headers_to_filer = Array(config_headers_to_filer) send(method.downcase) end
patch()
click to toggle source
# File lib/rspec_api_documentation/curl.rb, line 34 def patch "curl \"#{url}\" #{post_data} -X PATCH #{headers}" end
post()
click to toggle source
# File lib/rspec_api_documentation/curl.rb, line 14 def post "curl \"#{url}\" #{post_data} -X POST #{headers}" end
post_data()
click to toggle source
# File lib/rspec_api_documentation/curl.rb, line 56 def post_data escaped_data = data.to_s.gsub("'", "\\u0027") "-d '#{escaped_data}'" end
put()
click to toggle source
# File lib/rspec_api_documentation/curl.rb, line 26 def put "curl \"#{url}\" #{post_data} -X PUT #{headers}" end
url()
click to toggle source
# File lib/rspec_api_documentation/curl.rb, line 38 def url "#{host}#{path}" end
Private Instance Methods
filter_headers(headers)
click to toggle source
# File lib/rspec_api_documentation/curl.rb, line 81 def filter_headers(headers) if !@config_headers_to_filer.empty? headers.reject do |header| @config_headers_to_filer.map(&:downcase).include?(format_header(header).downcase) end else headers end end
format_auth_header(value)
click to toggle source
# File lib/rspec_api_documentation/curl.rb, line 63 def format_auth_header(value) ::Base64.decode64(value.split(' ', 2).last || '') end
format_full_header(header, value)
click to toggle source
# File lib/rspec_api_documentation/curl.rb, line 71 def format_full_header(header, value) formatted_value = if value.is_a?(Numeric) value else value ? value.gsub(/"/, "\\\"") : '' end "#{format_header(header)}: #{formatted_value}" end
format_header(header)
click to toggle source
# File lib/rspec_api_documentation/curl.rb, line 67 def format_header(header) header.gsub(/^HTTP_/, '').titleize.split.join("-") end