Class: Fog::AWS::SNS::Real

Inherits:
Object
  • Object
show all
Includes:
CredentialFetcher::ConnectionMethods
Defined in:
lib/fog/aws/sns.rb,
lib/fog/aws/requests/sns/publish.rb,
lib/fog/aws/requests/sns/subscribe.rb,
lib/fog/aws/requests/sns/list_topics.rb,
lib/fog/aws/requests/sns/unsubscribe.rb,
lib/fog/aws/requests/sns/create_topic.rb,
lib/fog/aws/requests/sns/delete_topic.rb,
lib/fog/aws/requests/sns/add_permission.rb,
lib/fog/aws/requests/sns/remove_permission.rb,
lib/fog/aws/requests/sns/list_subscriptions.rb,
lib/fog/aws/requests/sns/confirm_subscription.rb,
lib/fog/aws/requests/sns/get_topic_attributes.rb,
lib/fog/aws/requests/sns/set_topic_attributes.rb,
lib/fog/aws/requests/sns/list_subscriptions_by_topic.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CredentialFetcher::ConnectionMethods

#refresh_credentials_if_expired

Constructor Details

#initialize(options = {}) ⇒ Real

Initialize connection to SNS

Notes

options parameter must include values for :aws_access_key_id and :aws_secret_access_key in order to create a connection

Examples

sns = SNS.new(
 :aws_access_key_id => your_aws_access_key_id,
 :aws_secret_access_key => your_aws_secret_access_key
)

Parameters

  • options<~Hash> - config arguments for connection. Defaults to {}.

Returns

  • SNS object with connection to AWS.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/fog/aws/sns.rb', line 81

def initialize(options={})
  @use_iam_profile = options[:use_iam_profile]
  @connection_options     = options[:connection_options] || {}
  @instrumentor       = options[:instrumentor]
  @instrumentor_name  = options[:instrumentor_name] || 'fog.aws.sns'

  options[:region] ||= 'us-east-1'
  @region = options[:region]
  @host = options[:host] || "sns.#{options[:region]}.amazonaws.com"

  @path       = options[:path]        || '/'
  @persistent = options[:persistent]  || false
  @port       = options[:port]        || 443
  @scheme     = options[:scheme]      || 'https'
  @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)

  setup_credentials(options)
end

Instance Attribute Details

#regionObject (readonly)

Returns the value of attribute region.



100
101
102
# File 'lib/fog/aws/sns.rb', line 100

def region
  @region
end

Instance Method Details

#add_permission(options = {}) ⇒ Object



7
8
9
10
11
12
# File 'lib/fog/aws/requests/sns/add_permission.rb', line 7

def add_permission(options = {})
  request({
    'Action'  => 'AddPermission',
    :parser   => Fog::Parsers::AWS::SNS::AddPermission.new
  }.merge!(options))
end

#confirm_subscription(arn, token, options = {}) ⇒ Object

Confirm a subscription

Parameters

  • arn<~String> - Arn of topic to confirm subscription to

  • token<~String> - Token sent to endpoint during subscribe action

  • options<~Hash>:

    • AuthenticateOnUnsubscribe<~Boolean> - whether or not unsubscription should be authenticated, defaults to false

See Also

docs.amazonwebservices.com/sns/latest/api/API_ConfirmSubscription.html



19
20
21
22
23
24
25
26
# File 'lib/fog/aws/requests/sns/confirm_subscription.rb', line 19

def confirm_subscription(arn, token, options = {})
  request({
    'Action'    => 'ConfirmSubscription',
    'Token'     => token,
    'TopicArn'  => arn.strip,
    :parser     => Fog::Parsers::AWS::SNS::ConfirmSubscription.new
  }.merge!(options))
end

#create_topic(name) ⇒ Object

Create a topic

Parameters

  • name<~String> - Name of topic to create

See Also

docs.amazonwebservices.com/sns/latest/api/API_CreateTopic.html



16
17
18
19
20
21
22
# File 'lib/fog/aws/requests/sns/create_topic.rb', line 16

def create_topic(name)
  request({
    'Action'  => 'CreateTopic',
    'Name'    => name,
    :parser   => Fog::Parsers::AWS::SNS::CreateTopic.new
  })
end

#delete_topic(arn) ⇒ Object

Delete a topic

Parameters

  • arn<~String> - The Arn of the topic to delete

See Also

docs.amazonwebservices.com/sns/latest/api/API_DeleteTopic.html



16
17
18
19
20
21
22
# File 'lib/fog/aws/requests/sns/delete_topic.rb', line 16

def delete_topic(arn)
  request({
    'Action'    => 'DeleteTopic',
    'TopicArn'  => arn.strip,
    :parser     => Fog::Parsers::AWS::SNS::DeleteTopic.new
  })
end

#get_topic_attributes(arn) ⇒ Object

Get attributes of a topic

Parameters

  • arn<~Hash>: The Arn of the topic to get attributes for

See Also

docs.amazonwebservices.com/sns/latest/api/API_GetTopicAttributes.html



16
17
18
19
20
21
22
# File 'lib/fog/aws/requests/sns/get_topic_attributes.rb', line 16

def get_topic_attributes(arn)
  request({
    'Action'    => 'GetTopicAttributes',
    'TopicArn'  => arn.strip,
    :parser     => Fog::Parsers::AWS::SNS::GetTopicAttributes.new
  })
end

#list_subscriptions(options = {}) ⇒ Object

List subscriptions

