Class: AWS::SNS::Subscription

Inherits:
Object
  • Object
show all
Includes:
Core::Model, HasDeliveryPolicy
Defined in:
lib/aws/sns/subscription.rb

Overview

Represents a subscription of a single endpoint to an SNS topic. To create a subscription, use the Topic#subscribe method. Depending on the endpoint type, you may also need to use Topic#confirm_subscription.

Instance Attribute Summary collapse

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods included from HasDeliveryPolicy

#delivery_policy, #delivery_policy=, #effective_delivery_policy

Methods included from Core::Model

#client, #config_prefix

Constructor Details

#initialize(arn, opts = {}) ⇒ Subscription

Returns a new instance of Subscription.


27
28
29
30
31
32
33
34
# File 'lib/aws/sns/subscription.rb', line 27

def initialize(arn, opts = {})
  @arn = arn
  @topic_arn = opts[:topic_arn]
  @endpoint = opts[:endpoint]
  @protocol = opts[:protocol]
  @owner_id = opts[:owner_id]
  super
end

Instance Attribute Details

#arnString (readonly)

Returns The ARN of the subscription.

Returns:

  • (String)

    The ARN of the subscription.


37
38
39
# File 'lib/aws/sns/subscription.rb', line 37

def arn
  @arn
end

#endpointString (readonly)

URL, an e-mail address, or a queue ARN.

Returns:

  • (String)

    The endpoint. This can be an HTTP or HTTPS


41
42
43
# File 'lib/aws/sns/subscription.rb', line 41

def endpoint
  @endpoint
end

#protocolString (readonly)

Returns The protocol. Possible values:

  • :http

  • :https

  • :email

  • :email_json

  • :sqs.

Returns:

  • (String)

    The protocol. Possible values:

    • :http

    • :https

    • :email

    • :email_json

    • :sqs


50
51
52
# File 'lib/aws/sns/subscription.rb', line 50

def protocol
  @protocol
end

Instance Method Details

#confirmation_authenticated?Boolean

Returns true if the subscription confirmation request was authenticated.

Returns:

  • (Boolean)

    Returns true if the subscription confirmation request was authenticated.


76
77
78
79
80
81
82
83
84
85
86
# File 'lib/aws/sns/subscription.rb', line 76

def confirmation_authenticated?

  return true if @authenticated

  if authenticated = get_attributes['ConfirmationWasAuthenticated']
    @authenticated = true
  else
    false
  end

end

#delivery_policy_jsonnil, String

You can get the parsed JSON hash from HasDeliveryPolicy#delivery_policy.

Returns:

  • (nil, String)

    Returns the delivery policy JSON string.


90
91
92
# File 'lib/aws/sns/subscription.rb', line 90

def delivery_policy_json
  get_attributes['DeliveryPolicy']
end

#effective_delivery_policy_jsonnil, String

You can get the parsed JSON hash from HasDeliveryPolicy#effective_delivery_policy.

Returns:

  • (nil, String)

    Returns the effective delivery policy JSON string.


96
97
98
# File 'lib/aws/sns/subscription.rb', line 96

def effective_delivery_policy_json
  get_attributes['EffectiveDeliveryPolicy']
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns true if the subscriptions have the same resource ARN.

Returns:

  • (Boolean)

    Returns true if the subscriptions have the same resource ARN.


122
123
124
# File 'lib/aws/sns/subscription.rb', line 122

def eql? other
  other.kind_of?(Subscription) and other.arn == arn
end

#exists?Boolean

Note:

This method requests the entire list of subscriptions for the topic (if known) or the account (if the topic is not known). It can be expensive if the number of subscriptions is high.

Returns true if the subscription exists.

Returns:

  • (Boolean)

    Returns true if the subscription exists.


106
107
108
109
110
111
112
113
# File 'lib/aws/sns/subscription.rb', line 106

def exists?
  begin
    get_attributes
    true
  rescue Errors::NotFound, Errors::InvalidParameter
    false
  end
end

#inspectObject


116
117
118
# File 'lib/aws/sns/subscription.rb', line 116

def inspect
  "<#{self.class} arn:#{arn}>"
end

#owner_idString

Returns The AWS account ID of the subscription owner.

Returns:

  • (String)

    The AWS account ID of the subscription owner.


53
54
55
# File 'lib/aws/sns/subscription.rb', line 53

def owner_id
  @owner_id ||= get_attributes['Owner']
end

#topicTopic

Returns:


63
64
65
# File 'lib/aws/sns/subscription.rb', line 63

def topic
  Topic.new(topic_arn, :config => config)  
end

#topic_arnString

Returns:

  • (String)

58
59
60
# File 'lib/aws/sns/subscription.rb', line 58

def topic_arn
  @topic_arn ||= get_attributes['TopicArn']
end

#unsubscribenil

Deletes this subscription.

Returns:

  • (nil)

69
70
71
72
# File 'lib/aws/sns/subscription.rb', line 69

def unsubscribe
  client.unsubscribe(:subscription_arn => arn)
  nil
end