Refactor Mailbluster API URL into a constant
This commit is contained in:
parent
1f3832c883
commit
633d62d729
1 changed files with 23 additions and 24 deletions
47
app/helpers/external/mailbluster_helper.rb
vendored
47
app/helpers/external/mailbluster_helper.rb
vendored
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue