Commit c996ca4b authored by Robert Speicher's avatar Robert Speicher

Add application

parent 2df9a52c
# HTTP Basic Auth
AUTH_USERNAME="username"
AUTH_PASSWORD="password"
# Marketo API
MRKT_HOST=""
MRKT_ID=""
MRKT_SECRET=""
require 'json'
require './lib/marketo_client'
require './lib/user'
class MarketoTools < Sinatra::Base
use Rack::Auth::Basic do |username, password|
username == ENV['AUTH_USERNAME'] && password == ENV['AUTH_PASSWORD']
end
# Receives GitLab System Hooks
#
# Specifically, we're interested in the `user_create` event.
#
# See http://gitlab.com/help/system_hooks/system_hooks
post '/' do
begin
params = JSON.parse(request.body.read)
rescue JSON::ParserError
params = {}
end
if params['event_name'] == 'user_create'
user = User.new(params)
# TODO (rspeicher): Do we need to do anything with this besides
# create/update a lead?
client.createupdate_leads([user.to_param], lookup_field: :email)
end
# https://dev.gitlab.org/gitlab/mailchimp-tools/commit/a93a0b97a906008e97c0fe6eccdf09ce32f944ea
'success'
end
private
def client
@client ||= MarketoClient.new
end
end
require 'bundler'
Bundler.require
Dotenv.load
require './app'
run MarketoTools
class MarketoClient < SimpleDelegator
attr_reader :client
def initialize
@client = Mrkt::Client.new(
host: ENV['MRKT_HOST'],
client_id: ENV['MRKT_ID'],
client_secret: ENV['MRKT_SECRET']
)
super(@client)
end
end
class User
include FullNameSplitter
attr_accessor :first_name, :last_name, :email
def initialize(params)
self.full_name = params['name']
self.email = params['email']
end
def to_param
{
email: email,
firstName: first_name,
lastName: last_name
}
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment