Refactor Mailbluster API URL into a constant

This commit is contained in:
CactusPuppy 2021-03-16 15:16:56 -07:00
parent 1f3832c883
commit 633d62d729
No known key found for this signature in database
GPG key ID: 4B33B0A3E15E2C82

View file

@ -2,36 +2,35 @@
module External
module MailblusterHelper
def query_api()
end
MAILBLUSTER_URL = 'https://api.mailbluster.com/api/leads'
def query_api; end
def create_lead(user)
# TODO
begin
uri = URI("http://api.mailbluster.com/api/leads")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.path,
{'Authorization' => ENV["MAILBLUSTER_API_KEY"]}) # TODO Authorization=APIKEY
request.body = {
'email' => user.email,
'firstName' => user.name,
'overrideExisting' => true,
'subscribed' => true,
'tags' => ["snapcon"],
}.to_json
response = http.request(request)
# puts request.body.to_json
# puts response.body.to_json
return response.to_json
rescue => e
puts "ERROR #{e}"
return nil
end
uri = URI(MAILBLUSTER_URL)
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.path,
'Authorization' => ENV['MAILBLUSTER_API_KEY']) # TODO: Authorization=APIKEY
request.body = {
'email' => user.email,
'firstName' => user.name,
'overrideExisting' => true,
'subscribed' => true,
'tags' => ['snapcon']
}.to_json
response = http.request(request)
# puts request.body.to_json
# puts response.body.to_json
response.to_json
rescue StandardError => e
puts "ERROR #{e}"
nil
end
def delete_lead(user)
# TODO
end
end
end