Parameters

  • options<~Hash>:

    • ‘NextToken’<~String> - Token returned from previous request, used for pagination

See Also

docs.amazonwebservices.com/sns/latest/api/API_ListSubscriptions.html



17
18
19
20
21
22
# File 'lib/fog/aws/requests/sns/list_subscriptions.rb', line 17

def list_subscriptions(options = {})
  request({
    'Action' => 'ListSubscriptions',
    :parser  => Fog::Parsers::AWS::SNS::ListSubscriptions.new
  }.merge!(options))
end

#list_subscriptions_by_topic(arn, options = {}) ⇒ Object

List subscriptions for a topic

Parameters

  • arn<~String> - Arn of topic to list subscriptions for

  • options<~Hash>:

    • ‘NextToken’<~String> - Token returned from previous request, used for pagination

See Also

docs.amazonwebservices.com/sns/latest/api/API_ListSubscriptionsByTopic.html



18
19
20
21
22
23
24
# File 'lib/fog/aws/requests/sns/list_subscriptions_by_topic.rb', line 18

def list_subscriptions_by_topic(arn, options = {})
  request({
    'Action'    => 'ListSubscriptionsByTopic',
    'TopicArn'  => arn.strip,
    :parser     => Fog::Parsers::AWS::SNS::ListSubscriptions.new
  }.merge!(options))
end

#list_topics(options = {}) ⇒ Object

List topics

Parameters

  • options<~Hash>:

    • ‘NextToken’<~String> - Token returned from previous request, used for pagination

See Also

docs.amazonwebservices.com/sns/latest/api/API_ListTopics.html



17
18
19
20
21
22
# File 'lib/fog/aws/requests/sns/list_topics.rb', line 17

def list_topics(options = {})
  request({
    'Action'  => 'ListTopics',
    :parser   => Fog::Parsers::AWS::SNS::ListTopics.new
  }.merge!(options))
end

#publish(arn, message, options = {}) ⇒ Object

Send a message to a topic

Parameters

  • arn<~String> - Arn of topic to send message to

  • message<~String> - Message to send to topic

  • options<~Hash>:

    • MessageStructure<~String> - message structure, in [‘json’]

    • Subject<~String> - value to use for subject when delivering by email

See Also

docs.amazonwebservices.com/sns/latest/api/API_Publish.html



20
21
22
23
24
25
26
27
# File 'lib/fog/aws/requests/sns/publish.rb', line 20

def publish(arn, message, options = {})
  request({
    'Action'    => 'Publish',
    'Message'   => message,
    'TopicArn'  => arn.strip,
    :parser     => Fog::Parsers::AWS::SNS::Publish.new
  }.merge!(options))
end

#reloadObject



102
103
104
# File 'lib/fog/aws/sns.rb', line 102

def reload
  @connection.reset
end

#remove_permission(options = {}) ⇒ Object



7
8
9
10
11
12
# File 'lib/fog/aws/requests/sns/remove_permission.rb', line 7

def remove_permission(options = {})
  request({
    'Action'  => 'RemovePermission',
    :parser   => Fog::Parsers::AWS::SNS::RemovePermission.new
  }.merge!(options))
end

#set_topic_attributes(arn, attribute_name, attribute_value) ⇒ Object

Set attributes of a topic

Parameters

  • arn<~Hash> - The Arn of the topic to get attributes for

  • attribute_name<~String> - Name of attribute to set, in [‘DisplayName’, ‘Policy’]

  • attribute_value<~String> - Value to set attribute to

See Also

docs.amazonwebservices.com/sns/latest/api/API_SetTopicAttributes.html



18
19
20
21
22
23
24
25
26
# File 'lib/fog/aws/requests/sns/set_topic_attributes.rb', line 18

def set_topic_attributes(arn, attribute_name, attribute_value)
  request({
    'Action'          => 'SetTopicAttributes',
    'AttributeName'   => attribute_name,
    'AttributeValue'  => attribute_value,
    'TopicArn'        => arn.strip,
    :parser     => Fog::Parsers::AWS::SNS::SetTopicAttributes.new
  })
end

#subscribe(arn, endpoint, protocol) ⇒ Object

Create a subscription

Parameters

  • arn<~String> - Arn of topic to subscribe to

  • endpoint<~String> - Endpoint to notify

  • protocol<~String> - Protocol to notify endpoint with, in [‘email’, ‘email-json’, ‘http’, ‘https’, ‘sqs’]

See Also

docs.amazonwebservices.com/sns/latest/api/API_Subscribe.html



18
19
20
21
22
23
24
25
26
# File 'lib/fog/aws/requests/sns/subscribe.rb', line 18

def subscribe(arn, endpoint, protocol)
  request({
    'Action'    => 'Subscribe',
    'Endpoint'  => endpoint,
    'Protocol'  => protocol,
    'TopicArn'  => arn.strip,
    :parser     => Fog::Parsers::AWS::SNS::Subscribe.new
  })
end

#unsubscribe(arn) ⇒ Object

Delete a subscription

Parameters

  • arn<~String> - Arn of subscription to delete

See Also

docs.amazonwebservices.com/sns/latest/api/API_Unsubscribe.html



16
17
18
19
20
21
22
# File 'lib/fog/aws/requests/sns/unsubscribe.rb', line 16

def unsubscribe(arn)
  request({
    'Action'          => 'Unsubscribe',
    'SubscriptionArn' => arn.strip,
    :parser           => Fog::Parsers::AWS::SNS::Unsubscribe.new
  })
end