Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

close.io

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

close.io - npm Package Compare versions

Comparing version 0.0.3 to 0.0.7

.jshintrc

257

lib/close.io.js

@@ -1,94 +0,107 @@

var https = require('https');
var deferred = require("node-promise").defer;
var request = require("request");
'use strict';
var deferred = require('node-promise').defer;
var request = require('request');
var qs = require('querystring');
var Closeio = function(api_key){
var Closeio = function(apiKey) {
var closeio = this;
this.api_key = api_key;
this.apiKey = apiKey;
this.lead = {
search: function(options){
search: function(options) {
var parameters = {};
if(options.limit) {
if('limit' in options) {
parameters._limit = options.limit;
delete options.limit;
}
if(options.skip) {
if('skip' in options) {
parameters._skip = options.skip;
delete options.skip;
}
if(options.fields) {
if('fields' in options) {
parameters._fields = options.fields;
delete options.fields;
}
parameters.query = qs.stringify(options, " ", ":");
return closeio._get("/lead/", parameters);
var option_keys = Object.keys(options);
if (option_keys.length > 0) {
parameters.query = '';
option_keys.forEach(function(option) {
var option_wrapper = (!/^".*"$/.test(option) && / +/.test(option)) ? '"' : '';
parameters.query += option_wrapper + option + option_wrapper + ':' + options[option] + ' ';
});
}
return closeio._get('/lead/', parameters);
},
create: function(options){
return closeio._post("/lead/", options);
create: function(options) {
return closeio._post('/lead/', options);
},
merge: function(options){
return closeio._post("/lead/merge/", options);
},
read: function(id) {
return closeio._get("/lead/" + id + "/");
return closeio._get('/lead/' + id + '/');
},
update: function(id, options) {
return closeio._put("/lead/" + id + "/", options);
return closeio._put('/lead/' + id + '/', options);
},
delete: function(id) {
return closeio._delete("/lead/" + id + "/");
return closeio._delete('/lead/' + id + '/');
}
};
this.contact = {
search: function(){
return closeio._get("/contact/");
search: function() {
return closeio._get('/contact/');
},
create: function(options){
return closeio._post("/contact/", options);
create: function(options) {
return closeio._post('/contact/', options);
},
read: function(id) {
return closeio._get("/contact/" + id + "/");
return closeio._get('/contact/' + id + '/');
},
update: function(id, options) {
return closeio._put("/contact/" + id + "/", options);
return closeio._put('/contact/' + id + '/', options);
},
delete: function(id) {
return closeio._delete("/contact/" + id + "/");
return closeio._delete('/contact/' + id + '/');
}
};
this.activity = {
search: function(options){
return closeio._get("/activity/", options);
search: function(options) {
return closeio._get('/activity/', options);
},
note: {
search: function(options){
return closeio._get("/activity/note/", options);
search: function(options) {
return closeio._get('/activity/note/', options);
},
create: function(options){
return closeio._post("/activity/note/", options);
create: function(options) {
return closeio._post('/activity/note/', options);
},
update: function(id, options){
return closeio._put("/activity/note/" + id, options);
},
update: function(id, options) {
return closeio._put('/activity/note/' + id + '/', options);
},
delete: function(id) {
return closeio._delete("/activity/note/" + id + "/");
return closeio._delete('/activity/note/' + id + '/');
}
},
email: {
search: function(options){
return closeio._get("/activity/email/", options);
search: function(options) {
return closeio._get('/activity/email/', options);
},
create: function(options){
return closeio._post("/activity/email/", options);
create: function(options) {
return closeio._post('/activity/email/', options);
},
update: function(id, options){
return closeio._put("/activity/email/" + id, options);
},
update: function(id, options) {
return closeio._put('/activity/email/' + id + '/', options);
},
delete: function(id) {
return closeio._delete("/activity/email/" + id + "/");
return closeio._delete('/activity/email/' + id + '/');
}
},
call: {
search: function(options){
return closeio._get("/activity/call/", options);
search: function(options) {
return closeio._get('/activity/call/', options);
},
delete: function(id) {
return closeio._delete("/activity/call/" + id + "/");
return closeio._delete('/activity/call/' + id + '/');
}

@@ -98,41 +111,41 @@ }

this.opportunity = {
search: function(options){
return closeio._get("/opportunity/", options);
search: function(options) {
return closeio._get('/opportunity/', options);
},
create: function(options){
return closeio._post("/opportunity/", options);
create: function(options) {
return closeio._post('/opportunity/', options);
},
read: function(id) {
return closeio._get("/opportunity/" + id + "/");
return closeio._get('/opportunity/' + id + '/');
},
update: function(id, options) {
return closeio._put("/opportunity/" + id + "/", options);
return closeio._put('/opportunity/' + id + '/', options);
},
delete: function(id) {
return closeio._delete("/opportunity/" + id + "/");
return closeio._delete('/opportunity/' + id + '/');
}
};
this.task = {
search: function(options){
return closeio._get("/task/", options);
search: function(options) {
return closeio._get('/task/', options);
},
create: function(options){
return closeio._post("/task/", options);
create: function(options) {
return closeio._post('/task/', options);
},
read: function(id) {
return closeio._get("/task/" + id + "/");
return closeio._get('/task/' + id + '/');
},
update: function(id, options) {
return closeio._put("/task/" + id + "/", options);
return closeio._put('/task/' + id + '/', options);
},
delete: function(id) {
return closeio._delete("/task/" + id + "/");
return closeio._delete('/task/' + id + '/');
}
};
this.user = {
me: function(){
return closeio._get("/me/");
me: function() {
return closeio._get('/me/');
},
read: function(id) {
return closeio._get("/user/" + id + "/");
return closeio._get('/user/' + id + '/');
}

@@ -142,51 +155,88 @@ };

read: function(id) {
return closeio._get("/organization/" + id + "/");
return closeio._get('/organization/' + id + '/');
},
update: function(id, options) {
return closeio._put("/organization/" + id + "/", options);
return closeio._put('/organization/' + id + '/', options);
}
};
this.report = {
read: function(organization_id, options) {
return closeio._get("/report/" + organization_id + "/", options);
read: function(id, options) {
return closeio._get('/report/' + id + '/', options);
}
};
this.email_template = {
search: function(){
return closeio._get("/email_template/");
search: function() {
return closeio._get('/email_template/');
},
create: function(options){
return closeio._post("/email_template/", options);
create: function(options) {
return closeio._post('/email_template/', options);
},
read: function(id) {
return closeio._get("/email_template/" + id + "/");
return closeio._get('/email_template/' + id + '/');
},
update: function(id, options) {
return closeio._put("/email_template/" + id + "/", options);
return closeio._put('/email_template/' + id + '/', options);
},
delete: function(id) {
return closeio._delete("/email_template/" + id + "/");
return closeio._delete('/email_template/' + id + '/');
}
};
this.saved_search = {
search: function(){
return closeio._get("/saved_search/");
search: function() {
return closeio._get('/saved_search/');
},
create: function(options){
return closeio._post("/saved_search/", options);
create: function(options) {
return closeio._post('/saved_search/', options);
},
read: function(id) {
return closeio._get("/saved_search/" + id + "/");
return closeio._get('/saved_search/' + id + '/');
},
update: function(id, options) {
return closeio._put("/saved_search/" + id + "/", options);
return closeio._put('/saved_search/' + id + '/', options);
},
delete: function(id) {
return closeio._delete("/saved_search/" + id + "/");
return closeio._delete('/saved_search/' + id + '/');
}
};
this.status = {
lead: {
list: function() {
return closeio._get('/status/lead/');
},
create: function(options) {
return closeio._post('/status/lead/', options);
},
read: function(id) {
return closeio._get('/status/lead/' + id + '/');
},
update: function(id, options) {
return closeio._put('/status/lead/' + id + '/', options);
},
delete: function(id) {
return closeio._delete('/status/lead/' + id + '/');
}
},
opportunity: {
list: function() {
return closeio._get('/status/opportunity/');
},
create: function(options) {
return closeio._post('/status/opportunity/', options);
},
read: function(id) {
return closeio._get('/status/opportunity/' + id + '/');
},
update: function(id, options) {
return closeio._put('/status/opportunity/' + id + '/', options);
},
delete: function(id) {
return closeio._delete('/status/opportunity/' + id + '/');
}
}
};
};
Closeio.prototype._request = function(options) {
options.auth = {
user: this.api_key,
user: this.apiKey,
pass: ''

@@ -197,27 +247,37 @@ };

request(options, function(error, response, body) {
if (!error && response.statusCode == 200) {
if (!error && response.statusCode === 200) {
d.resolve(JSON.parse(body));
return;
}
if(error){
if (error) {
d.reject(error);
return;
}
d.reject(JSON.parse(body));
var rejection;
try {
rejection = JSON.parse(body);
}catch(e){
rejection = response.statusCode == 200 ? body : response.statusCode;
}
d.reject(rejection);
});
return d.promise;
};
Closeio.prototype._post = function(path, options) {
var options = {
uri: "https://app.close.io/api/v1" + path,
options = {
uri: 'https://app.close.io/api/v1' + path,
body: JSON.stringify(options),
headers: {"Content-type": "application/json"},
method: "POST"
headers: {
'Content-type': 'application/json'
},
method: 'POST'
};
return this._request(options);
};
Closeio.prototype._get = function(path, parameters) {
var options = {
uri: "https://app.close.io/api/v1" + path,
method: "GET",
uri: 'https://app.close.io/api/v1' + path,
method: 'GET',
qs: parameters

@@ -227,18 +287,23 @@ };

};
Closeio.prototype._put = function(path, options) {
var options = {
uri: "https://app.close.io/api/v1" + path,
options = {
uri: 'https://app.close.io/api/v1' + path,
body: JSON.stringify(options),
headers: {"Content-type": "application/json"},
method: "PUT"
headers: {
'Content-type': 'application/json'
},
method: 'PUT'
};
return this._request(options);
};
Closeio.prototype._delete = function(path) {
var options = {
uri: "https://app.close.io/api/v1" + path,
method: "DELETE"
uri: 'https://app.close.io/api/v1' + path,
method: 'DELETE'
};
return this._request(options);
};
module.exports = exports = Closeio;
module.exports = exports = Closeio;
{
"name": "close.io",
"preferGlobal": "false",
"version": "0.0.3",
"version": "0.0.7",
"author": "John Wehr <johnwehr@gmail.com>",
"description": "",
"contributors": [
"contributors": [
{
"name": "John Wehr",
"email": "johnwehr@gmail.com"
}
},
{
"name": "Paul Cothenet",
"email": "paul@madkudu.com"
}
],

@@ -16,9 +20,8 @@ "main": "./lib/close.io.js",

"type": "git",
"url": "https://github.com/wehriam/Close.io.git"
"url": "git@github.com:closeio/closeio-node.git"
},
"keywords": [],
"dependencies" : {
"node-promise": "*",
"request": "2.21.0"
},
"keywords": [
"close.io",
"closeio"
],
"noAnalyze": true,

@@ -30,4 +33,11 @@ "license": "MIT",

"scripts": {
"test": "mocha"
"test": "./node_modules/mocha/bin/mocha --recursive test/"
},
"dependencies": {
"node-promise": "0.5.8",
"request": "2.69.0"
},
"devDependencies": {
"mocha": "^3.3.0"
}
}

@@ -8,12 +8,14 @@ Close.io

```npm install close.io```
```npm install --save close.io```
**Usage**
The module uses [kriszyp/node-promise](https://github.com/kriszyp/node-promise) promises.
```
npm install
mocha test
```
Get an API key from your settings page: https://app.close.io/settings/
```
```javascript
var Closeio = require('close.io');

@@ -23,3 +25,4 @@

closeio.lead.create({name: "Spider Man"}).then(function(lead){
closeio.lead.create({name: "Spider Man"})
.then(function(lead){
return closeio.lead.read(lead.id);

@@ -30,3 +33,3 @@ }).then(function(lead){

return closeio.lead.delete(lead.id);
}).then(function(){
}).then(function(){
return closeio.lead.search({name:"Bruce Wayne"});

@@ -37,3 +40,2 @@ }).then(function(search_results){}, function(err){

});
```

@@ -1,30 +0,135 @@

var Closeio = require('../lib/close.io.js');
var config = require('../config.json');
'use strict';
var Closeio = require('../lib/close.io.js'),
config = require('../config.json'),
assert = require('assert');
describe('Close.io API', function() {
it('should create, read, updated, delete and search for leads.', function(done) {
this.timeout(10000);
var closeio = new Closeio(config.api_key);
closeio.lead.create({name: "John Wehr"}).then(function(data){
function randomString() {
return Math.floor(Math.random() * 10000).toString();
}
describe('Close.io API', function () {
this.timeout(5000);
var closeio
beforeEach(() => {
closeio = new Closeio(config.apiKey);
})
it('should create, read, updated, delete and search for leads.', function () {
return closeio.lead.create({
name: 'John Wehr'
}).then(function (data) {
return closeio.lead.read(data.id);
}).then(function(data){
return closeio.lead.update(data.id, {name: "John Wehr 2"});
}).then(function(data){
}).then(function (data) {
return closeio.lead.update(data.id, {
name: 'John Wehr 2'
});
}).then(function (data) {
assert(data.name === 'John Wehr 2');
return closeio.lead.delete(data.id);
}).then(function(data){
return closeio.lead.search({name:"Wayne"});
}).then(function(data){
done();
}, function(){
throw Error("Could not updated leads.");
}).then(function () {
return closeio.lead.search({
name: 'Wayne'
});
});
});
it('should throw a verbose error', function(done) {
var closeio = new Closeio(config.api_key);
closeio.lead.create({contacts:[{emails:[{email:"test@example.com"}]}]}).then(function(data){
}).then(function(data){
}, function(err){
it('should throw an error if attempting to create a lead without email', function (done) {
closeio.lead.create({
contacts: [{
emails: [{
email: ''
}]
}]
}).then(function () {
done(new Error('This should have failed'))
}, function (err) {
done();
});
});
});
it('should create, read, update, delete lead statuses', function () {
var randomVal = randomString(); // for confirming update
return closeio.status.lead.create({
label: randomString()
}).then(function (data) {
return closeio.status.lead.read(data.id);
}).then(function (data) {
return closeio.status.lead.update(data.id, {
label: randomVal
});
}).then(function (data) {
assert(data.label === randomVal);
return closeio.status.lead.delete(data.id);
});
});
it('should create, read, update, delete opportunity statuses', function () {
var randomVal = randomString(); // for confirming update
return closeio.status.opportunity.create({
label: randomString()
}).then(function (data) {
return closeio.status.opportunity.read(data.id);
}).then(function (data) {
return closeio.status.opportunity.update(data.id, {
label: randomVal
});
}).then(function (data) {
assert(data.label === randomVal);
return closeio.status.opportunity.delete(data.id);
});
});
describe('search', function () {
var lead_id;
before(function () {
return closeio.lead.create({
name: 'John Wehr',
custom: {
foo: 'bar',
'Lead initials': 'JW'
}
}).then(function (data) {
assert(data.id);
lead_id = data.id;
})
})
it('should return all leads if no option is passed', function () {
var lead_id;
return closeio.lead.search({})
.then(function (data) {
// console.log(data)
assert(data.data.length > 0);
});
});
it('should search a lead by name', function () {
var lead_id;
return closeio.lead.search({ name: 'John Wehr'})
.then(function (data) {
// console.log(data)
assert(data.data.length > 0);
});
});
it('should search for leads with custom field containing spaces.', function () {
return closeio.lead.search({ 'custom.Lead initials': 'JW' })
.then(function (data) {
// console.log(data)
assert(data.data.length > 0);
});
});
after(function () {
return closeio.lead.delete(lead_id)
})
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc