Class: RemoteTable::Request
- Inherits:
-
Object
- Object
- RemoteTable::Request
- Defined in:
- lib/remote_table/request.rb
Instance Attribute Summary collapse
-
#form_data ⇒ Object
Returns the value of attribute form_data.
-
#parsed_url ⇒ Object
Returns the value of attribute parsed_url.
-
#password ⇒ Object
Returns the value of attribute password.
-
#post_data ⇒ Object
Returns the value of attribute post_data.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #download ⇒ Object
-
#initialize(bus) ⇒ Request
constructor
TODO: support HTTP basic auth.
Constructor Details
#initialize(bus) ⇒ Request
TODO: support HTTP basic auth
7 8 9 10 11 12 13 14 |
# File 'lib/remote_table/request.rb', line 7 def initialize(bus) raise(ArgumentError, "RemoteTable needs :url option") unless bus[:url].present? @parsed_url = URI.parse bus[:url] if @parsed_url.host == 'spreadsheets.google.com' and (bus[:format].blank? or bus[:format].to_s == 'csv') @parsed_url.query = 'output=csv&' + @parsed_url.query.sub(/\&*output=.*(\&|\z)/, '') end @form_data = bus[:form_data] end |
Instance Attribute Details
#form_data ⇒ Object
Returns the value of attribute form_data.
4 5 6 |
# File 'lib/remote_table/request.rb', line 4 def form_data @form_data end |
#parsed_url ⇒ Object
Returns the value of attribute parsed_url.
3 4 5 |
# File 'lib/remote_table/request.rb', line 3 def parsed_url @parsed_url end |
#password ⇒ Object
Returns the value of attribute password.
3 4 5 |
# File 'lib/remote_table/request.rb', line 3 def password @password end |
#post_data ⇒ Object
Returns the value of attribute post_data.
3 4 5 |
# File 'lib/remote_table/request.rb', line 3 def post_data @post_data end |
#username ⇒ Object
Returns the value of attribute username.
3 4 5 |
# File 'lib/remote_table/request.rb', line 3 def username @username end |
Instance Method Details
#download ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/remote_table/request.rb', line 16 def download path = ::File.join staging_dir_path, 'REMOTE_TABLE_PACKAGE' if parsed_url.scheme == 'file' parsed_url.path else cmd = %{ curl \ --silent \ --header "Expect: " \ --location \ #{"--data \"#{form_data}\"" if form_data.present?} \ "#{parsed_url}" \ --output "#{path}" } `#{cmd}` path end end |