Commit 86554d76 by 3rd-Eden

[api] Implement the email and location API

[fix] Make the version configurable
parent caf027f7
60671
\ No newline at end of file
'use strict';
/**
* Access the E-mail API.
*
* @constructor
* @param {FullContact} api Reference to the FullContact wrapping instance.
* @api public
*/
function Email(api) {
this.api = api;
this.endpoint = 'https://api.fullcontact.com/'+ api.version +'/mail/';
this.send = api.process.bind(api, this);
}
/**
* Check if we we're given a disposable e-mail address.
*
* ```js
* fullcontact.email.disposable('foo@bar.bar', fn);
* ```
*
* @returns {Email}
* @api public
*/
Email.prototype.disposable = function disposable() {
var args = this.api.args(arguments, 'casing');
//
// Add a custom endpoint.
//
args.endpoint = this.endpoint +'disposable.json';
this.send({ email: args.value }, args);
return this;
};
module.exports = Email;
'use strict';
/**
* Access the location API.
*
* @constructor
* @param {FullContact} api Reference to the FullContact wrapping instance.
* @api private
*/
function Location(api) {
this.api = api;
this.endpoint = 'https://api.fullcontact.com/'+ api.version +'/address/';
this.send = api.process.bind(api, this);
}
/**
* Normalize the location data.
*
* ```js
* fullcontact.location.normalize('denver', [includeZeroPopulation], [casing], fn);
* ```
*
* @returns {Location}
* @api public
*/
Location.prototype.normalize = function normalize() {
var args = this.api.args(arguments, 'includeZeroPopulation', 'casing');
//
// Add a custom endpoint.
//
args.endpoint = this.endpoint +'locationNormalizer.json';
this.send({ place: args.value }, args);
return this;
};
/**
* Retrieve more information from the location API.
*
* ```js
* fullcontact.location.enrich('denver', [includeZeroPopulation], [casing], fn);
* ```
*
* @returns {Location}
* @api public
*/
Location.prototype.enrich = function enrichment() {
var args = this.api.args(arguments, 'includeZeroPopulation', 'casing');
//
// Add a custom endpoint.
//
args.endpoint = this.endpoint +'locationEnrichment.json';
this.send({ place: args.value }, args);
return this;
};
//
// Expose the Location endpoint.
//
module.exports = Location;
'use strict'; 'use strict';
/**
* Access the name API.
*
* @constructor
* @param {FullContact} api Reference to the FullContact wrapping instance.
* @api public
*/
function Name(api) { function Name(api) {
this.api = api; this.api = api;
this.endpoint = 'https://api.fullcontact.com/v2/name/'; this.endpoint = 'https://api.fullcontact.com/'+ api.version +'/name/';
this.send = api.process.bind(api, this); this.send = api.process.bind(api, this);
} }
...@@ -21,7 +28,7 @@ Name.prototype.normalize = function normalize() { ...@@ -21,7 +28,7 @@ Name.prototype.normalize = function normalize() {
var args = this.api.args(arguments, 'casing'); var args = this.api.args(arguments, 'casing');
// //
// Add a custom endpoint // Add a custom endpoint.
// //
args.endpoint = this.endpoint +'normalizer.json'; args.endpoint = this.endpoint +'normalizer.json';
...@@ -44,7 +51,7 @@ Name.prototype.deducer = function deducer() { ...@@ -44,7 +51,7 @@ Name.prototype.deducer = function deducer() {
var args = this.api.args(arguments, 'casing'); var args = this.api.args(arguments, 'casing');
// //
// Add a custom endpoint // Add a custom endpoint.
// //
args.endpoint = this.endpoint +'deducer.json'; args.endpoint = this.endpoint +'deducer.json';
...@@ -66,7 +73,7 @@ Name.prototype.similarity = function similarity() { ...@@ -66,7 +73,7 @@ Name.prototype.similarity = function similarity() {
var args = this.api.args(arguments, 'q2', 'casing'); var args = this.api.args(arguments, 'q2', 'casing');
// //
// Add a custom endpoint // Add a custom endpoint.
// //
args.endpoint = this.endpoint +'similarity.json'; args.endpoint = this.endpoint +'similarity.json';
...@@ -91,7 +98,7 @@ Name.prototype.stats = function stats() { ...@@ -91,7 +98,7 @@ Name.prototype.stats = function stats() {
var args = this.api.args(arguments, 'casing'); var args = this.api.args(arguments, 'casing');
// //
// Add a custom endpoint // Add a custom endpoint.
// //
args.endpoint = this.endpoint +'stats.json'; args.endpoint = this.endpoint +'stats.json';
...@@ -113,7 +120,7 @@ Name.prototype.parser = function parser() { ...@@ -113,7 +120,7 @@ Name.prototype.parser = function parser() {
var args = this.api.args(arguments, 'casing'); var args = this.api.args(arguments, 'casing');
// //
// Add a custom endpoint // Add a custom endpoint.
// //
args.endpoint = this.endpoint +'parser.json'; args.endpoint = this.endpoint +'parser.json';
......
...@@ -12,7 +12,7 @@ var crypto = require('crypto'); ...@@ -12,7 +12,7 @@ var crypto = require('crypto');
function Person(api) { function Person(api) {
this.api = api; this.api = api;
this.endpoint = 'https://api.fullcontact.com/v2/person.json'; this.endpoint = 'https://api.fullcontact.com/'+ api.version +'/person.json';
this.send = api.process.bind(api, this); this.send = api.process.bind(api, this);
} }
......
...@@ -16,13 +16,14 @@ function FullContact(api) { ...@@ -16,13 +16,14 @@ function FullContact(api) {
if (!(this instanceof FullContact)) return new FullContact(api); if (!(this instanceof FullContact)) return new FullContact(api);
this.key = api; // API key this.key = api; // API key
this.version = 'v2'; // API version
this.remaining = 0; // How many API calls are remaining this.remaining = 0; // How many API calls are remaining
this.ratelimit = 0; // The amount of API calls allowed this.ratelimit = 0; // The amount of API calls allowed
this.ratereset = 0; // In how many seconds is the rate limit reset this.ratereset = 0; // In how many seconds is the rate limit reset
this.queueing = false; // Should we be queueing requests this.queueing = false; // Should we be queueing requests
this.requests = []; // Stores all queued commands. this.requests = []; // Stores all queued commands
} }
/** /**
...@@ -164,7 +165,7 @@ FullContact.prototype.exec = function exec(fn) { ...@@ -164,7 +165,7 @@ FullContact.prototype.exec = function exec(fn) {
request({ request({
method: 'POST', method: 'POST',
uri: 'https://api.fullcontact.com/v2/batch.json', uri: 'https://api.fullcontact.com/'+ this.version +'/batch.json',
qs: { apiKey: this.key }, qs: { apiKey: this.key },
json: { json: {
requests: requests.map(function urlsonly(data) { requests: requests.map(function urlsonly(data) {
...@@ -231,13 +232,23 @@ FullContact.createClient = function createClient(api) { ...@@ -231,13 +232,23 @@ FullContact.createClient = function createClient(api) {
// //
// Expose the endpoints. // Expose the endpoints.
// //
FullContact.Location = require('./endpoints/location');
FullContact.Person = require('./endpoints/person'); FullContact.Person = require('./endpoints/person');
FullContact.Email = require('./endpoints/email');
FullContact.Name = require('./endpoints/name'); FullContact.Name = require('./endpoints/name');
// //
// Lazy load the various of endpoints so they only get initialized when we // Lazy load the various of endpoints so they only get initialized when we
// actually need them. // actually need them.
// //
FullContact.define(FullContact.prototype, 'location', function define() {
return new FullContact.Location(this);
});
FullContact.define(FullContact.prototype, 'email', function define() {
return new FullContact.Email(this);
});
FullContact.define(FullContact.prototype, 'person', function define() { FullContact.define(FullContact.prototype, 'person', function define() {
return new FullContact.Person(this); return new FullContact.Person(this);
}); });
......
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