Sha256: 3791cef2edf3358a944476566811d9342944275fef82b7257838c1c66cd9a819

Contents?: true

Size: 978 Bytes

Versions: 7

Compression:

Stored size: 978 Bytes

Contents

module Services
  module Hubspot
    module Authorization
      module Tokens
        class Refresh < Tokens::Base
          def initialize(tokens:, request:)
            @tokens = tokens.with_indifferent_access
            @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
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hubspot-api-client-9.0.0 sample-apps/trello-integration-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-8.0.1 sample-apps/trello-integration-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-8.0.0 sample-apps/trello-integration-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-7.3.0 sample-apps/trello-integration-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-7.2.0 sample-apps/trello-integration-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-7.1.1 sample-apps/trello-integration-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-7.1.0 sample-apps/trello-integration-app/app/lib/services/hubspot/authorization/tokens/refresh.rb