Module: Autility::Command

Defined in:
lib/autility/command.rb

Overview

Public: A Command is a system cURL command builder.

Examples

command = Command.build(url, params, cookie, "foo.pdf")
# => "curl --data ..."

Class Method Summary collapse

Class Method Details

.build(url, method, cookie, params, path) ⇒ Object

Public: Builds a command to fetch and save a remote document via cURL.

url - The String url where we can get the document method - the String HTTP method to use. cookie - the session Cookie needed to access the url params - The Array of POST params needed to fetch it path - the String path to save the document to.

Returns the String command ready to execute.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/autility/command.rb', line 19

def build(url, method, cookie, params, path)
  out = "curl"

  if method == :post
    out = "curl --data \""

    out << params.to_a.map do |name, value|
      "#{name}=#{value}"
    end.join("&")

    out << "\""
  end

  out << " #{cookie.to_command}" if cookie
  out << " \"#{url}\""
  out << " -o "
  out << path
  out
end