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

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, options={}
  options = {:method => "GET", :output => '/dev/null', :params => []}.merge(options)
  progress_meter = Chimps.verbose? ? '' : '-s -S'
  command = "#{curl_program} #{progress_meter} -X #{options[:method]} -o #{options[:output]}"
  command += " #{curl_params(options[:params])}" unless options[: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.

Parameters:

Returns:



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_programObject



8
9
10
# File 'lib/chimps/utils/uses_curl.rb', line 8

def curl_program
  `which curl`.chomp
end