Sha256: 9723063d201484d5001dea0a3f5b4a89f83a98234ad4de9e10739b79da68a6b1

Contents?: true

Size: 954 Bytes

Versions: 23

Compression:

Stored size: 954 Bytes

Contents

module Services
  module Hubspot
    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
end

Version data entries

23 entries across 12 versions & 1 rubygems

Version Path
hubspot-api-client-9.0.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-9.0.0 sample-apps/search-result-paging-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-8.0.1 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-8.0.1 sample-apps/search-result-paging-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-8.0.0 sample-apps/search-result-paging-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-8.0.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-7.3.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-7.3.0 sample-apps/search-result-paging-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-7.2.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-7.2.0 sample-apps/search-result-paging-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-7.1.1 sample-apps/search-result-paging-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-7.1.1 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-7.1.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-7.1.0 sample-apps/search-result-paging-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-7.0.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-7.0.0 sample-apps/search-result-paging-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-6.0.0 sample-apps/search-result-paging-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-6.0.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-5.0.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/authorization/tokens/refresh.rb
hubspot-api-client-5.0.0 sample-apps/search-result-paging-app/app/lib/services/hubspot/authorization/tokens/refresh.rb