{"size": 743, "ext": "js", "max_stars_repo_path": "subscription.js", "max_stars_repo_name": "tekwrks/emailer", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "subscription.js", "max_issues_repo_name": "tekwrks/emailer", "max_issues_repo_issues_event_min_datetime": "2019-11-04T19:07:56.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-06T11:54:30.000Z", "max_forks_repo_path": "subscription.js", "max_forks_repo_name": "multiplio/mailgun", "max_forks_repo_forks_event_min_datetime": "2018-11-08T23:16:50.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-08T23:16:50.000Z"}
{"max_stars_count": null, "max_issues_count": 4, "max_forks_count": 1, "avg_line_length": 21.8529411765, "max_line_length": 95, "alphanum_fraction": 0.5074024226}
const logger = require('./logger')

module.exports = function (mailgun) {
  const updateSub = function (email, sub) {
    mailgun
      .lists(`users@${process.env.MAILGUN_DOMAIN}`)
      .members(email)
      .update(
        {
          subscribed: sub,
        },
        function (err, body) {
          if (err) {
            logger.error(`could not ${sub ? '' : 'un'}subscribe : ${email} : ${err} : ${body}`)
          }
          else {
            logger.debug(`${sub ? '' : 'un'}subscribed : ${email} : ${body}`)
          }
        })
  }
  const unsubscribe = function (email) {
    updateSub(email, false)
  }
  const subscribe = function (email) {
    updateSub(email, true)
  }

  return {
    subscribe,
    unsubscribe,
  }
}

