Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support to others protocols than application for subscriptions (eg email or sms) #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,14 @@ Delete the topic with the given topicArn. The callback has the format fn(err).
Send a message to a user. The _message_ parameter can be a String, or an Object with the formats below. The callback format is callback(err, messageId).

#### subscribe(endpointArn, topicArn, callback)
Subscribe an endpoint to a topic. The callback has the format fn(err, subscriptionArn).
Subscribe an endpoint to a topic with the implicit `application` protocol. The callback has the format fn(err, subscriptionArn).

#### unsubscribe(subscriptionArn, callback)
Unsubscribe an endpoint from a topic via the given subscriptionArn. The callback has the format fn(err).

#### subscribeWithProtocol(endpointArn, topicArn, protocol, callback)
Subscribe an endpoint to a topic using a specific protocol such as `email` or `sms`. The callback has the format fn(err, subscriptionArn).

#### publishToTopic(topicArn, message, callback)
Publish a message a topic. The callback has the format fn(err, messageId).
Please note that the message *must* be in the final Amazon SNS format as
Expand Down
18 changes: 15 additions & 3 deletions lib/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,17 +508,18 @@ Interface.prototype._getSubscriptions =


/**
* Subscribe an endpoint to a topic.
* Subscribe an endpoint to a topic with a given protocol.
* @param {String} endpointArn
* @param {String} topicArn
* @param {String} protocol
* @param {Function} callback
*/

Interface.prototype.subscribe = function(endpointArn, topicArn, callback) {
Interface.prototype.subscribeWithProtocol = function(endpointArn, topicArn, protocol, callback) {
var params = {
Endpoint: endpointArn,
TopicArn: topicArn,
Protocol: 'application'
Protocol: protocol
};
var self = this;
self.sns.subscribe(params, function(err, res) {
Expand All @@ -539,6 +540,17 @@ Interface.prototype.subscribe = function(endpointArn, topicArn, callback) {
});
};

/**
* Subscribe an endpoint to a topic.
* @param {String} endpointArn
* @param {String} topicArn
* @param {Function} callback
*/

Interface.prototype.subscribe = function(endpointArn, topicArn, callback) {
subscribeWithProtocol(endpointArn, topicArn, 'application', callback);
};


/**
* Unsubscribe an endpoint from a topic via its SubscriptionArn.
Expand Down