Sha256: f449c51afc0f970a3ad9c1b80f6d00a28571e1d50766741a1e8f51a99648678f

Contents?: true

Size: 1.23 KB

Versions: 20

Compression:

Stored size: 1.23 KB

Contents

require 'sequel'
require 'pact_broker/domain/webhook'
require 'pact_broker/domain/pacticipant'
require 'pact_broker/db'
require 'pact_broker/repositories/webhook'


module PactBroker
  module Repositories

    class WebhookRepository

      include Repositories

      def create uuid, webhook, consumer, provider
        db_webhook = Webhook.from_domain webhook, consumer, provider
        db_webhook.uuid = uuid
        db_webhook.save
        webhook.request.headers.each_pair do | name, value |
          db_webhook.add_header WebhookHeader.from_domain(name, value, db_webhook.id)
        end
        find_by_uuid db_webhook.uuid
      end

      def find_by_uuid uuid
        Webhook.where(uuid: uuid).limit(1).collect(&:to_domain)[0]
      end

      def delete_by_uuid uuid
        Webhook.where(uuid: uuid).destroy
      end

      def delete_by_pacticipant pacticipant
        Webhook.where(consumer_id: pacticipant.id).destroy
        Webhook.where(provider_id: pacticipant.id).destroy
      end

      def find_all
        Webhook.all.collect(&:to_domain)
      end

      def find_by_consumer_and_provider consumer, provider
        Webhook.where(consumer_id: consumer.id, provider_id: provider.id).collect(&:to_domain)
      end

    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
pact_broker-1.15.0 lib/pact_broker/repositories/webhook_repository.rb
pact_broker-1.14.0 lib/pact_broker/repositories/webhook_repository.rb
pact_broker-1.13.0 lib/pact_broker/repositories/webhook_repository.rb
pact_broker-1.12.0 lib/pact_broker/repositories/webhook_repository.rb
pact_broker-1.11.2 lib/pact_broker/repositories/webhook_repository.rb
pact_broker-1.11.1 lib/pact_broker/repositories/webhook_repository.rb
pact_broker-1.11.0 lib/pact_broker/repositories/webhook_repository.rb
pact_broker-1.10.0 lib/pact_broker/repositories/webhook_repository.rb
pact_broker-1.9.3 lib/pact_broker/repositories/webhook_repository.rb
pact_broker-1.9.2 lib/pact_broker/repositories/webhook_repository.rb
pact_broker-1.9.1 lib/pact_broker/repositories/webhook_repository.rb
pact_broker-1.9.0 lib/pact_broker/repositories/webhook_repository.rb
pact_broker-1.9.0.rc1 lib/pact_broker/repositories/webhook_repository.rb
pact_broker-1.8.1 lib/pact_broker/repositories/webhook_repository.rb
pact_broker-1.8.0 lib/pact_broker/repositories/webhook_repository.rb
pact_broker-1.7.0 lib/pact_broker/repositories/webhook_repository.rb
pact_broker-1.6.0 lib/pact_broker/repositories/webhook_repository.rb
pact_broker-1.5.0 lib/pact_broker/repositories/webhook_repository.rb
pact_broker-1.4.0 lib/pact_broker/repositories/webhook_repository.rb
pact_broker-1.3.2.rc1 lib/pact_broker/repositories/webhook_repository.rb