lib/agx/sync/client.rb in agx-0.3.1 vs lib/agx/sync/client.rb in agx-0.3.2

- old
+ new

@@ -114,10 +114,25 @@ handle_error(e) end end end + def current_token + new_token = OAuth2::AccessToken.new @client, @token[:access_token], { + expires_at: @token[:expires_at], + refresh_token: @token[:refresh_token] + } + if Time.now.to_i + 90 >= @token[:expires_at] + new_token = new_token.refresh! + @token[:access_token] = new_token.token + @token[:refresh_token] = new_token.refresh_token + @token[:expires_at] = new_token.expires_at + end + + new_token + end + protected def validate_credentials unless @client_id && @client_secret error = Agx::Error.new("agX Client Credentials Not Set", {title: "AGX_CREDENTIALS_ERROR"}) @@ -175,24 +190,9 @@ rescue Oj::ParseError end error_to_raise = Agx::Error.new(error.message, error_params) raise error_to_raise - end - - def current_token - new_token = OAuth2::AccessToken.new @client, @token[:access_token], { - expires_at: @token[:expires_at], - refresh_token: @token[:refresh_token] - } - if Time.now.to_i + 90 >= @token[:expires_at] - new_token = new_token.refresh! - @token[:access_token] = new_token.token - @token[:refresh_token] = new_token.refresh_token - @token[:expires_at] = new_token.expires_at - end - - new_token end def set_client @client = OAuth2::Client.new( @client_id,