Skip to content

Commit 9c8e4b8

Browse files
authored
Merge pull request #26 from eengoron/master
Add ability to use a lead search query string instead of an itemized list of search keywords
2 parents 1c344be + 90b3211 commit 9c8e4b8

5 files changed

Lines changed: 45 additions & 11 deletions

File tree

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,26 @@ closeio.lead.create({name: "Spider Man"})
3535
console.log(err);
3636
});
3737
```
38+
39+
**Searching for Leads**
40+
41+
The `lead.search` method accepts either a string or a dictionary of search keywords as valid parameters.
42+
43+
To use a string to specify your search query, pass a `query` parameter to the `lead.search` method:
44+
45+
```javascript
46+
closeio.lead.search({query: 'name:"Bruce Wayne" email_address:bruce@wayneenterprises.com'})
47+
.then(function(search_results){
48+
console.log(search_results.total_results);
49+
});
50+
```
51+
52+
To use a dictionary of search keywords to specify your search query, structure your parameters as follows:
53+
```javascript
54+
closeio.lead.search({name: "Bruce Wayne", email_address: 'bruce@wayneenterprises.com'})
55+
.then(function(search_results){
56+
console.log(search_results.total_results);
57+
});
58+
```
59+
60+
**Note**: The `query` parameter will override any other search keywords present in your dictionary.

lib/close.io.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ var Closeio = function(apiKey) {
2121
parameters._fields = options.fields;
2222
delete options.fields;
2323
}
24-
25-
var option_keys = Object.keys(options);
26-
if (option_keys.length > 0) {
27-
parameters.query = '';
28-
option_keys.forEach(function(option) {
29-
var option_wrapper = (!/^".*"$/.test(option) && / +/.test(option)) ? '"' : '';
30-
parameters.query += option_wrapper + option + option_wrapper + ':' + options[option] + ' ';
31-
});
24+
if ('query' in options) {
25+
parameters.query = options.query;
26+
} else {
27+
var option_keys = Object.keys(options);
28+
if (option_keys.length > 0) {
29+
parameters.query = '';
30+
option_keys.forEach(function(option) {
31+
var option_wrapper = (!/^".*"$/.test(option) && / +/.test(option)) ? '"' : '';
32+
parameters.query += option_wrapper + option + option_wrapper + ':' + options[option] + ' ';
33+
});
34+
}
3235
}
3336

3437
return closeio._get('/lead/', parameters);

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "close.io",
33
"preferGlobal": "false",
4-
"version": "1.2.1",
4+
"version": "1.3.0",
55
"author": "John Wehr <johnwehr@gmail.com>",
66
"description": "",
77
"contributors": [

test/close.io.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,15 @@ describe('Close.io API', function () {
125125
});
126126
});
127127

128-
128+
it('should search a lead by query', function () {
129+
var lead_id;
130+
return closeio.lead.search({ query: 'name:"John Wehr"'})
131+
.then(function (data) {
132+
// console.log(data)
133+
assert(data.data.length > 0);
134+
});
135+
});
136+
129137
after(function () {
130138
return closeio.lead.delete(lead_id)
131139
})

0 commit comments

Comments
 (0)