2014-08-10 02:11:26 -04:00
|
|
|
config = require '../server_config'
|
|
|
|
request = require 'request'
|
|
|
|
log = require 'winston'
|
|
|
|
|
2016-09-14 14:50:25 -04:00
|
|
|
DELIGHTED_EMAIL_DELAY = 10 * 86400 # in seconds
|
2014-08-10 02:11:26 -04:00
|
|
|
|
2016-04-07 14:19:12 -04:00
|
|
|
module.exports.addDelightedUser = addDelightedUser = (user, trialRequest) ->
|
|
|
|
props = trialRequest.get('properties')
|
|
|
|
name = props.firstName + ' ' + props.lastName
|
2014-08-10 02:11:26 -04:00
|
|
|
form =
|
2016-04-07 14:19:12 -04:00
|
|
|
email: props.email
|
2014-08-10 02:11:26 -04:00
|
|
|
name: name
|
|
|
|
delay: DELIGHTED_EMAIL_DELAY
|
|
|
|
properties:
|
2016-04-07 14:19:12 -04:00
|
|
|
id: trialRequest.get('applicant')
|
2014-08-10 02:11:26 -04:00
|
|
|
locale: user.get('preferredLanguage')
|
|
|
|
testGroupNumber: user.get('testGroupNumber')
|
|
|
|
gender: user.get('gender')
|
|
|
|
lastLevel: user.get('lastLevel')
|
2016-06-17 16:53:49 -04:00
|
|
|
state: if props.nces_id and props.country is 'USA' then props.state else 'other'
|
2016-09-14 14:50:25 -04:00
|
|
|
|
2016-04-07 14:19:12 -04:00
|
|
|
@postPeople(form)
|
2016-09-14 14:50:25 -04:00
|
|
|
|
2016-04-07 14:19:12 -04:00
|
|
|
module.exports.postPeople = (form) ->
|
|
|
|
return unless key = config.mail.delightedAPIKey
|
2014-08-10 02:11:26 -04:00
|
|
|
request.post {uri: "https://#{key}:@api.delightedapp.com/v1/people.json", form: form}, (err, res, body) ->
|
2014-08-28 22:39:46 -04:00
|
|
|
return log.error 'Error sending Delighted request:', err or body if err or /error/i.test body
|
2014-08-10 02:11:26 -04:00
|
|
|
#log.info "Got DelightedApp response: #{body}"
|