Init create_lead, fix MailblusterHelper name

This commit is contained in:
Ziyi 2021-03-13 15:22:19 -08:00 committed by CactusPuppy
parent 5739c05a94
commit 7f60f8aace
No known key found for this signature in database
GPG key ID: 4B33B0A3E15E2C82
2 changed files with 21 additions and 4 deletions

View file

@ -1,9 +1,26 @@
# frozen_string_literal: true
module External
module Mailbluster
module MailblusterHelper
def create_lead(user)
# TODO
begin
uri = URI("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 = {'firstName' => user.name,
'email' => user.email,
'subscribed' => true,
'tags' => ["snapcon"],
'overrideExisting' => true}.to_json
response = http.request(request)
puts response
return true
rescue => e
puts "ERROR #{e}"
return false
end
end
end
end
end

View file

@ -3,7 +3,7 @@
require 'spec_helper'
require 'webmock/rspec'
describe MailblusterHelper, type: :helper do
describe External::MailblusterHelper, type: :helper do
let!(:user) { create(:user) }
describe 'create_lead' do
@ -13,4 +13,4 @@ describe MailblusterHelper, type: :helper do
with { |req| req.body == "abc" }
end
end
end
end