Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
tralamazza committed Jul 22, 2011
0 parents commit b342d9d
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
Empty file added Readme.md
Empty file.
11 changes: 11 additions & 0 deletions examples/query.js
@@ -0,0 +1,11 @@
var RapleafApi = require('../index');


var key = process.argv[2];
var email = process.argv[3];

var rap = new RapleafApi(key);

rap.query_by_email(email, function(data) {
console.log(data);
});
1 change: 1 addition & 0 deletions index.js
@@ -0,0 +1 @@
module.exports = require('./lib/node-rapleaf');
71 changes: 71 additions & 0 deletions lib/node-rapleaf.js
@@ -0,0 +1,71 @@
/*
* Author: Daniel Tralamazza
*
* RapLeaf API for node.js
*
* TODO bulk call
*/

var https = require('https'),
qs = require('querystring'),
crypto = require('crypto');


var RapleafApi = function(api_key) {
this.api_key = api_key;
this.base_path = '/v4/dr?';
this.options = {
host: 'personalize.rapleaf.com',
headers: {
'User-Agent': 'RapleafAPI/node/1.0'
}
};
};

RapleafApi.prototype._send_query = function(params, callback) {
params.api_key = this.api_key;
this.options.path = this.base_path + qs.stringify(params);
https.get(this.options, function(res) {
res.setEncoding('utf-8');
res.on('data', function(d) {
if (res.statusCode != 200)
throw new Error(d);
callback(d);
});
}).on('error', function(err) {
throw new Error(err);
});
};

RapleafApi.prototype.query_by_email = function(email, callback, hash_it) {
if (hash_it) {
var sha1sum = crypto.createHash('sha1');
sha1sum.update(email);
return this.query_by_sha1(sha1sum.digest('hex'), callback);
} else
return this._send_query({ 'email': email }, callback);
};

RapleafApi.prototype.query_by_md5 = function(md5email, callback) {
return this._send_query({ 'md5_email': md5email }, callback);
};

RapleafApi.prototype.query_by_sha1 = function(sha1email, callback) {
return this._send_query({ 'sha1_email': sha1email }, callback);
};

RapleafApi.prototype.query_by_nap = function(first, last, street, city, state, callback, email) {
var params = { first: first, last: last, street: street, state: state };
if (email !== undefined)
params.email = email;
return this._send_query(params, callback);
};

RapleafApi.prototype.query_by_nap = function(first, last, zip4, callback, email) {
var params = { first: first, last: last, zip4: zip4 };
if (email !== undefined)
params.email = email;
return this._send_query(params, callback);
};

module.exports = RapleafApi;
10 changes: 10 additions & 0 deletions package.json
@@ -0,0 +1,10 @@
{
"name" : "node-rapleaf",
"description" : "Rapleaf API client for node.js",
"keywords" : [ "rapleaf", "api" ],
"version" : "0.0.1",
"author" : "Daniel Tralamazza <tralamazza@gmail.com>",
"repository" : { "type" : "git", "url" : "git://github.com/tralamazza/node-rapleaf.git" },
"main" : "index",
"engines" : { "node" : "0.4.x" }
}

0 comments on commit b342d9d

Please sign in to comment.