lib/gooddata/connection.rb in gooddata-0.6.0.pre5 vs lib/gooddata/connection.rb in gooddata-0.6.0.pre6

- old
+ new

@@ -30,14 +30,13 @@ class Connection DEFAULT_URL = 'https://secure.gooddata.com' LOGIN_PATH = '/gdc/account/login' TOKEN_PATH = '/gdc/account/token' - STAGE_PATH = '/uploads/' attr_reader(:auth_token, :url) - attr_accessor :status + attr_accessor :status, :options # Options: # * :tries - Number of retries to perform. Defaults to 1. # * :on - The Exception on which a retry will be performed. Defaults to Exception, which retries on any Exception. @@ -194,18 +193,19 @@ end # Uploads a file to GoodData server # /uploads/ resources are special in that they use a different # host and a basic authentication. - def upload(file, dir = nil, options={}) + def upload(file, options={}) ensure_connection - # We should have followed a link. If it was correct. - stage_url = @options[:webdav_server] || @url.sub(/\./, '-di.') + dir = options[:directory] || '' + staging_uri = options[:staging_url].to_s + url = dir.empty? ? staging_uri : URI.join(staging_uri, "#{dir}/").to_s + # Make a directory, if needed - if dir then - url = stage_url + STAGE_PATH + dir + '/' + unless dir.empty? then method = :get GoodData.logger.debug "#{method}: #{url}" begin # first check if it does exits RestClient::Request.execute({ @@ -228,29 +228,29 @@ :user_agent => GoodData.gem_version_string }}.merge(cookies) ) end end - else - dir = "." end payload = options[:stream] ? "file" : File.read(file) filename = options[:filename] || options[:stream] ? "randome-filename.txt" : File.basename(file) # Upload the file + puts "uploading the file #{URI.join(url, filename).to_s}" + req = RestClient::Request.new({ :method => :put, - :url => stage_url + STAGE_PATH + dir + '/' + filename, + :url => URI.join(url, filename).to_s, :timeout => @options[:timeout], :headers => { :user_agent => GoodData.gem_version_string, }, :payload => payload, :raw_response => true }.merge(cookies)) resp = req.execute - pp e.inspect + true end def download(what, where) stage_url = @options[:webdav_server] || @url.sub(/\./, '-di.') url = stage_url + STAGE_PATH + what