Class: Fog::Google::Pubsub::Real
- Inherits:
-
Object
- Object
- Fog::Google::Pubsub::Real
- Includes:
- Shared
- Defined in:
- lib/fog/google/pubsub/real.rb,
lib/fog/google/requests/pubsub/get_topic.rb,
lib/fog/google/requests/pubsub/list_topics.rb,
lib/fog/google/requests/pubsub/create_topic.rb,
lib/fog/google/requests/pubsub/delete_topic.rb,
lib/fog/google/requests/pubsub/publish_topic.rb,
lib/fog/google/requests/pubsub/get_subscription.rb,
lib/fog/google/requests/pubsub/pull_subscription.rb,
lib/fog/google/requests/pubsub/list_subscriptions.rb,
lib/fog/google/requests/pubsub/create_subscription.rb,
lib/fog/google/requests/pubsub/delete_subscription.rb,
lib/fog/google/requests/pubsub/acknowledge_subscription.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#pubsub ⇒ Object
readonly
Returns the value of attribute pubsub.
Attributes included from Shared
#api_url, #api_version, #project
Instance Method Summary collapse
-
#acknowledge_subscription(subscription, ack_ids) ⇒ Object
Acknowledges a message received from a subscription.
-
#create_subscription(subscription_name, topic, push_config = {}, ack_deadline_seconds = nil) ⇒ Object
Create a subscription resource on a topic.
-
#create_topic(topic_name) ⇒ Object
Create a topic on the remote service.
-
#delete_subscription(subscription_name) ⇒ Object
Delete a subscription on the remote service.
-
#delete_topic(topic_name) ⇒ Object
Delete a topic on the remote service.
-
#get_subscription(subscription_name) ⇒ Object
Retrieves a subscription by name from the remote service.
-
#get_topic(topic_name) ⇒ Object
Retrieves a resource describing a topic.
-
#initialize(options) ⇒ Real
constructor
A new instance of Real.
-
#list_subscriptions(project = nil) ⇒ Object
Gets a list of all subscriptions for a given project.
-
#list_topics(project = nil) ⇒ Object
Gets a list of all topics for a given project.
-
#publish_topic(topic, messages) ⇒ Object
Publish a list of messages to a topic.
-
#pull_subscription(subscription, options = { :return_immediately => true, :max_messages => 10 }) ⇒ Object
Pulls from a subscription.
Methods included from Shared
#build_excon_response, #create_signing_key, #initialize_google_client, #new_pk12_google_client, #request, #shared_initialize
Constructor Details
#initialize(options) ⇒ Real
Returns a new instance of Real.
10 11 12 13 14 15 16 |
# File 'lib/fog/google/pubsub/real.rb', line 10 def initialize() shared_initialize([:google_project], GOOGLE_PUBSUB_API_VERSION, GOOGLE_PUBSUB_BASE_URL) [:google_api_scope_url] = GOOGLE_PUBSUB_API_SCOPE_URLS.join(" ") @client = initialize_google_client() @pubsub = @client.discovered_api("pubsub", api_version) end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
7 8 9 |
# File 'lib/fog/google/pubsub/real.rb', line 7 def client @client end |
#pubsub ⇒ Object (readonly)
Returns the value of attribute pubsub.
8 9 10 |
# File 'lib/fog/google/pubsub/real.rb', line 8 def pubsub @pubsub end |
Instance Method Details
#acknowledge_subscription(subscription, ack_ids) ⇒ Object
Acknowledges a message received from a subscription.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/fog/google/requests/pubsub/acknowledge_subscription.rb', line 8 def acknowledge_subscription(subscription, ack_ids) api_method = @pubsub.projects.subscriptions.acknowledge parameters = { "subscription" => subscription.to_s } body = { "ackIds" => ack_ids } request(api_method, parameters, body) end |
#create_subscription(subscription_name, topic, push_config = {}, ack_deadline_seconds = nil) ⇒ Object
Create a subscription resource on a topic.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/google/requests/pubsub/create_subscription.rb', line 19 def create_subscription(subscription_name, topic, push_config = {}, ack_deadline_seconds = nil) api_method = @pubsub.projects.subscriptions.create parameters = {} parameters["name"] = subscription_name.to_s unless subscription_name.nil? body = { "topic" => (topic.is_a?(Topic) ? topic.name : topic.to_s) } if !push_config.nil? && push_config.key?("push_endpoint") body["pushConfig"] = push_config["push_endpoint"].clone body["pushConfig"]["attributes"] = push_config["attributes"] if push_config.key?("attributes") end body["ackDeadlineSeconds"] = ack_deadline_seconds unless ack_deadline_seconds.nil? request(api_method, parameters, body) end |
#create_topic(topic_name) ⇒ Object
Create a topic on the remote service.
11 12 13 14 15 16 17 18 |
# File 'lib/fog/google/requests/pubsub/create_topic.rb', line 11 def create_topic(topic_name) api_method = @pubsub.projects.topics.create parameters = { "name" => topic_name.to_s } request(api_method, parameters) end |
#delete_subscription(subscription_name) ⇒ Object
Delete a subscription on the remote service.
9 10 11 12 13 14 15 16 |
# File 'lib/fog/google/requests/pubsub/delete_subscription.rb', line 9 def delete_subscription(subscription_name) api_method = @pubsub.projects.subscriptions.delete parameters = { "subscription" => subscription_name.to_s } request(api_method, parameters) end |
#delete_topic(topic_name) ⇒ Object
Delete a topic on the remote service.
9 10 11 12 13 14 15 16 |
# File 'lib/fog/google/requests/pubsub/delete_topic.rb', line 9 def delete_topic(topic_name) api_method = @pubsub.projects.topics.delete parameters = { "topic" => topic_name.to_s } request(api_method, parameters) end |
#get_subscription(subscription_name) ⇒ Object
Retrieves a subscription by name from the remote service.
9 10 11 12 13 14 15 16 |
# File 'lib/fog/google/requests/pubsub/get_subscription.rb', line 9 def get_subscription(subscription_name) api_method = @pubsub.projects.subscriptions.get parameters = { "subscription" => subscription_name.to_s } request(api_method, parameters) end |
#get_topic(topic_name) ⇒ Object
Retrieves a resource describing a topic.
9 10 11 12 13 14 15 16 |
# File 'lib/fog/google/requests/pubsub/get_topic.rb', line 9 def get_topic(topic_name) api_method = @pubsub.projects.topics.get parameters = { "topic" => topic_name.to_s } request(api_method, parameters) end |
#list_subscriptions(project = nil) ⇒ Object
Gets a list of all subscriptions for a given project.
11 12 13 14 15 16 17 18 |
# File 'lib/fog/google/requests/pubsub/list_subscriptions.rb', line 11 def list_subscriptions(project = nil) api_method = @pubsub.projects.subscriptions.list parameters = { "project" => (project.nil? ? "projects/#{@project}" : project.to_s) } request(api_method, parameters) end |
#list_topics(project = nil) ⇒ Object
Gets a list of all topics for a given project.
11 12 13 14 15 16 17 18 |
# File 'lib/fog/google/requests/pubsub/list_topics.rb', line 11 def list_topics(project = nil) api_method = @pubsub.projects.topics.list parameters = { "project" => (project.nil? ? "projects/#{@project}" : project.to_s) } request(api_method, parameters) end |
#publish_topic(topic, messages) ⇒ Object
Publish a list of messages to a topic.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fog/google/requests/pubsub/publish_topic.rb', line 12 def publish_topic(topic, ) api_method = @pubsub.projects.topics.publish parameters = { "topic" => topic } body = { "messages" => } request(api_method, parameters, body) end |
#pull_subscription(subscription, options = { :return_immediately => true, :max_messages => 10 }) ⇒ Object
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.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fog/google/requests/pubsub/pull_subscription.rb', line 19 def pull_subscription(subscription, = { :return_immediately => true, :max_messages => 10 }) api_method = @pubsub.projects.subscriptions.pull parameters = { "subscription" => Fog::Google::Pubsub.subscription_name(subscription) } body = { "returnImmediately" => [:return_immediately], "maxMessages" => [:max_messages] } request(api_method, parameters, body) end |