{"size": 1072, "ext": "js", "max_stars_repo_path": "SNSAdapter.js", "max_stars_repo_name": "oclef/parseServer", "max_stars_repo_stars_event_min_datetime": "2016-11-23T14:33:36.000Z", "max_stars_repo_stars_event_max_datetime": "2016-11-23T14:33:36.000Z", "max_issues_repo_path": "SNSAdapter.js", "max_issues_repo_name": "oclef/parseServer", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SNSAdapter.js", "max_forks_repo_name": "oclef/parseServer", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.3636363636, "max_line_length": 68, "alphanum_fraction": 0.6809701493}
// SNSAdapter
//
// Uses SNS for push notification

var AWS = require('aws-sdk');
var path = require('path');

var DEFAULT_REGION = "us-east-1";

// Publish to an SNS endpoint
// Providing AWS access and secret keys is mandatory
// Region will use sane defaults if omitted
function SNSAdapter(accessKey, secretKey, options) {
  options = options || {};

  this.region = options.region || DEFAULT_REGION;

  AWS.config.update({
    accessKeyId: accessKey,
    secretAccessKey: secretKey,
    region: options.region || DEFAULT_REGION
  });
  
  this.sns = new AWS.SNS();
}

// For a given config object, endpoint and payload, publish via SNS
// Returns a promise containing the SNS object publish response
SNSAdapter.prototype.publish = function(config, endpoint, payload) {

  var params = {
    Message: payload,
    MessageStructure: 'json',
    TargetArn: endpoint
  };
  return new Promise((resolve, reject) => {
    this.sns.publish(params, (err, data) => {
      if (err !== null) return reject(err);
      resolve(data);
    });
  });
}

module.exports = SNSAdapter;