Sha256: bdc588c1e4af715821b726bee27ba81950a5bc1ef89e0d52f39a4bb9c9888cee

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module TwilioBase
  module Fake
    module Chat
      class Service
        Service = Struct.new(:friendly_name) do
          attr_accessor :webhook_filters, :post_webhook_url

          def sid
            @sid ||= TwilioBase::GlobalConfig.first&.chat_service_sid ||
                     FactoryBot.generate(:chat_service_sid)
          end

          def update(post_webhook_url:, webhook_filters: nil)
            self.post_webhook_url = post_webhook_url
            self.webhook_filters = webhook_filters if webhook_filters
          end
        end

        cattr_accessor :services
        self.services = []

        def initialize(service_sid = nil)
          self.service_sid = service_sid
        end

        def create(friendly_name:)
          service = Service.new(friendly_name)
          self.class.services << service
          service
        end

        def channels(channel_id = nil)
          TwilioBase::Fake::Chat::Channel.new(channel_id)
        end

        def fetch
          services.detect { |service| service.sid == service_sid }
        end

        def list
          services
        end

        private

        attr_accessor :service_sid
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
twilio_base-1.11.1101 spec/support/twilio_base/fake/chat/service.rb
twilio_base-1.11.11 spec/support/twilio_base/fake/chat/service.rb
twilio_base-1.9.0 spec/support/twilio_base/fake/chat/service.rb
twilio_base-1.8.0 spec/support/twilio_base/fake/chat/service.rb