Files
openfoodnetwork/app/models/connected_app.rb
Gaetan Craig-Riou 0824430da5 Add Vine connected app
The connection/disconnection logic is yet to be implemented
2024-09-24 10:43:55 +10:00

39 lines
890 B
Ruby

# frozen_string_literal: true
# An enterprise can be connected to other apps.
#
# Here we store keys and links to access the app.
class ConnectedApp < ApplicationRecord
TYPES = ['discover_regen', 'affiliate_sales_data', 'vine'].freeze
belongs_to :enterprise
after_destroy :disconnect
scope :discover_regen, -> { where(type: "ConnectedApp") }
scope :affiliate_sales_data, -> { where(type: "ConnectedApps::AffiliateSalesData") }
scope :vine, -> { where(type: "ConnectedApps::Vine") }
scope :connecting, -> { where(data: nil) }
scope :ready, -> { where.not(data: nil) }
def connecting?
data.nil?
end
def ready?
!connecting?
end
def connect(api_key:, channel:)
ConnectAppJob.perform_later(self, api_key, channel:)
end
def disconnect
WebhookDeliveryJob.perform_later(
data["destroy"],
"disconnect-app",
nil
)
end
end