-
-
Save walker/b356d70b67b4340de739 to your computer and use it in GitHub Desktop.
BSD Spud Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPUD HELPER | |
function getUniversalProfile(cb) { | |
var bsd_fields = ['firstname', 'lastname', 'email', 'phone', 'addr1', 'addr2', 'city', 'state_cd', 'zip']; | |
bQuery.bsd.spud( | |
'get', | |
bsd_fields, | |
{ | |
success: function (data) { | |
test_msg("BSD data:", data); | |
cb(build_user(data)); | |
} | |
} | |
); | |
} | |
// build user profile | |
function build_user(user) { | |
test_msg("Build user:"); | |
user.firstname = user_prop("firstname", "first_name"); | |
user.lastname = user_prop("lastname", "last_name"); | |
user.email = user_prop("email", "email"); | |
user.phone = user_prop("phone", "phone"); | |
user.addr1 = user_prop("addr1", "home_addr2"); | |
user.addr2 = user_prop("addr2", "home_addr2"); | |
user.city = user_prop("city", "home_city"); | |
user.state = user_prop("state_cd", "home_state"); | |
user.zip = user_prop("zip", "home_zip"); | |
if(typeof(mixpanel)!='undefined') | |
user.ip = mixpanel.get_property("uip"); | |
test_msg(user); | |
return user; | |
// helpers | |
function user_prop(bsd_field_name, mix_field_name) { | |
if (user[bsd_field_name]) return user[bsd_field_name]; | |
else if (typeof(mixpanel)!='undefined' && mixpanel.get_property(mix_field_name)) return mixpanel.get_property(mix_field_name); | |
else return undefined; | |
} | |
} | |
/* | |
Example: | |
getUniversalProfile(function(user) { | |
console.log(user); | |
}); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment