class Workarea::Api::Curl
This class stolen from Rspec Api
Documentation
Attributes
host[RW]
Public Instance Methods
delete()
click to toggle source
# File lib/workarea/api/curl.rb, line 29 def delete "curl \"#{url}\" #{post_data} -X DELETE #{headers}" end
get()
click to toggle source
# File lib/workarea/api/curl.rb, line 17 def get "curl -g \"#{url}#{get_data}\" -X GET #{headers}" end
get_data()
click to toggle source
# File lib/workarea/api/curl.rb, line 51 def get_data "?#{data}" unless data.blank? end
head()
click to toggle source
# File lib/workarea/api/curl.rb, line 21 def head "curl \"#{url}#{get_data}\" -X HEAD #{headers}" end
headers()
click to toggle source
Calls superclass method
# File lib/workarea/api/curl.rb, line 41 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/workarea/api/curl.rb, line 7 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/workarea/api/curl.rb, line 33 def patch "curl \"#{url}\" #{post_data} -X PATCH #{headers}" end
post()
click to toggle source
# File lib/workarea/api/curl.rb, line 13 def post "curl \"#{url}\" #{post_data} -X POST #{headers}" end
post_data()
click to toggle source
# File lib/workarea/api/curl.rb, line 55 def post_data escaped_data = data.to_s.gsub("'", '\\u0027') "-d '#{escaped_data}'" end
put()
click to toggle source
# File lib/workarea/api/curl.rb, line 25 def put "curl \"#{url}\" #{post_data} -X PUT #{headers}" end
url()
click to toggle source
# File lib/workarea/api/curl.rb, line 37 def url "#{host}#{path}" end
Private Instance Methods
filter_headers(headers)
click to toggle source
# File lib/workarea/api/curl.rb, line 75 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/workarea/api/curl.rb, line 62 def format_auth_header(value) ::Base64.decode64(value.split(' ', 2).last || '') end
format_full_header(header, value)
click to toggle source
# File lib/workarea/api/curl.rb, line 70 def format_full_header(header, value) formatted_value = value ? value.gsub(/"/, '\\"') : '' "#{format_header(header)}: #{formatted_value}" end
format_header(header)
click to toggle source
# File lib/workarea/api/curl.rb, line 66 def format_header(header) header.gsub(/^HTTP_/, '').titleize.split.join('-') end