class AWS::SNS::Topic
def confirm_subscription token, options = {}
-
(Subscription)
- The newly created subscription.
Options Hash:
(**:options)
-
:authenticate_on_unsubscribe
(Boolean
) --
Parameters:
-
options
(Hash
) -- Additional options for confirming the -
token
(String
) -- Short-lived token sent to an endpoint
def confirm_subscription token, options = {} options[:authenticate_on_unsubscribe] = 'true' if options[:authenticate_on_unsubscribe] confirm_opts = options.merge(:token => token, :topic_arn => arn) resp = client.confirm_subscription(confirm_opts) Subscription.new( resp[:subscription_arn], :topic_arn => arn, :config => config) end
def delete
-
(nil)
-
def delete client.delete_topic(:topic_arn => arn) nil end
def delivery_policy_json
-
(nil, String
- The delivery policy JSON string.)
def delivery_policy_json to_h[:delivery_policy_json] end
def display_name
-
(String)
- Returns the human-readable name used in
def display_name to_h[:display_name] end
def display_name= display_name
-
(String)
- Returns the display_name as passed.
Parameters:
-
display_name
(String
) -- Sets the human-readable name used in
def display_name= display_name set_attribute('DisplayName', display_name) display_name end
def effective_delivery_policy_json
-
(String
- The effective delivery policy JSON string.)
def effective_delivery_policy_json to_h[:effective_delivery_policy_json] end
def endpoint_opts(endpoint, opts = {})
def endpoint_opts(endpoint, opts = {}) case when endpoint.is_a?(SQS::Queue) # auto add a policy to the queue to allow the topic # to send the queue messages unless opts[:update_policy] == false policy = endpoint.policy || SQS::Policy.new policy.allow( :principal => :any, :actions => [:send_message], :resources => [endpoint] ).where(:source_arn).is(arn) endpoint.policy = policy end { :protocol => 'sqs', :endpoint => endpoint.arn } when endpoint =~ /^arn:/ raise ArgumentError, "expected a queue ARN" unless endpoint =~ /^arn:aws:sqs:/ { :protocol => "sqs", :endpoint => endpoint } when endpoint.kind_of?(URI) { :protocol => endpoint.scheme, :endpoint => endpoint.to_s } when endpoint =~ /^(https?):/ { :protocol => $1, :endpoint => endpoint } when endpoint.include?("@") { :protocol => opts[:json] ? "email-json" : "email", :endpoint => endpoint } when endpoint.gsub(/\D/,'') =~ /\d{11,15}/ { :protocol => "sms", :endpoint => endpoint.gsub(/\D/,'') } else raise ArgumentError, "could not determine protocol for '#{endpoint}'" end end
def eql? other
-
(Boolean)
- Returns true if compared to another {Topic}
def eql? other other.kind_of?(Topic) and other.arn == arn end
def initialize arn, options = {}
-
arn
(String
) -- The topic ARN.
def initialize arn, options = {} @arn = arn super end
def name
-
(String)
- Returns the toipc name.
def name arn.split(/:/)[-1] end
def num_subscriptions_confirmed
-
(Integer)
- Returns number of confirmed topic subscriptions.
def num_subscriptions_confirmed to_h[:num_subscriptions_confirmed] end
def num_subscriptions_deleted
-
(Integer)
- Returns number of deleted topic subscriptions.
def num_subscriptions_deleted to_h[:num_subscriptions_deleted] end
def num_subscriptions_pending
-
(Integer)
- Returns number of pending topic subscriptions.
def num_subscriptions_pending to_h[:num_subscriptions_pending] end
def owner
-
(String)
- The topic owner's ID.
def owner to_h[:owner] end
def parse_policy policy_json
def parse_policy policy_json if policy_json policy = SNS::Policy.from_json(policy_json) policy.extend(PolicyProxy) policy.topic = self policy else nil end end
def policy
-
(Policy)
- The topic's {Policy}.
def policy to_h[:policy] end
def policy= policy
-
(nil)
-
Parameters:
-
policy
(String, Policy
) -- A JSON policy string, a {Policy} object
def policy= policy policy_json = policy.is_a?(String) ? policy : policy.to_json set_attribute('Policy', policy_json) nil end
def publish default_message, options = {}
-
(String)
- Returns the ID of the message that was sent.
Options Hash:
(**options)
-
:sqs
(String
) -- - Message to use when sending to an -
:email_json
(String
) -- - Message to use when sending -
:email
(String
) -- - Message to use when sending to an -
:https
(String
) -- - Message to use when sending to an -
:http
(String
) -- - Message to use when sending to an -
:subject
(String
) -- Used as the "Subject" line when
Parameters:
-
options
(Hash
) -- -
default_message
(String
) -- The message you want to send to the
def publish default_message, options = {} message = { :default => default_message } [:http, :https, :email, :email_json, :sqs].each do |protocol| if options[protocol] message[protocol.to_s.gsub(/_/, '-')] = options[protocol] end end publish_opts = {} publish_opts[:message] = message.to_json publish_opts[:message_structure] = 'json' publish_opts[:subject] = options[:subject] if options[:subject] publish_opts[:topic_arn] = arn response = client.publish(publish_opts) response[:message_id] end
def set_attribute name, value
def set_attribute name, value client.send(:set_topic_attributes, { :topic_arn => arn, :attribute_name => name, :attribute_value => value, }) end
def subscribe endpoint, options = {}
-
(Subscription, nil)
- Returns a subscription when possible.
Options Hash:
(**options)
-
:json
(Boolean
) --
Parameters:
-
options
(Hash
) -- -
endpoint
(mixed
) -- The endpoint that should receive
Other tags:
- Example: SQS Queue (by Queue object) -
Example: SQS Queue (by arn) -
Example: Email address as a JSON endpoint -
Example: Email address as endpoint -
Example: Using a uri object to set the endpoint (http and https) -
Example: Using a url string to set the endpoint (http and https) -
def subscribe endpoint, options = {} subscribe_opts = endpoint_opts(endpoint, options).merge(:topic_arn => arn) resp = client.subscribe(subscribe_opts) if arn = resp[:subscription_arn] and arn =~ /^arn:/ Subscription.new(arn, :config => config) else nil end end
def subscriptions
-
(TopicSubscriptionCollection)
- Returns a collection that
def subscriptions TopicSubscriptionCollection.new(self) end
def to_h
-
(Hash)
- Returns a hash of attributes about this topic,
def to_h attributes = client.get_topic_attributes(:topic_arn => arn).attributes { :arn => arn, :name => name, :owner => attributes['Owner'], :display_name => attributes['DisplayName'] || name, :policy => parse_policy(attributes['Policy']), :num_subscriptions_confirmed => attributes['SubscriptionsConfirmed'].to_i, :num_subscriptions_pending => attributes['SubscriptionsPending'].to_i, :num_subscriptions_deleted => attributes['SubscriptionsDeleted'].to_i, :delivery_policy_json => attributes['DeliveryPolicy'], :effective_delivery_policy_json => attributes['EffectiveDeliveryPolicy'], } end
def update_delivery_policy policy_json
def update_delivery_policy policy_json set_attribute('DeliveryPolicy', policy_json) end