Skip to content

Instantly share code, notes, and snippets.

@xcambar
Last active June 1, 2018 17:50
Show Gist options
  • Save xcambar/1a50919a28df3871bc86 to your computer and use it in GitHub Desktop.
Save xcambar/1a50919a28df3871bc86 to your computer and use it in GitHub Desktop.
//
// This script shows how to add custom traits to a user
//
var hull = require('hull');
hull.conf({
appId: 'abcd',
orgUrl: 'https://demo.hullapp.io',
appSecret: '1234'
});
// Get the Hull User ID from your User object
var hullUserId = '5396d6fd448eee6f8c00281c';
//Perform calls as the Hull User
var userClient = hull.as(hullUserId);
// String Trait
userClient.trait('wow', 'such love');
// Number Trait
userClient.trait('w00t', 1000 /*, function... */);
// Number trait Incrementation, with Optional error handling
userClient.trait('w00t').inc(12, function (err, data) {
if (err) {
console.log('Ooops:', err);
} else {
console.log('Done!');
}
});
//
// This script receives webhooks and verifies them before processing
//
var hull = require('hull');
hull.conf({
appId: 'abcd',
orgUrl: 'https://demo.hullapp.io',
appSecret: '1234'
});
//Use an Express middleware to verify webhooks
var express = require('express');
var app = express();
//Use the default config to parse webhook
app.use(hull.webhook());
// Alternatively, override default config
/*app.use(hull.webhook({
appId:'other_app_id',
orgUrl:'other_org_url',
appSecret:'other_app_secret'
}));*/
app.post('/webhook', function (req, res) {
// req.body is a decoded Hash containing received data from WebHook
console.log(req.body);
res.send(200, 'OK');
});
var server = app.listen(3000, function () {
console.log('Listening on %s', server.address().port);
});
//
// This script shows how to manipulate data in Hull as a specific user
//
var hull = require('hull');
hull.conf({
appId: 'abcd',
orgUrl: 'https://demo.hullapp.io',
appSecret: '1234'
});
// These are Hull IDs
var hullUser1Id = '53919934f1bccd7c6f00060b';
var hullUser2Id = '53919ddaa1d0531ef100075a';
// Get User1 profile
var userClient1 = hull.as(hullUser1Id);
userClient1.get('me', function (err, data) {
console.info('User1', data);
});
// Get User2 profile from Hull
var userClient2 = hull.as(hullUser2Id);
userClient2.get('me', function (err, data) {
console.info('User2', data);
});
//
{
"name": "whyd",
"version": "0.0.0",
"description": "Whyd demo",
"main": "index.js",
"author": "Xavier Cambar",
"license": "MIT",
"dependencies": {
"hull": "~0.4.0",
"express": "~4.4.2"
}
}
//
// This script shows how to import and create Hull users
//
var hull = require('hull');
hull.conf({
appId: 'abcd',
orgUrl: 'https://demo.hullapp.io',
appSecret: '1234'
});
// Create a new Client
var adminClient = hull.client();
// Get a User Hash
var user = {
email: "[email protected]",
password: "bla"
};
//Create the User on Hull
adminClient.post('users', user, function (err, data) {
//The Response contains the Hull User ID that you should store in your database
console.info("Here's my user id: %s", data.id);
});
//
// This script shows how to create Hull users from Facebook Users
//
var hull = require('hull');
hull.conf({
appId: '53918a74f1bccd7c6f0004e0',
orgUrl: 'https://demo.hullapp.io',
appSecret: '1234'
});
var adminClient = hull.client();
var user = {
facebook: {
access_token: "Loooooo....oong string"
}
};
adminClient.post('users', user, function (err, data) {
if (err) {
return console.log(err, data);
}
console.info("Here's my user id: %s", data.id);
console.info("Here's all my info:", data);
});
@unity
Copy link

unity commented Jun 11, 2014

@xcambar please add inline comments, and also explain linkIdentity vs create account

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment