lib/gooddata/client.rb in gooddata-0.6.0.pre10 vs lib/gooddata/client.rb in gooddata-0.6.0.pre11

- old
+ new

@@ -1,8 +1,8 @@ -require 'gooddata/version' -require 'gooddata/connection' -require 'gooddata/helpers' +require File.join(File.dirname(__FILE__), 'version') +require File.join(File.dirname(__FILE__), 'connection') +require File.join(File.dirname(__FILE__), 'helpers') # fastercsv is built in Ruby 1.9 if RUBY_VERSION < "1.9" require 'fastercsv' else @@ -11,11 +11,11 @@ end # Initializes required dynamically loaded classes def init_gd_module() # Metadata packages, such as report.rb, require this to be loaded first - require File.dirname(__FILE__) + '/models/metadata.rb' + require File.join(File.dirname(__FILE__), '/models/metadata.rb') # Load models from models folder Dir[File.dirname(__FILE__) + '/models/*.rb'].each { |file| require file } # Load collections @@ -78,39 +78,37 @@ class << self include Threaded RELEASE_INFO_PATH = '/gdc/releaseInfo' - # Version - def version - VERSION - end - - # Identifier of gem version - # @return Formatted gem version - def gem_version_string() - "gooddata-gem/#{version}" - end - # Connect to the GoodData API # # @param options # @param second_options # @param third_options # - # Goodd def connect(options=nil, second_options=nil, third_options={}) if options.is_a? Hash fail "You have to provide login and password" if ((options[:login].nil? || options[:login].empty?) && (options[:password].nil? || options[:password].empty?)) threaded[:connection] = Connection.new(options[:login], options[:password], options) GoodData.project = options[:project] if options[:project] elsif options.is_a?(String) && second_options.is_a?(String) fail "You have to provide login and password" if ((options.nil? || options.empty?) && (second_options.nil? || second_options.empty?)) threaded[:connection] = Connection.new(options, second_options, third_options) end + + return threaded[:connection] end + # Disconnect (logout) if logged in + def disconnect + if threaded[:connection] + threaded[:connection].disconnect + threaded[:connection] = nil + end + end + # Turn logging on def logging_on if logger.is_a? NilLogger GoodData::logger = Logger.new(STDOUT) end @@ -173,15 +171,22 @@ # # ### Examples # # The following calls are equivalent # - # * GoodData.project = 'afawtv356b6usdfsdf34vt' - # * GoodData.use 'afawtv356b6usdfsdf34vt' - # * GoodData.use '/gdc/projects/afawtv356b6usdfsdf34vt' - # * GoodData.project = Project['afawtv356b6usdfsdf34vt'] + # # Assign project ID + # GoodData.project = 'afawtv356b6usdfsdf34vt' # + # # Use project ID + # GoodData.use 'afawtv356b6usdfsdf34vt' + # + # # Use project URL + # GoodData.use '/gdc/projects/afawtv356b6usdfsdf34vt' + # + # # Select project using indexer on GoodData::Project class + # GoodData.project = Project['afawtv356b6usdfsdf34vt'] + # def project=(project) if project.is_a? Project threaded[:project] = project elsif project.nil? threaded[:project] = nil @@ -219,11 +224,11 @@ # @param path The HTTP path on the GoodData server (must be prefixed with a forward slash) # @param data The payload data in the format of a Hash object # # ### Examples # - # GoodData.post '/gdc/projects', { ... } + # GoodData.post '/gdc/projects', { ... } # def post(path, data, options = {}) connection.post path, data, options end @@ -236,11 +241,11 @@ # @param path The HTTP path on the GoodData server (must be prefixed with a forward slash) # @param data The payload data in the format of a Hash object # # ### Examples # - # GoodData.put '/gdc/projects', { ... } + # GoodData.put '/gdc/projects', { ... } # def put(path, data, options = {}) connection.put path, data, options end @@ -265,21 +270,29 @@ :directory => options[:directory], :staging_url => url })) end - def upload_to_project_webdav(file, options={}) + def get_project_webdav_path(file, options={}) u = URI(connection.options[:webdav_server] || GoodData.project.links["uploads"]) url = URI.join(u.to_s.chomp(u.path.to_s), "/project-uploads/", "#{GoodData.project.pid}/") + end + + def upload_to_project_webdav(file, options={}) + url = get_project_webdav_path(file, options) connection.upload(file, options.merge({ :directory => options[:directory], :staging_url => url })) end - def download_form_user_webdav(file, where, options={}) + def get_user_webdav_path(file, options={}) u = URI(connection.options[:webdav_server] || GoodData.project.links["uploads"]) url = URI.join(u.to_s.chomp(u.path.to_s), "/uploads/") + end + + def download_from_user_webdav(file, where, options={}) + url = get_user_webdav_path(file, options) connection.download(file, where, options.merge({ :staging_url => url })) end