Files
openfoodnetwork/app/models/connected_app.rb
David Cook 9d89b4726b Move connect logic to model
Then subtypes can override as needed.
2024-07-25 17:06:13 +10:00

32 lines
587 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
belongs_to :enterprise
after_destroy :disconnect
scope :discover_regen, -> { where(type: "ConnectedApp") }
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