Skip to content

Instantly share code, notes, and snippets.

@roboli
Created April 12, 2018 13:57
Show Gist options
  • Save roboli/361851bee36252a4efa7c602749922be to your computer and use it in GitHub Desktop.
Save roboli/361851bee36252a4efa7c602749922be to your computer and use it in GitHub Desktop.
var DBA_CLIO_URI = 'https://6d821675.ngrok.io/';
var LEAD_GROUP = 51940;
function getUrlVars(url) {
var vars = [], hash;
var hashes = url.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
function checkExperian($) {
return function(lead) {
return $.post(DBA_CLIO_URI + 'experian-check', lead);
};
}
function searchLead($) {
return function(query) {
return $.get(DBA_CLIO_URI + 'leads', query);
};
}
function createLead($) {
return function(lead) {
return $.post(DBA_CLIO_URI + 'leads', lead);
};
}
function updateLead($) {
return function(lead) {
var dfd = $.Deferred();
$.ajax({
url: DBA_CLIO_URI + 'leads',
type: 'PUT',
data: lead,
success: dfd.resolve,
error: dfd.reject
});
return dfd.promise();
};
}
function confirm($) {
return function(leadId, agreed) {
return $.post(DBA_CLIO_URI + 'confirm', {
lead_id: leadId,
agreed: agreed
});
};
}
function dbaClio($) {
return {
uri: DBA_CLIO_URI,
leadGroup: LEAD_GROUP,
checkExperian: checkExperian($),
confirm: confirm($),
createLead: createLead($),
updateLead: updateLead($),
searchLead: searchLead($)
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment