Skip to content

Commit 4fca383

Browse files
author
Eero Otsus
committed
Merge remote-tracking branch 'pipedrive/client-nodejs/master'
2 parents f9e5b62 + 70e6ab4 commit 4fca383

File tree

12 files changed

+66
-945
lines changed

12 files changed

+66
-945
lines changed

Jenkinsfile

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.md

Lines changed: 49 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,43 @@
11
# Pipedrive client for NodeJS based apps
2-
3-
[![NPM version](https://badge.fury.io/js/pipedrive.svg)](http://badge.fury.io/js/pipedrive) [![Build Status](https://travis-ci.org/pipedrive/client-nodejs.svg)](https://travis-ci.org/pipedrive/client-nodejs)
4-
52
Pipedrive is a sales pipeline software that gets you organized. It's a powerful sales CRM with effortless sales pipeline management. See www.pipedrive.com for details.
63

74
This is the official Pipedrive API wrapper-client for NodeJS based apps, distributed by Pipedrive Inc freely under the MIT licence. It provides you with basic functionality for operating with objects such as Deals, Persons, Organizations, Products and much more, without having to worry about the underlying networking stack and actual HTTPS requests.
85

9-
# Install
10-
6+
## Installation
117
```
128
npm install pipedrive
139
```
1410

15-
# Usage
11+
## Roadmap & known issues
12+
- [Missing async/await promise support](https://github.com/pipedrive/client-nodejs/issues/81)
13+
- [Missing oauth 2.0 support](https://github.com/pipedrive/client-nodejs/issues/78)
14+
15+
## API Documentation
16+
The Pipedrive REST API documentation can be found at https://developers.pipedrive.com/v1
17+
18+
## Testing & Quality
19+
[![NPM version](https://badge.fury.io/js/pipedrive.svg)](http://badge.fury.io/js/pipedrive) [![Build Status](https://travis-ci.org/pipedrive/client-nodejs.svg)](https://travis-ci.org/pipedrive/client-nodejs)
20+
21+
To run unit tests, execute
22+
```bash
23+
npm run test
24+
```
25+
26+
## Licence
27+
This Pipedrive API client is distributed under the MIT licence.
1628

29+
## Contribution
30+
- Run tests
31+
- Make PR
32+
33+
# How to use
1734
With a pre-set API token:
1835
```js
1936
var Pipedrive = require('pipedrive');
2037
var pipedrive = new Pipedrive.Client('YOUR_API_TOKEN_HERE', { strictMode: true });
2138
```
2239

23-
# A simple "Hello world" that lists some deals
40+
### A simple "Hello world" that lists some deals
2441

2542
Here's a quick example that will list some deals from your Pipedrive account:
2643

@@ -36,7 +53,7 @@ pipedrive.Deals.getAll({}, function(err, deals) {
3653
});
3754
```
3855

39-
# Supported objects
56+
### Supported objects
4057

4158
* Activities
4259
* ActivityTypes
@@ -64,60 +81,60 @@ pipedrive.Deals.getAll({}, function(err, deals) {
6481
* Users
6582
* Webhooks
6683

67-
# Supported operations for object collections
84+
### Supported operations for object collections
6885

69-
### pipedrive.{Object}.add (data, [fn callback])
86+
#### pipedrive.{Object}.add (data, [fn callback])
7087
Add an object. Returns ```error, data``` to the callback where data contains the ```id``` property of the newly created item.
7188

72-
### pipedrive.{Object}.get (id, [fn callback])
89+
#### pipedrive.{Object}.get (id, [fn callback])
7390
Get specific object. Returns ```error, object, additionalData, rawRequest, rawResponse, relatedObjects```
7491

75-
### pipedrive.{Object}.update (id, data, [fn callback])
92+
#### pipedrive.{Object}.update (id, data, [fn callback])
7693
Update an object. Returns ```error``` in case of an error to the callback.
7794

78-
### pipedrive.{Object}.getAll (params, [fn callback])
95+
#### pipedrive.{Object}.getAll (params, [fn callback])
7996
Get all objects, optionally passing additional parameters (such as ```filter_id``` in case of deals, persons and organizations). Returns ```error, objects``` to the callback function where objects is a collection (array) of objects.
8097

81-
### pipedrive.{Object}.remove (id, [fn callback])
98+
#### pipedrive.{Object}.remove (id, [fn callback])
8299
Delete an object with a specifc ID. Returns ```error``` in case of an error to the callback.
83100

84-
### pipedrive.{Object}.removeMany ([Array ids], [fn callback])
101+
#### pipedrive.{Object}.removeMany ([Array ids], [fn callback])
85102
Delete multiple objects using an array of IDs. Returns ```error``` in case of an error to the callback.
86103

87-
### pipedrive.{Object}.merge (whichId, withId, [fn callback])
104+
#### pipedrive.{Object}.merge (whichId, withId, [fn callback])
88105
Merge two objects of the same kind. Returns ```error``` in case of an error to the callback. Merge is only supported for the following objects:
89106
* Persons
90107
* Organizations
91108

92-
### pipedrive.{Object}.find (params, [fn callback])
109+
#### pipedrive.{Object}.find (params, [fn callback])
93110
Find objects of certain kind by their name/title, using `term` property supplied inside params object. Supported for:
94111
* Deals
95112
* Persons
96113
* Organizations
97114
* Users
98115

99-
# Supported operations for each object
116+
### Supported operations for each object
100117

101-
### {object}.get(fieldName)
118+
#### {object}.get(fieldName)
102119
Returns the value of [fieldName] of the object.
103120

104-
### {object}.set(fieldName, newValue)
121+
#### {object}.set(fieldName, newValue)
105122
Sets a new value of [fieldName] of the object. Returns {object}.
106123

107-
### {object}.save([fn callback])
124+
#### {object}.save([fn callback])
108125
Updates the state of the {object} in Pipedrive via the API. Returns {object}.
109126

110-
### {object}.remove([fn callback])
127+
#### {object}.remove([fn callback])
111128
Deletes the {object} in Pipedrive via the API. Returns ```error``` in case of an error to the callback.
112129

113-
### {object}.merge(withId, [fn callback])
130+
#### {object}.merge(withId, [fn callback])
114131
Merges the {object} with another object of the same kind with the ID given as ```withId```. Returns ```error``` in case of error to the callback. Merge is only supported for the following objects:
115132
* Persons
116133
* Organizations
117134

118-
# Operations with nested objects
135+
### Operations with nested objects
119136

120-
## Adding a product to a deal
137+
#### Adding a product to a deal
121138

122139
To add a product to a deal, simply invoke the ```addProduct``` method on a deal object.
123140
```js
@@ -129,11 +146,11 @@ pipedrive.Deals.get(1, function(err, deal) {
129146
});
130147
})
131148
```
132-
## You can add multiple products with a single request, too.
149+
#### You can add multiple products with a single request, too.
133150

134151
To add multiple products with a single request, make the first argument of deal's ```addProduct``` method (as shown above) an array, e.g. ```[{ product_id: 1, quantity: 5, discount: 0 }, { product_id: 1, quantity: 2, discount: 20 }]```. This will add two product rows to a deal — one with a quantity of 5 and with no discount, the latter will add a separate row for the same product but with a quantity of 2 and no discount.
135152

136-
## Updating a deal product
153+
#### Updating a deal product
137154
```js
138155
pipedrive.Deals.get(deal_id, function(err, deal) {
139156
if (err) throw err;
@@ -152,7 +169,7 @@ pipedrive.Deals.get(deal_id, function(err, deal) {
152169
Updating multiple deal products in one request is not supported yet.
153170

154171

155-
## Delete a product from a deal
172+
#### Delete a product from a deal
156173
```js
157174
pipedrive.Deals.get(deal_id, function(err, deal) {
158175
if (err) throw err;
@@ -167,7 +184,7 @@ pipedrive.Deals.get(deal_id, function(err, deal) {
167184
})
168185
```
169186

170-
## Search for field value matches
187+
#### Search for field value matches
171188

172189
There is an additional method to perform the `SearchResults/field` search. This can be used for field-value searches.
173190

@@ -191,7 +208,7 @@ pipedrive.SearchResults.field({
191208
* **start** (optional, default 0) – results pagination start
192209
* **limit** (optional, default 100) — results pagination limit
193210

194-
## Retrieve all records for a given object type:
211+
#### Retrieve all records for a given object type:
195212

196213
You can request all entries for an valid object using `getAll(object, callback)`
197214

@@ -205,9 +222,8 @@ pipedrive.getAll('Persons', function (err, collection) {
205222
});
206223
```
207224

208-
# Examples
209-
210-
## Get 15 first deals using the first deals filter
225+
### Examples
226+
#### Get 15 first deals using the first deals filter
211227

212228
```js
213229
var Pipedrive = require('pipedrive');
@@ -227,36 +243,3 @@ pipedrive.Filters.getAll({ type: 'deals' }, function(filtersListErr, filtersList
227243

228244
});
229245
```
230-
231-
# Ad hoc data change event listeneres (beta)
232-
233-
The API client lets you create event listeners to specific data changes in your Pipedrive account. This is very similar to Webhooks, except the listeners are bound on an ad hoc basis and will only be executed during the lifecycle of your application. For example (see below) you may want to execute a callback every time a new deal is added to Pipedrive. Note that this callback will execute not only when you create the deal through this API client but regardless of where the deal was added from — a mobile app, the web app or through the Pipedrive API by some other integration.
234-
235-
```js
236-
var Pipedrive = require('pipedrive');
237-
var pipedrive = new Pipedrive.Client('PUT_YOUR_API_TOKEN_HERE', { strictMode: true });
238-
239-
pipedrive.on('deal.added', function(event, data) {
240-
console.log('A deal was added! ' + data.current.title + ' (' + data.current.value + ' ' + data.current.currency + ')');
241-
});
242-
```
243-
244-
Supported event names consist of object type (deal, person, organization, ...) and type of change (`added`, `deleted`, `updated` or `merged`), joined by a dot. The list of supported object types are listed in the [Pipedrive Webhooks documentation](https://app.pipedrive.com/webhooks).
245-
246-
To read more about ad hoc data change event listeners, check out [examples/live-updates.js](examples/live-updates.js).
247-
248-
# API Documentation
249-
250-
The Pipedrive REST API documentation can be found at https://developers.pipedrive.com/v1
251-
252-
# Testing
253-
To run unit tests, execute `npm run tests`
254-
255-
# Licence
256-
257-
This Pipedrive API client is distributed under the MIT licence.
258-
259-
# Contribution
260-
261-
TBD
262-

examples/live-updates.js

Lines changed: 0 additions & 59 deletions
This file was deleted.

lib/Collection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
CollectionItem = require(__dirname + '/CollectionItem'),
66
RestHandlers = require(__dirname + '/restHandlers'),
77
blueprint = require(__dirname + '/blueprint'),
8-
inflection = require(__dirname + '/inflection');
8+
inflection = require('inflection');
99

1010
module.exports = Collection;
1111

lib/CollectionItem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
var _ = require('lodash'),
55
RestHandlers = require(__dirname + '/restHandlers'),
66
blueprint = require(__dirname + '/blueprint'),
7-
inflection = require(__dirname + '/inflection');
7+
inflection = require('inflection');
88

99
function CollectionItem(kind, data, itemId, options, undefinedProperty) {
1010

lib/Pipedrive.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@
1111

1212
var _ = require('lodash'),
1313
blueprint = require(__dirname + '/blueprint'),
14-
inflection = require(__dirname + '/inflection'),
15-
Channel = require(__dirname + '/channel'),
16-
log = require(__dirname + '/log'),
17-
RestHandlers = require(__dirname + '/restHandlers'),
18-
Collection = require(__dirname + '/Collection'),
19-
CollectionItem = require(__dirname + '/CollectionItem'),
20-
wrapCollectionItems = require(__dirname + '/wrapCollectionItems');
14+
Collection = require(__dirname + '/Collection');
2115

2216
exports.Client = Client;
2317

@@ -35,15 +29,7 @@
3529
options = _.extend({}, defaults, options);
3630
options.strictMode = !!options.strictMode;
3731

38-
var that = this,
39-
listener = new Channel(apiToken);
40-
41-
if (options.strictMode) {
42-
// in strict mode, we'll expose the EventEmitter-like real-time integration methods
43-
this.on = listener.on;
44-
this.removeListener = listener.removeListener;
45-
this.removeAllListeners = listener.removeAllListeners;
46-
}
32+
var that = this;
4733

4834
_.each(blueprint.apiObjects, function (item) {
4935
that[item.substr(0, 1).toUpperCase() + item.substr(1)] = new Collection(item, _.extend({}, options, {apiToken: apiToken}));

0 commit comments

Comments
 (0)