Class: Fog::AWS::SNS::Real
- Inherits:
-
Object
- Object
- Fog::AWS::SNS::Real
- 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
- #add_permission(options = {}) ⇒ Object
-
#confirm_subscription(arn, token, options = {}) ⇒ Object
Confirm a subscription.
-
#create_topic(name) ⇒ Object
Create a topic.
-
#delete_topic(arn) ⇒ Object
Delete a topic.
-
#get_topic_attributes(arn) ⇒ Object
Get attributes of a topic.
-
#initialize(options = {}) ⇒ Real
constructor
Initialize connection to SNS.
-
#list_subscriptions(options = {}) ⇒ Object
List subscriptions.
-
#list_subscriptions_by_topic(arn, options = {}) ⇒ Object
List subscriptions for a topic.
-
#list_topics(options = {}) ⇒ Object
List topics.
-
#publish(arn, message, options = {}) ⇒ Object
Send a message to a topic.
- #reload ⇒ Object
- #remove_permission(options = {}) ⇒ Object
-
#set_topic_attributes(arn, attribute_name, attribute_value) ⇒ Object
Set attributes of a topic.
-
#subscribe(arn, endpoint, protocol) ⇒ Object
Create a subscription.
-
#unsubscribe(arn) ⇒ Object
Delete a subscription.
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 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/fog/aws/sns.rb', line 51 def initialize(={}) require 'multi_json' @aws_access_key_id = [:aws_access_key_id] @aws_secret_access_key = [:aws_secret_access_key] @connection_options = [:connection_options] || {} @hmac = Fog::HMAC.new('sha256', @aws_secret_access_key) [:region] ||= 'us-east-1' @host = [:host] || case [:region] when 'ap-southeast-1' 'sns.ap-southeast-1.amazonaws.com' when 'eu-west-1' 'sns.eu-west-1.amazonaws.com' when 'us-east-1' 'sns.us-east-1.amazonaws.com' when 'us-west-1' 'sns.us-west-1.amazonaws.com' else raise ArgumentError, "Unknown region: #{[:region].inspect}" end @path = [:path] || '/' @persistent = [:persistent] || false @port = [:port] || 443 @scheme = [: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 ( = {}) request({ 'Action' => 'AddPermission', :parser => Fog::Parsers::AWS::SNS::AddPermission.new }.merge!()) 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, = {}) request({ 'Action' => 'ConfirmSubscription', 'Token' => token, 'TopicArn' => arn, :parser => Fog::Parsers::AWS::SNS::ConfirmSubscription.new }.merge!()) 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, :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, :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( = {}) request({ 'Action' => 'ListSubscriptions', :parser => Fog::Parsers::AWS::SNS::ListSubscriptions.new }.merge!()) 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, = {}) request({ 'Action' => 'ListSubscriptionsByTopic', 'TopicArn' => arn, :parser => Fog::Parsers::AWS::SNS::ListSubscriptions.new }.merge!()) 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( = {}) request({ 'Action' => 'ListTopics', :parser => Fog::Parsers::AWS::SNS::ListTopics.new }.merge!()) 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
21 22 23 24 25 26 27 28 |
# File 'lib/fog/aws/requests/sns/publish.rb', line 21 def publish(arn, , = {}) request({ 'Action' => 'Publish', 'Message' => , 'TopicArn' => arn, :parser => Fog::Parsers::AWS::SNS::Publish.new }.merge!()) end |
#reload ⇒ Object
79 80 81 |
# File 'lib/fog/aws/sns.rb', line 79 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 ( = {}) request({ 'Action' => 'RemovePermission', :parser => Fog::Parsers::AWS::SNS::RemovePermission.new }.merge!()) 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, :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, :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, :parser => Fog::Parsers::AWS::SNS::Unsubscribe.new }) end |