Class: PubsubClient

Inherits:
Object
  • Object
show all
Defined in:
lib/pubsub_client.rb,
lib/pubsub_client/version.rb,
lib/pubsub_client/publisher.rb,
lib/pubsub_client/subscriber.rb,
lib/pubsub_client/null_publisher.rb,
lib/pubsub_client/null_subscriber.rb,
lib/pubsub_client/publisher_factory.rb,
lib/pubsub_client/subscriber_factory.rb,
lib/pubsub_client/null_publisher_factory.rb,
lib/pubsub_client/null_subscriber_factory.rb

Defined Under Namespace

Classes: NullPublisher, NullPublisherFactory, NullSubscriber, NullSubscriberFactory, Publisher, PublisherFactory, Subscriber, SubscriberFactory

Constant Summary collapse

Error =
Class.new(StandardError)
ConfigurationError =
Class.new(Error)
CredentialsError =
Class.new(Error)
InvalidTopicError =
Class.new(Error)
InvalidSubscriptionError =
Class.new(Error)
VERSION =
'2.0.0'

Instance Method Summary collapse

Instance Method Details

#publish(message, topic, attributes = {}, &block) ⇒ Object



32
33
34
35
36
37
# File 'lib/pubsub_client.rb', line 32

def publish(message, topic, attributes = {}, &block)
  ensure_credentials!

  @publisher_factory ||= PublisherFactory.new
  @publisher_factory.build(topic).publish(message, attributes, &block)
end

#stub!Object

Raises:



16
17
18
19
20
21
22
# File 'lib/pubsub_client.rb', line 16

def stub!
  raise ConfigurationError, 'PubsubClient is already configured' if @publisher_factory || @subscriber_factory

  @publisher_factory = NullPublisherFactory.new
  @subscriber_factory = NullSubscriberFactory.new
  @stubbed = true
end

#subscriber(subscription) ⇒ Object

Parameters:

  • subscription (String)
    • The name of the subscription to subscribe to.



25
26
27
28
29
30
# File 'lib/pubsub_client.rb', line 25

def subscriber(subscription)
  ensure_credentials!

  @subscriber_factory ||= SubscriberFactory.new
  @subscriber_factory.build(subscription)
end