class Fog::Google::Pubsub::Real

Attributes

client[RW]
pubsub[R]

Public Class Methods

new(options) click to toggle source
# File lib/fog/google/pubsub/real.rb, line 10
def initialize(options)
  shared_initialize(options[:google_project], GOOGLE_PUBSUB_API_VERSION, GOOGLE_PUBSUB_BASE_URL)
  options[:google_api_scope_url] = GOOGLE_PUBSUB_API_SCOPE_URLS.join(" ")

  @client = initialize_google_client(options)
  @pubsub = ::Google::Apis::PubsubV1::PubsubService.new
  apply_client_options(@pubsub, options)
end

Public Instance Methods

acknowledge_subscription(subscription, ack_ids) click to toggle source

Acknowledges a message received from a subscription.

@see cloud.google.com/pubsub/reference/rest/v1/projects.subscriptions/acknowledge

# File lib/fog/google/requests/pubsub/acknowledge_subscription.rb, line 8
def acknowledge_subscription(subscription, ack_ids)
  # Previous behavior allowed passing a single ack_id without being wrapped in an Array,
  # this is for backwards compatibility.
  unless ack_ids.is_a?(Array)
    ack_ids = [ack_ids]
  end
  ack_request = ::Google::Apis::PubsubV1::AcknowledgeRequest.new(
    ack_ids: ack_ids
  )

  @pubsub.acknowledge_subscription(subscription, ack_request)
end
create_subscription(subscription_name, topic, push_config = {}, ack_deadline_seconds = nil) click to toggle source

Create a subscription resource on a topic.

@param subscription_name [#to_s] name of the subscription to create.

Note that it must follow the restrictions of subscription names;
specifically it must be named within a project (e.g.
"projects/my-project/subscriptions/my-subscripton")

@param topic [Topic, to_s] topic instance or name of topic to create

subscription on

@param push_config [Hash] configuration for a push config (if empty

hash, then no push_config is created)

@param ack_deadline_seconds [Number] how long the service waits for

an acknowledgement before redelivering the message; if nil then
service default of 10 is used

@see cloud.google.com/pubsub/reference/rest/v1/projects.subscriptions/create

# File lib/fog/google/requests/pubsub/create_subscription.rb, line 19
def create_subscription(subscription_name, topic, push_config = {}, ack_deadline_seconds = nil)
  subscription = ::Google::Apis::PubsubV1::Subscription.new(
    topic: topic,
    ack_deadline_seconds: ack_deadline_seconds,
    push_config: push_config
  )

  @pubsub.create_subscription(subscription_name, subscription)
end
create_topic(topic_name) click to toggle source

Create a topic on the remote service.

@param topic_name [#to_s] name of topic to create; note that it must

obey the naming rules for a topic (e.g.
'projects/myProject/topics/my_topic')

@see cloud.google.com/pubsub/reference/rest/v1/projects.topics/create

# File lib/fog/google/requests/pubsub/create_topic.rb, line 11
def create_topic(topic_name)
  @pubsub.create_topic(topic_name)
end
delete_subscription(subscription_name) click to toggle source

Delete a subscription on the remote service.

@param subscription_name [#to_s] name of subscription to delete @see cloud.google.com/pubsub/reference/rest/v1/projects.subscriptions/delete

# File lib/fog/google/requests/pubsub/delete_subscription.rb, line 9
def delete_subscription(subscription_name)
  @pubsub.delete_subscription(subscription_name)
end
delete_topic(topic_name) click to toggle source

Delete a topic on the remote service.

@param topic_name [#to_s] name of topic to delete @see cloud.google.com/pubsub/reference/rest/v1/projects.topics/delete

# File lib/fog/google/requests/pubsub/delete_topic.rb, line 9
def delete_topic(topic_name)
  @pubsub.delete_topic(topic_name)
end
get_subscription(subscription_name) click to toggle source

Retrieves a subscription by name from the remote service.

@param subscription_name [#to_s] name of subscription to retrieve @see cloud.google.com/pubsub/reference/rest/v1/projects.topics/get

# File lib/fog/google/requests/pubsub/get_subscription.rb, line 9
def get_subscription(subscription_name)
  @pubsub.get_subscription(subscription_name)
end
get_topic(topic_name) click to toggle source

Retrieves a resource describing a topic.

@param topic_name [#to_s] name of topic to retrieve @see cloud.google.com/pubsub/reference/rest/v1/projects.topics/get

# File lib/fog/google/requests/pubsub/get_topic.rb, line 9
def get_topic(topic_name)
  @pubsub.get_topic(topic_name)
end
list_subscriptions(project = nil) click to toggle source

Gets a list of all subscriptions for a given project.

@param_name project [#to_s] Project path to list subscriptions under;

must be a project url prefix (e.g. 'projects/my-project'). If nil,
the project configured on the client is used.

@see cloud.google.com/pubsub/reference/rest/v1/projects.topics/list

# File lib/fog/google/requests/pubsub/list_subscriptions.rb, line 11
def list_subscriptions(project = nil)
  if project.nil?
    project = "projects/#{@project}"
  else
    project = project.to_s
  end

  @pubsub.list_subscriptions(project)
end
list_topics(project = nil) click to toggle source

Gets a list of all topics for a given project.

@param_name project [#to_s] Project path to list topics under; must

be a project url prefix (e.g. 'projects/my-project'). If nil, the
project configured on the client is used.

@see cloud.google.com/pubsub/reference/rest/v1/projects.topics/list

# File lib/fog/google/requests/pubsub/list_topics.rb, line 11
def list_topics(project = nil)
  if project.nil?
    project = "projects/#{@project}"
  else
    project = project.to_s
  end

  @pubsub.list_topics(project)
end
publish_topic(topic, messages) click to toggle source

Publish a list of messages to a topic.

@param messages [Array<Hash>] List of messages to be published to a

topic; each hash should have a value defined for 'data' or for
'attributes' (or both). Note that the value associated with 'data'
must be base64 encoded.

@see cloud.google.com/pubsub/reference/rest/v1/projects.topics/publish

# File lib/fog/google/requests/pubsub/publish_topic.rb, line 12
def publish_topic(topic, messages)
  publish_request = ::Google::Apis::PubsubV1::PublishRequest.new(
    :messages => messages
  )

  @pubsub.publish_topic(topic, publish_request)
end
pull_subscription(subscription, options = {}) click to toggle source

Pulls from a subscription. If option 'return_immediately' is false, then this method blocks until one or more messages is available or the remote server closes the connection.

@param subscription [Subscription, to_s] subscription instance or

name of subscription to pull from

@param options [Hash] options to modify the pull request @option options [Boolean] :return_immediately if true, method returns

after API call; otherwise the connection is held open until
messages are available or the remote server closes the connection
(defaults to true)

@option options [Number] :max_messages maximum number of messages to

retrieve (defaults to 10)

@see cloud.google.com/pubsub/reference/rest/v1/projects.subscriptions/pull

# File lib/fog/google/requests/pubsub/pull_subscription.rb, line 19
def pull_subscription(subscription, options = {})
  defaults = { :return_immediately => true,
               :max_messages => 10 }
  options = defaults.merge(options)

  pull_request = ::Google::Apis::PubsubV1::PullRequest.new(
    :return_immediately => options[:return_immediately],
    :max_messages => options[:max_messages]
  )

  @pubsub.pull_subscription(subscription, pull_request)
end