Class: RightAws::Sns

Inherits:
Object
  • Object
show all
Defined in:
lib/sns/right_sns.rb

Overview

RightAws::Sns – RightScale’s Amazon SNS interface

The RightAws::Sns class provides a complete interface to Amazon’s Simple Notification Service. For explanations of the semantics of each call, please refer to Amazon’s documentation at docs.amazonwebservices.com/sns/2010-03-31/api/

Error handling: all operations raise an RightAws::AwsError in case of problems. Note that transient errors are automatically retried.

sns    = RightAws::Sns.new(aws_access_key_id, aws_secret_access_key)
topics = sns.topics #=> [<Sns::Topic>, <Sns::Topic>]
topic1 = sns.create_topic('bananas') #=> <Sns::Topic>
topic1.subscribe('email', '[email protected]') #=> true
 ...
topic1.send_message('Some content', 'An optional subject')

Params is a hash:

{:server       => 'sns.us-east-1.amazonaws.com' # Amazon service host: 'sns.us-east-1.amazonaws.com' (default)
 :port         => 443                   # Amazon service port: 80 or 443 (default)
 :multi_thread => true|false            # Multi-threaded (connection per each thread): true or false (default)
 :signature_version => '0'              # The signature version : '0' or '1'(default)
 :logger       => Logger Object}        # Logger instance: logs to STDOUT if omitted }

Defined Under Namespace

Classes: Member, Message, Topic

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aws_access_key_id = nil, aws_secret_access_key = nil, params = {}) ⇒ Sns

Returns a new instance of Sns.



55
56
57
# File 'lib/sns/right_sns.rb', line 55

def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
  @interface = SnsInterface.new(aws_access_key_id, aws_secret_access_key, params)
end

Instance Attribute Details

#interfaceObject (readonly)

Returns the value of attribute interface.



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

def interface
  @interface
end

Instance Method Details

#create_topic(name) ⇒ Object

Creates a new topic.



76
77
78
# File 'lib/sns/right_sns.rb', line 76

def create_topic(name)
  @interface.create_topic(self, name)
end

#topic(arn) ⇒ Object

Returns Topic instance by ARN.



71
72
73
# File 'lib/sns/right_sns.rb', line 71

def topic(arn)
  Topic.new(self, arn)
end

#topicsObject

Retrieves a list of topics. Returns an array of Topic instances.

RightAws::Sns.topics #=> array of topics


64
65
66
67
68
# File 'lib/sns/right_sns.rb', line 64

def topics
  @interface.list_topics.map do |arn|
    Topic.new(self, arn)
  end
end