Sha256: d5619bf5315ad11dbfdd7a5fe6c94ad082c00482e4861f7faa2821b0bf8b7ee8

Contents?: true

Size: 880 Bytes

Versions: 6

Compression:

Stored size: 880 Bytes

Contents

module Services
  module Authorization
    module Tokens
      class Refresh < Tokens::Base
        def initialize(tokens:, request:)
          @tokens = tokens
          @request = request
        end

        def call
          @tokens = refresh_tokens if Time.current > @tokens[:expires_at]
          @tokens
        end

        private

        def refresh_tokens
          tokens_api = ::Hubspot::OAuth::TokensApi.new
          tokens = tokens_api.post_oauth_v1_token(
            grant_type: :refresh_token,
            refresh_token: @tokens[:refresh_token],
            redirect_uri: redirect_uri,
            client_id: ENV['HUBSPOT_CLIENT_ID'],
            client_secret: ENV['HUBSPOT_CLIENT_SECRET'],
            return_type: 'Object'
          )
          tokens[:expires_at] = expires_at(tokens[:expires_in])
          tokens
        end
      end
    end
  end
end

Version data entries

6 entries across 1 versions & 1 rubygems

Version Path
hubspot-api-client-2.0.0 sample-apps/companies-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-2.0.0 sample-apps/contacts-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-2.0.0 sample-apps/leaky-bucket-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-2.0.0 sample-apps/oauth-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-2.0.0 sample-apps/rate-limits-redis-sample-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-2.0.0 sample-apps/retry-middleware-sample-app/app/lib/services/authorization/tokens/refresh.rb