intercom.io.js |
|
Module dependencies. |
|
Represents errors thrown by intercom, see IntercomError.js |
|
Define some sane default options Right now we only have one endpoint for intercom data |
|
Params
appId
String
apiKey
String
options
Object
API
public
|
|
Overload the contractor Parse out single option objects |
|
Preform some sane validation checks and throw errors We need the appId |
|
The api key is also required |
|
Copy over the relavant data |
|
Extend the defaults |
|
Contruct the endpoint with the correct auth from the appId and apiKey |
|
Expose |
|
Helper function to Construct the endpoint Params
endpoint
String
appId
String
apiKey
String
API
public
|
|
Check if the endpoint already has auth built in |
|
Compare auths and warn developer if different (sanity check) |
|
Return the url |
|
Helper method to create an instance easily Enables use like this:
Params
appId
String
apiKey
String
options
Object
API
public
|
|
The main method that makes all the requests to intercom. This method deals with the intercom api and can be used to make requests to the intercom api. API
public
|
115
116 Intercom.prototype.request = function(method, path, parameters, cb) {
117 debug('Requesting [%s] %s with data %o', method, path, parameters)
118
119 var url = this.endpoint + path;
120 var requestOptions = {
121 method: method,
122 url: url
123 };
124
125 if (method === 'GET' || method === 'DELETE') {
126 requestOptions.qs = parameters;
127 } else {
128
129 |
requestOptions.form = parameters; |
128
129 requestOptions.body = qs.stringify(parameters);
130 requestOptions.headers = {
131 'Content-Type': 'application/json'
132 };
133 }
134
135 return request(requestOptions, function(err, res, data) {
136 var parsed;
137
138 if (!err && data) {
139 debug('Recieved response %s', data);
140
141 try {
142 parsed = JSON.parse(data);
143
144 if (parsed && parsed.error && !err) {
145 err = new Error(data);
146 }
147 } catch (exception) {
148
149 }
150 }
151
152 return cb && cb(err, parsed || data);
153 });
154 };
155
156
157 |
Helper method to create dates for intercom easily Params
date
NumberorDate
API
public
|
|
¶ Users |
171
172 Intercom.prototype.getUsers = function(options, cb) {
173 return this.request('GET', 'users', options, cb);
174 };
175
176 Intercom.prototype.getUser = function(userObj, cb) {
177 return this.request('GET', 'users', userObj, cb);
178 };
179
180 Intercom.prototype.createUser = function(userObj, cb) {
181 return this.request('POST', 'users', userObj, cb);
182 };
183
184 Intercom.prototype.updateUser = function(userObj, cb) {
185 return this.request('PUT', 'users', userObj, cb);
186 };
187
188 Intercom.prototype.deleteUser = function(userObj, cb) {
189 return this.request('DELETE', 'users', userObj, cb);
190 };
191
192
193 |
¶ Impressions |
|
¶ Message Threads |
197
198 Intercom.prototype.getMessageThread = function(userObj, cb) {
199 return this.request('GET', 'users/message_threads', userObj, cb);
200 };
201
202 Intercom.prototype.createMessageThread = function(userObj, cb) {
203 return this.request('POST', 'users/message_threads', userObj, cb);
204 };
205
206 Intercom.prototype.replyMessageThread = function(userObj, cb) {
207 return this.request('PUT', 'users/message_threads', userObj, cb);
208 };
209
210
211 |
¶ Notes |
|
¶ Tags |
215
216 Intercom.prototype.getTag = function(userObj, cb) {
217 return this.request('GET', 'tags', userObj, cb);
218 };
219
220 Intercom.prototype.createTag = function(userObj, cb) {
221 return this.request('POST', 'tags', userObj, cb);
222 };
223
224 Intercom.prototype.updateTag = function(userObj, cb) {
225 return this.request('PUT', 'tags', userObj, cb);
226 };
227
228
229 |
Expose |