lib/gooddata/connection.rb in gooddata-0.5.5 vs lib/gooddata/connection.rb in gooddata-0.5.6
- old
+ new
@@ -32,24 +32,51 @@
DEFAULT_URL = 'https://secure.gooddata.com'
LOGIN_PATH = '/gdc/account/login'
TOKEN_PATH = '/gdc/account/token'
STAGE_PATH = '/uploads/'
+ attr_reader(:auth_token)
+
+ # 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.
+ #
+ # Example
+ # =======
+ # retryable(:tries => 1, :on => OpenURI::HTTPError) do
+ # # your code here
+ # end
+ #
+ def retryable(options = {}, &block)
+ opts = { :tries => 1, :on => Exception }.merge(options)
+
+ retry_exception, retries = opts[:on], opts[:tries]
+
+ begin
+ return yield
+ rescue retry_exception
+ retry if (retries -= 1) > 0
+ end
+
+ yield
+ end
+
# Set the GoodData account credentials.
#
# This have to be performed before any calls to the API.
#
# === Parameters
#
# * +username+ - The GoodData account username
# * +password+ - The GoodData account password
def initialize(username, password, url = nil, options = {})
- @status = :not_connected
- @username = username
- @password = password
- @url = url || DEFAULT_URL
- @options = options
+ @status = :not_connected
+ @username = username
+ @password = password
+ @url = url || DEFAULT_URL
+ @auth_token = options.delete(:auth_token)
+ @options = options
end
# Returns the user JSON object of the currently logged in GoodData user account.
def user
ensure_connection
@@ -285,9 +312,12 @@
result = response
GoodData.logger.debug "Response: a zipped stream"
elsif response.headers[:content_length].to_s == '0'
result = nil
GoodData.logger.debug "Response: Empty response possibly 204"
+ elsif response.code == 204
+ result = nil
+ GoodData.logger.debug "Response: 204 no content"
else
raise "Unsupported response content type '%s':\n%s" % [ content_type, response.to_str[0..127] ]
end
result
rescue RestClient::Exception => e