Skip to content

Instantly share code, notes, and snippets.

@joemsak
Last active February 21, 2017 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joemsak/d0e00988e6440edbaf1833ef8187e754 to your computer and use it in GitHub Desktop.
Save joemsak/d0e00988e6440edbaf1833ef8187e754 to your computer and use it in GitHub Desktop.
class MentorProfile < ActiveRecord::Base
# ... omitted
def enable_searchability
# called ONLY from a consent waiver model being saved and
# when a background check model is saved
update_attributes(searchable: can_enable_searchable?)
if can_enable_searchable?
RegistrationMailer.welcome_mentor(account).deliver_later
SubscribeEmailListJob.perform_later(
account.email,
account.full_name,
"MENTOR_LIST_ID",
[{ Key: 'City', Value: city },
{ Key: 'State/Province', Value: state_province },
{ Key: 'Country', Value: Country[country].name }]
)
end
end
# ... omitted
private
def can_enable_searchable?
# the consent waiver model and the background check models must exist!
# this method returns false for those 2,000 subscribes, they're
# not even registered in the database to the current Season model
# (which happens when an existing user logs in again after a certain date
consent_signed? and background_check_complete?
end
# ... omitted
end
class SubscribeEmailListJob < ActiveJob::Base
queue_as :default
def perform(email, name, list_env_key, custom_fields = [])
return if Rails.env.development? or Rails.env.test?
auth = { api_key: ENV.fetch('CAMPAIGN_MONITOR_API_KEY') }
begin
CreateSend::Subscriber.add(auth, ENV.fetch(list_env_key), email, name, custom_fields, true)
rescue CreateSend::BadRequest => br
p "Error: #{br}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment