lib/mrkt/concerns/authentication.rb in mrkt-0.9.0 vs lib/mrkt/concerns/authentication.rb in mrkt-0.10.0
- old
+ new
@@ -3,26 +3,29 @@
def authenticate!
return if authenticated?
authenticate
- if !authenticated? && @retry_authentication
- @retry_authentication_count.times do
- sleep(@retry_authentication_wait_seconds) if @retry_authentication_wait_seconds > 0
- authenticate
- break if authenticated?
- end
- end
+ retry_authentication if !authenticated? && @retry_authentication
- fail Mrkt::Errors::AuthorizationError, 'Client not authenticated' unless authenticated?
+ raise Mrkt::Errors::AuthorizationError, 'Client not authenticated' unless authenticated?
end
def authenticated?
@token && valid_token?
end
def valid_token?
@valid_until && Time.now < @valid_until
+ end
+
+ def retry_authentication
+ @retry_authentication_count.times do
+ sleep(@retry_authentication_wait_seconds) if @retry_authentication_wait_seconds.positive?
+ authenticate
+
+ break if authenticated?
+ end
end
def authenticate
connection.get('/identity/oauth/token', authentication_params).tap do |response|
data = response.body