Sha256: 9eb5dd1096207aadd100f90d2e48072c53b5e2e0542732572546747f20331ec0

Contents?: true

Size: 1.06 KB

Versions: 7

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module Shark
  class Subscription < Base
    extend SubscriptionService::Resource

    custom_endpoint :bulk_creation, on: :collection, request_method: :post
    custom_endpoint :bulk_deletion, on: :collection, request_method: :post

    def self.create_multiple(attributes)
      bulk_creation(subscriptions_attributes(attributes))
    end

    def self.destroy_multiple(attributes)
      bulk_deletion(subscriptions_attributes(attributes))
    end

    def save
      if self['id'].present?
        raise Shark::ActionNotSupportedError,
              'Shark::Subscription#save is not supported for persisted subscriptions'
      else
        super
      end
    end

    def update_attributes(_attributes = {})
      raise Shark::ActionNotSupportedError,
            'Shark::Subscription#update_attributes is not supported'
    end

    def self.subscriptions_attributes(attributes)
      {
        data: {
          type: 'bulk-subscriptions',
          attributes: {
            subscriptions: attributes
          }
        }
      }
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bima-shark-sdk-2.4.4 lib/shark/subscription.rb
bima-shark-sdk-2.4.3 lib/shark/subscription.rb
bima-shark-sdk-2.4.2 lib/shark/subscription.rb
bima-shark-sdk-2.4.1 lib/shark/subscription.rb
bima-shark-sdk-2.4.0 lib/shark/subscription.rb
bima-shark-sdk-2.3.1 lib/shark/subscription.rb
bima-shark-sdk-2.3.0 lib/shark/subscription.rb