lib/gooddata/rest/client.rb in gooddata-0.6.18 vs lib/gooddata/rest/client.rb in gooddata-0.6.19
- old
+ new
@@ -59,22 +59,25 @@
# client = GoodData.connect('jon.smith@goodddata.com', 's3cr3tp4sw0rd')
#
# @param username [String] Username to be used for authentication
# @param password [String] Password to be used for authentication
# @return [GoodData::Rest::Client] Client
- def connect(username, password, opts = { :verify_ssl => true })
+ def connect(username, password, opts = { verify_ssl: true })
if username.nil? && password.nil?
username = ENV['GD_GEM_USER']
password = ENV['GD_GEM_PASSWORD']
end
+ username = username.symbolize_keys if username.is_a?(Hash)
+
new_opts = opts.dup
if username.is_a?(Hash) && username.key?(:sst_token)
- new_opts[:sst_token] = username[:sst_token]
+ new_opts = username
elsif username.is_a? Hash
new_opts[:username] = username[:login] || username[:user] || username[:username]
new_opts[:password] = username[:password]
+ new_opts[:verify_ssl] = username[:verify_ssl] if username[:verify_ssl] == false || !username[:verify_ssl].blank?
elsif username.nil? && password.nil? && (opts.nil? || opts.empty?)
new_opts = Helpers::AuthHelper.read_credentials
else
new_opts[:username] = username
new_opts[:password] = password
@@ -98,18 +101,18 @@
@@instance = client # rubocop:disable ClassVars
client
end
def disconnect
- if @@instance # rubocop:disable ClassVars, Style/GuardClause
- @@instance.disconnect # rubocop:disable ClassVars
+ if @@instance # rubocop:disable Style/GuardClause
+ @@instance.disconnect
@@instance = nil # rubocop:disable ClassVars
end
end
def connection
- @@instance # rubocop:disable ClassVars
+ @@instance
end
# Retry block if exception thrown
def retryable(options = {}, &block)
GoodData::Rest::Connection.retryable(options, &block)
@@ -144,11 +147,11 @@
def create_project(options = { title: 'Project', auth_token: ENV['GD_PROJECT_TOKEN'] })
GoodData::Project.create({ client: self }.merge(options))
end
def create_project_from_blueprint(blueprint, options = {})
- GoodData::Model::ProjectCreator.migrate(spec: blueprint, token: options[:auth_token], client: self)
+ GoodData::Model::ProjectCreator.migrate(options.merge(spec: blueprint, client: self))
end
def domain(domain_name)
GoodData::Domain[domain_name, :client => self]
end
@@ -207,11 +210,11 @@
def stats_on
@stats = true
end
- def stats_on? # rubocop:disable Style/TrivialAccessors
+ def stats_on?
@stats
end
def generate_request_id
@connection.generate_request_id
@@ -232,11 +235,11 @@
# @param uri [String] Target URI
def get(uri, opts = {}, & block)
@connection.get uri, opts, & block
end
- def project_webdav_path(opts = { :project => GoodData.project })
+ def project_webdav_path(opts = { project: GoodData.project })
p = opts[:project]
fail ArgumentError, 'No :project specified' if p.nil?
project = GoodData::Project[p, opts]
fail ArgumentError, 'Wrong :project specified' if project.nil?
@@ -244,11 +247,11 @@
url = project.links['uploads']
fail 'Project WebDAV not supported in this Data Center' unless url
url
end
- def user_webdav_path(opts = { :project => GoodData.project })
+ def user_webdav_path(opts = { project: GoodData.project })
p = opts[:project]
fail ArgumentError, 'No :project specified' if p.nil?
project = GoodData::Project[p, opts]
fail ArgumentError, 'Wrong :project specified' if project.nil?
@@ -292,25 +295,22 @@
# @return [Hash] Result of polling
def poll_on_response(link, options = {}, &bl)
sleep_interval = options[:sleep_interval] || DEFAULT_SLEEP_INTERVAL
time_limit = options[:time_limit] || DEFAULT_POLL_TIME_LIMIT
- # by default the response is processed
- process = options[:process]
-
# get the first status and start the timer
- response = get(link, :process => process)
+ response = get(link, options)
poll_start = Time.now
while bl.call(response)
- if time_limit && (Time.now - poll_start > time_limit)
- fail "The time limit #{time_limit} secs for polling on #{link} is over"
+ limit_breached = time_limit && (Time.now - poll_start > time_limit)
+ if limit_breached
+ fail ExecutionLimitExceeded, "The time limit #{time_limit} secs for polling on #{link} is over"
end
sleep sleep_interval
GoodData::Rest::Client.retryable(:tries => 3, :refresh_token => proc { connection.refresh_token }) do
- sleep sleep_interval
- response = get(link, :process => process)
+ response = get(link, options)
end
end
response
end
@@ -343,10 +343,10 @@
# @param options [Hash] must contain :staging_url key (file will be downloaded from :staging_url + source_relative_path)
def download(source_relative_path, target_file_path, options = {})
@connection.download source_relative_path, target_file_path, options
end
- def download_from_user_webdav(source_relative_path, target_file_path, options = { :client => GoodData.client, :project => project })
+ def download_from_user_webdav(source_relative_path, target_file_path, options = { client: GoodData.client, project: project })
download(source_relative_path, target_file_path, options.merge(:directory => options[:directory],
:staging_url => get_user_webdav_url(options)))
end
def upload_to_user_webdav(file, options = {})