Class: Fog::Google::Pubsub::Topic
- Inherits:
-
Model
- Object
- Model
- Fog::Google::Pubsub::Topic
- Defined in:
- lib/fog/google/models/pubsub/topic.rb
Overview
Represents a Pubsub topic resource
Instance Method Summary collapse
-
#create ⇒ Fog::Google::Pubsub::Topic
Creates this topic resource on the service.
-
#destroy ⇒ Fog::Google::Pubsub::Topic
Deletes this topic resource on the service.
-
#publish(messages) ⇒ Array<String>
Publish a message to this topic.
-
#save ⇒ Fog::Google::Pubsub::Topic
Save the instance (does the same thing as #create).
Instance Method Details
#create ⇒ Fog::Google::Pubsub::Topic
Creates this topic resource on the service.
15 16 17 18 19 20 |
# File 'lib/fog/google/models/pubsub/topic.rb', line 15 def create requires :name service.create_topic(name) self end |
#destroy ⇒ Fog::Google::Pubsub::Topic
Deletes this topic resource on the service.
25 26 27 28 29 30 |
# File 'lib/fog/google/models/pubsub/topic.rb', line 25 def destroy requires :name service.delete_topic(name) self end |
#publish(messages) ⇒ Array<String>
Publish a message to this topic. This method will automatically encode the message via base64 encoding.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fog/google/models/pubsub/topic.rb', line 41 def publish() requires :name # Ensure our messages are base64 encoded = [] .each do || = {} if .is_a?(Hash) if .key?("data") [:data] = Base64.strict_encode64(["data"]) end else [:data] = Base64.strict_encode64(.to_s) end << end service.publish_topic(name, ).to_h[:message_ids] end |
#save ⇒ Fog::Google::Pubsub::Topic
Save the instance (does the same thing as #create)
65 66 67 |
# File 'lib/fog/google/models/pubsub/topic.rb', line 65 def save create end |