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

Inherits:
Object
  • Object
show all
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 Method Summary collapse

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.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fog/aws/sns.rb', line 51

def initialize(options={})
  require 'multi_json'
  @aws_access_key_id      = options[:aws_access_key_id]
  @aws_secret_access_key  = options[:aws_secret_access_key]
  @connection_options     = options[:connection_options] || {}
  @hmac       = Fog::HMAC.new('sha256', @aws_secret_access_key)

  options[:region] ||= 'us-east-1'
  @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::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
end

Instance Method Details

#add_permission(options = {}) ⇒ Object



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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

#reloadObject



68
69
70
# File 'lib/fog/aws/sns.rb', line 68

def reload
  @connection.reset
end

#remove_permission(options = {}) ⇒ Object



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

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



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

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



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

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



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

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