Actually remove redundant code from helpers

This commit is contained in:
CactusPuppy 2021-04-01 21:35:32 -07:00
parent 8c184d4f30
commit b0104cac09
No known key found for this signature in database
GPG key ID: 4B33B0A3E15E2C82

View file

@ -1,64 +0,0 @@
# frozen_string_literal: true
require 'httparty'
module External
module MailblusterHelper
MAILBLUSTER_URL = 'https://api.mailbluster.com/api/leads/'
# def query_api(user, method)
# TODO? General helper for all queries
# end
def create_lead(user)
options = {
headers: {
'Content-Type' => 'application/json',
'Authorization' => ENV['MAILBLUSTER_API_KEY']
},
body: {
'email' => user.email,
'firstName' => user.name,
'overrideExisting' => true,
'subscribed' => true,
'tags' => [ENV['OSEM_NAME'] || 'snapcon']
}.to_json
}
HTTParty.post(MAILBLUSTER_URL, options).parsed_response
rescue StandardError => e
puts "ERROR #{e}"
nil
end
def edit_lead(user, add_tags: [], remove_tags: [], old_email: nil)
options = {
headers: {
'Content-Type' => 'application/json',
'Authorization' => ENV['MAILBLUSTER_API_KEY']
},
body: {
'email' => user.email,
'firstName' => user.name,
'addTags' => add_tags,
'removeTags' => remove_tags
}.to_json
}
email_hash = Digest::MD5.hexdigest(old_email.presence || user.email)
HTTParty.put(MAILBLUSTER_URL + email_hash, options).parsed_response
end
def delete_lead(user)
email_hash = Digest::MD5.hexdigest user.email
options = {
headers: {
'Content-Type' => 'application/json',
'Authorization' => ENV['MAILBLUSTER_API_KEY']
}
}
HTTParty.delete(MAILBLUSTER_URL + email_hash, options).parsed_response
rescue StandardError => e
puts "ERROR #{e}"
nil
end
end
end