diff --git a/README.md b/README.md index 848164c..53b6979 100644 --- a/README.md +++ b/README.md @@ -35,3 +35,26 @@ closeio.lead.create({name: "Spider Man"}) console.log(err); }); ``` + +**Searching for Leads** + +The `lead.search` method accepts either a string or a dictionary of search keywords as valid parameters. + +To use a string to specify your search query, pass a `query` parameter to the `lead.search` method: + +```javascript +closeio.lead.search({query: 'name:"Bruce Wayne" email_address:bruce@wayneenterprises.com'}) +.then(function(search_results){ + console.log(search_results.total_results); +}); +``` + +To use a dictionary of search keywords to specify your search query, structure your parameters as follows: +```javascript +closeio.lead.search({name: "Bruce Wayne", email_address: 'bruce@wayneenterprises.com'}) +.then(function(search_results){ + console.log(search_results.total_results); +}); +``` + +**Note**: The `query` parameter will override any other search keywords present in your dictionary. diff --git a/lib/close.io.js b/lib/close.io.js index 4d7eaee..3a2106e 100644 --- a/lib/close.io.js +++ b/lib/close.io.js @@ -21,14 +21,17 @@ var Closeio = function(apiKey) { parameters._fields = options.fields; delete options.fields; } - - 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] + ' '; - }); + if ('query' in options) { + parameters.query = options.query; + } else { + 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); diff --git a/package-lock.json b/package-lock.json index 8927d38..955157e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "close.io", - "version": "1.2.1", + "version": "1.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index f5d34c4..7fc8e67 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "close.io", "preferGlobal": "false", - "version": "1.2.1", + "version": "1.3.0", "author": "John Wehr ", "description": "", "contributors": [ diff --git a/test/close.io.js b/test/close.io.js index dc9aa43..1c1440d 100644 --- a/test/close.io.js +++ b/test/close.io.js @@ -125,7 +125,15 @@ describe('Close.io API', function () { }); }); - + it('should search a lead by query', function () { + var lead_id; + return closeio.lead.search({ query: 'name:"John Wehr"'}) + .then(function (data) { + // console.log(data) + assert(data.data.length > 0); + }); + }); + after(function () { return closeio.lead.delete(lead_id) })