Sha256: 60253642a49b0508654200137ddebfe89c869f6e90092c62a4aaea692e0d2ec1

Contents?: true

Size: 1.08 KB

Versions: 12

Compression:

Stored size: 1.08 KB

Contents

module Services
  module Hubspot
    module Webhooks
      class PauseActiveSubscriptions
        def initialize(app_id:)
          @app_id = app_id
        end

        def call
          return false if active_subscriptions.empty?

          inputs = active_subscriptions.map do |subscription|
            ::Hubspot::Webhooks::SubscriptionBatchUpdateRequest.new(
              id: subscription.id,
              active: false
            )
          end

          batch_input_subscription_batch_update_request =
            ::Hubspot::Webhooks::BatchInputSubscriptionBatchUpdateRequest.new(inputs: inputs)

          ::Hubspot::Webhooks::SubscriptionsApi.new.update_batch(
            @app_id,
            batch_input_subscription_batch_update_request
          )
        end

        private

        def active_subscriptions
          return @active_subscriptions if @active_subscriptions.present?

          subscriptions = ::Hubspot::Webhooks::SubscriptionsApi.new.get_all(@app_id).results
          @active_subscriptions = subscriptions.filter(&:active)
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
hubspot-api-client-9.0.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/webhooks/pause_active_subscriptions.rb
hubspot-api-client-8.0.1 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/webhooks/pause_active_subscriptions.rb
hubspot-api-client-8.0.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/webhooks/pause_active_subscriptions.rb
hubspot-api-client-7.3.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/webhooks/pause_active_subscriptions.rb
hubspot-api-client-7.2.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/webhooks/pause_active_subscriptions.rb
hubspot-api-client-7.1.1 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/webhooks/pause_active_subscriptions.rb
hubspot-api-client-7.1.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/webhooks/pause_active_subscriptions.rb
hubspot-api-client-7.0.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/webhooks/pause_active_subscriptions.rb
hubspot-api-client-6.0.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/webhooks/pause_active_subscriptions.rb
hubspot-api-client-5.0.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/webhooks/pause_active_subscriptions.rb
hubspot-api-client-4.0.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/webhooks/pause_active_subscriptions.rb
hubspot-api-client-3.3.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/webhooks/pause_active_subscriptions.rb