Class: WebFixtures::Request
- Inherits:
-
Object
- Object
- WebFixtures::Request
- Defined in:
- lib/web_fixtures/request.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
Returns the value of attribute input.
-
#method ⇒ Object
Returns the value of attribute method.
-
#options ⇒ Object
Returns the value of attribute options.
-
#output ⇒ Object
Returns the value of attribute output.
-
#password ⇒ Object
Returns the value of attribute password.
-
#uri ⇒ Object
Returns the value of attribute uri.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #collect_password ⇒ Object
- #collect_username ⇒ Object
- #curl_command ⇒ Object
- #filename ⇒ Object
-
#initialize(method, uri, options = {}, input = STDIN, output = STDOUT) ⇒ Request
constructor
A new instance of Request.
- #output_file ⇒ Object
- #storage_path ⇒ Object
- #store! ⇒ Object
- #uri_components ⇒ Object
Constructor Details
#initialize(method, uri, options = {}, input = STDIN, output = STDOUT) ⇒ Request
Returns a new instance of Request.
13 14 15 16 17 18 19 20 |
# File 'lib/web_fixtures/request.rb', line 13 def initialize(method, uri, = {}, input = STDIN, output = STDOUT) @method = method @uri = uri @options = @input = input @output = output end |
Instance Attribute Details
#input ⇒ Object
Returns the value of attribute input.
8 9 10 |
# File 'lib/web_fixtures/request.rb', line 8 def input @input end |
#method ⇒ Object
Returns the value of attribute method.
4 5 6 |
# File 'lib/web_fixtures/request.rb', line 4 def method @method end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/web_fixtures/request.rb', line 6 def @options end |
#output ⇒ Object
Returns the value of attribute output.
9 10 11 |
# File 'lib/web_fixtures/request.rb', line 9 def output @output end |
#password ⇒ Object
Returns the value of attribute password.
11 12 13 |
# File 'lib/web_fixtures/request.rb', line 11 def password @password end |
#uri ⇒ Object
Returns the value of attribute uri.
5 6 7 |
# File 'lib/web_fixtures/request.rb', line 5 def uri @uri end |
#username ⇒ Object
Returns the value of attribute username.
11 12 13 |
# File 'lib/web_fixtures/request.rb', line 11 def username @username end |
Instance Method Details
#collect_password ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/web_fixtures/request.rb', line 64 def collect_password return password if password return nil unless [:authenticate] output.print "Password: " @password = input.gets.chomp end |
#collect_username ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/web_fixtures/request.rb', line 56 def collect_username return username if username return nil unless [:authenticate] output.print "Username: " @username = input.gets.chomp end |
#curl_command ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/web_fixtures/request.rb', line 26 def curl_command command = "curl -s" command << " -i" if [:include_headers] command << " -u #{collect_username}:#{collect_password}" if [:authenticate] command << " -X #{method.to_s.upcase}" if method != :get command << " -o \"#{output_file}\"" command << " \"#{uri}\"" command end |
#filename ⇒ Object
47 48 49 50 |
# File 'lib/web_fixtures/request.rb', line 47 def filename title = uri_components[3..-1].join("_") (title.empty? ? "root" : title) + ".txt" end |
#output_file ⇒ Object
52 53 54 |
# File 'lib/web_fixtures/request.rb', line 52 def output_file File.join(storage_path, filename) end |
#storage_path ⇒ Object
40 41 42 43 44 45 |
# File 'lib/web_fixtures/request.rb', line 40 def storage_path root = [:root_path] || "." directory = uri_components[2] File.join(root, directory) end |
#store! ⇒ Object
22 23 24 |
# File 'lib/web_fixtures/request.rb', line 22 def store! `mkdir -p \"#{storage_path}\" && #{curl_command}` end |
#uri_components ⇒ Object
36 37 38 |
# File 'lib/web_fixtures/request.rb', line 36 def uri_components @uri_components ||= uri.split('/') end |