class Fog::AWS::SNS::Real

Attributes

region[R]

Public Class Methods

new(options={}) click to toggle source

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.

# 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

Public Instance Methods

add_permission(options = {}) click to toggle source
# 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 = {}) click to toggle source

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

# 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) click to toggle source

Create a topic

Parameters

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

See Also

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

# 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) click to toggle source

Delete a topic

Parameters

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

See Also

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

# 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) click to toggle source

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

# 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 = {}) click to toggle source

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

# 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 = {}) click to toggle source

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

# 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 = {}) click to toggle source

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

# 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 = {}) click to toggle source

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

# 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
reload() click to toggle source
# File lib/fog/aws/sns.rb, line 102
def reload
  @connection.reset
end
remove_permission(options = {}) click to toggle source
# 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) click to toggle source

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

# 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) click to toggle source

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

# 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) click to toggle source

Delete a subscription

Parameters

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

See Also

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

# 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

Private Instance Methods

_request(body, headers, idempotent, parser) click to toggle source
# File lib/fog/aws/sns.rb, line 145
def _request(body, headers, idempotent, parser)
  @connection.request({
    :body       => body,
    :expects    => 200,
    :idempotent => idempotent,
    :headers    => headers,
    :method     => 'POST',
    :parser     => parser
  })
end
request(params) click to toggle source
# File lib/fog/aws/sns.rb, line 117
def request(params)
  refresh_credentials_if_expired

  idempotent  = params.delete(:idempotent)
  parser      = params.delete(:parser)

  body, headers = AWS.signed_params_v4(
    params,
    { 'Content-Type' => 'application/x-www-form-urlencoded' },
    {
      :method             => 'POST',
      :aws_session_token  => @aws_session_token,
      :signer             => @signer,
      :host               => @host,
      :path               => @path,
      :port               => @port
    }
  )

  if @instrumentor
    @instrumentor.instrument("#{@instrumentor_name}.request", params) do
      _request(body, headers, idempotent, parser)
    end
  else
    _request(body, headers, idempotent, parser)
  end
end
setup_credentials(options) click to toggle source
# File lib/fog/aws/sns.rb, line 108
def setup_credentials(options)
  @aws_access_key_id      = options[:aws_access_key_id]
  @aws_secret_access_key  = options[:aws_secret_access_key]
  @aws_session_token     = options[:aws_session_token]
  @aws_credentials_expire_at = options[:aws_credentials_expire_at]

  @signer = Fog::AWS::SignatureV4.new( @aws_access_key_id, @aws_secret_access_key, @region, 'sns')
end