Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Report Subscription Confirmation #4

Open
wants to merge 2 commits into from

1 participant

@txase

This branch reports the subscription confirmation message to the client callback. The only way to get the subscription ARN, used for modifying a subscription, is by parsing the confirmation message.

txase added some commits
@txase txase Check for successful subscription confirmation response fc5dd4c
@txase txase Report subscription confirmation message too
The only way to get the subscription ARN, which is required for modifying
the subscription, is by parsing the subscription confirmation message.
This change calls the supplied callback for the confirmation message so
the client can get the ARN and any other data it needs.
f867c05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 26, 2012
  1. @txase
  2. @txase

    Report subscription confirmation message too

    txase authored
    The only way to get the subscription ARN, which is required for modifying
    the subscription, is by parsing the subscription confirmation message.
    This change calls the supplied callback for the confirmation message so
    the client can get the ARN and any other data it needs.
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 2 deletions.
  1. +21 −2 lib/snsclient.js
View
23 lib/snsclient.js
@@ -1,6 +1,7 @@
var https = require('https')
, crypto = require('crypto')
- , url = require('url');
+ , url = require('url')
+ , xml2js = require('xml2js');
// Local memory cache for PEM certificates
var pem_cache = {};
@@ -123,7 +124,25 @@ function SNSClient(opts, cb) {
validateRequest(opts, message, function(err){
if(err) return;
if(message.Type === 'SubscriptionConfirmation') {
- return https.get(url.parse(message.SubscribeURL));
+ https.get(url.parse(message.SubscribeURL), function(req) {
+ if (req.statusCode != 200) {
+ return cb(new Error('Error confirming subscription'));
+ }
+ var response = '';
+ req.on('data', function(chunk) {
+ response += chunk;
+ });
+ req.on('end', function() {
+ var parser = new xml2js.Parser();
+ parser.addListener('end', function(result) {
+ if (typeof result != 'undefined' && typeof result.Errors != 'undefined') {
+ cb(new Error('Error parsing subscription confirmation response XML'));
+ }
+ return cb(null, result);
+ });
+ parser.parseString(response);
+ });
+ });
}
if(message.Type === 'Notification') {
return cb(null, message);
Something went wrong with that request. Please try again.