Sha256: 59de261709a9eb2992f88467c2451dd4aa7398e8763c62c4d3c2105558d205cc

Contents?: true

Size: 876 Bytes

Versions: 136

Compression:

Stored size: 876 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
          default_api = ::Hubspot::OAuth::DefaultApi.new
          tokens = default_api.create_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

136 entries across 20 versions & 1 rubygems

Version Path
hubspot-api-client-9.0.0 sample-apps/imports-contacts-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-9.0.0 sample-apps/contacts-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-9.0.0 sample-apps/rate-limits-redis-sample-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-9.0.0 sample-apps/timeline-events-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-9.0.0 sample-apps/leaky-bucket-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-9.0.0 sample-apps/companies-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-9.0.0 sample-apps/retry-middleware-sample-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-9.0.0 sample-apps/oauth-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-8.0.1 sample-apps/imports-contacts-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-8.0.1 sample-apps/retry-middleware-sample-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-8.0.1 sample-apps/companies-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-8.0.1 sample-apps/timeline-events-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-8.0.1 sample-apps/oauth-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-8.0.1 sample-apps/contacts-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-8.0.1 sample-apps/leaky-bucket-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-8.0.1 sample-apps/rate-limits-redis-sample-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-8.0.0 sample-apps/contacts-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-8.0.0 sample-apps/imports-contacts-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-8.0.0 sample-apps/leaky-bucket-app/app/lib/services/authorization/tokens/refresh.rb
hubspot-api-client-8.0.0 sample-apps/companies-app/app/lib/services/authorization/tokens/refresh.rb