Module: Chimps::Utils::UsesCurl
- Included in:
- Download, Chimps::Upload
- Defined in:
- lib/chimps/utils/uses_curl.rb
Overview
A module which defines methods to interface with curl
via a system call.
Instance Method Summary collapse
- #curl(url, options = {}) ⇒ Object
-
#curl_params(params) ⇒ String
Curl invocations (specifically those that do S3 HTTP POST) are sometimes sensitive about the order of parameters.
- #curl_program ⇒ Object
Instance Method Details
#curl(url, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/chimps/utils/uses_curl.rb', line 24 def curl url, ={} = {:method => "GET", :output => '/dev/null', :params => []}.merge() progress_meter = Chimps.verbose? ? '' : '-s -S' command = "#{curl_program} #{progress_meter} -X #{[:method]} -o #{[:output]}" command += " #{curl_params([:params])}" unless [:params].empty? command += " '#{url}'" Chimps.log.info(command) system(command) end |
#curl_params(params) ⇒ String
Curl invocations (specifically those that do S3 HTTP POST) are sometimes sensitive about the order of parameters. Instead of a Hash we therefore take an Array of pairs here.
18 19 20 21 22 |
# File 'lib/chimps/utils/uses_curl.rb', line 18 def curl_params params params.map do |param, value| "-F #{param}='#{value}'" end.join(' ') end |
#curl_program ⇒ Object
8 9 10 |
# File 'lib/chimps/utils/uses_curl.rb', line 8 def curl_program `which curl`.chomp end |