Skip to content

Commit 613c8b2

Browse files
authored
Enhancement: Readability and sorted array keys (intercom#334)
1 parent 95840af commit 613c8b2

File tree

1 file changed

+66
-59
lines changed

1 file changed

+66
-59
lines changed

README.md

+66-59
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ This resource is only available in API Versions 2.0 and above
9393
```php
9494
/** Create a contact */
9595
$client->contacts->create([
96-
'type' => 'user',
96+
'custom_attributes' => ['nickname' => 'Teddy'],
9797
'email' => '[email protected]',
98-
'custom_attributes' => ['foo' => 'bar']
98+
'type' => 'user',
9999
]);
100100

101101
/** Update a contact */
102102
$client->contacts->update('570680a8a1bcbca8a90001b9', [
103+
'custom_attributes' => ['nickname' => 'Teddy'],
103104
'email' => '[email protected]',
104-
'custom_attributes' => ['foo' => 'bar']
105105
]);
106106

107107
/** Permanently delete a contact */
@@ -113,9 +113,9 @@ $client->contacts->getContact('570680a8a1bcbca8a90001b9');
113113
/** Search for contacts */
114114
$query = ['field' => 'name', 'operator' => '=', 'value' => 'Alice'];
115115
$client->contacts->search([
116+
'pagination' => ['per_page' => 10],
116117
'query' => $query,
117118
'sort' => ['field' => 'name', 'order' => 'ascending'],
118-
'pagination' => ['per_page' => 10]
119119
]);
120120

121121
/** Get next page of conversation search results */
@@ -132,17 +132,17 @@ This resource is only available in API Versions 1.0 to 1.4. Newer versions use t
132132
```php
133133
/** Create a user */
134134
$client->users->create([
135+
'custom_attributes' => ['nickname' => 'Teddy'],
135136
'email' => '[email protected]',
136-
'custom_attributes' => ['foo' => 'bar']
137137
]);
138138

139139
/**
140140
* Update a user (Note: This method is an alias to the create method. In practice you
141141
* can use create to update users if you wish)
142142
*/
143143
$client->users->update([
144+
'custom_attributes' => ['nickname' => 'Teddy'],
144145
'email' => '[email protected]',
145-
'custom_attributes' => ['foo' => 'bar']
146146
]);
147147

148148
/** Archive a user by ID (i.e. soft delete) */
@@ -158,27 +158,29 @@ $client->users->getUser('570680a8a1bcbca8a90001b9');
158158

159159
/** Add companies to a user */
160160
$client->users->create([
161-
'email' => '[email protected]',
162161
'companies' => [
163162
[
164-
'company_id' => '3'
163+
'company_id' => '3',
165164
]
166-
]
165+
],
166+
'email' => '[email protected]',
167167
]);
168168

169169
/** Remove companies from a user */
170170
$client->users->create([
171-
'email' => '[email protected]',
172171
'companies' => [
173172
[
174173
'company_id' => '3',
175-
'remove' => true
174+
'remove' => true,
176175
]
177-
]
176+
],
177+
'email' => '[email protected]',
178178
]);
179179

180180
/** Find a single user by email */
181-
$client->users->getUsers(['email' => '[email protected]']);
181+
$client->users->getUsers([
182+
'email' => '[email protected]',
183+
]);
182184

183185
/** List all users up to 10k records */
184186
$client->users->getUsers([]);
@@ -204,17 +206,17 @@ This resource is only available in API Versions 1.0 to 1.4. Newer versions use t
204206
* See more options here: https://developers.intercom.io/reference#create-lead
205207
*/
206208
$client->leads->create([
209+
'custom_attributes' => ['nickname' => 'Teddy'],
207210
'email' => '[email protected]',
208-
'custom_attributes' => ['foo' => 'bar']
209211
]);
210212

211213
/**
212214
* Update a lead (Note: This method is an alias to the create method.
213215
* In practice you can use create to update leads if you wish)
214216
*/
215217
$client->leads->update([
218+
'custom_attributes' => ['nickname' => 'Teddy'],
216219
'email' => '[email protected]',
217-
'custom_attributes' => ['foo' => 'bar']
218220
]);
219221

220222
/**
@@ -232,11 +234,11 @@ $client->leads->deleteLead('570680a8a1bcbca8a90000a9');
232234
/** Convert a Lead to a User */
233235
$client->leads->convertLead([
234236
'contact' => [
235-
'user_id' => '8a88a590-e1c3-41e2-a502-e0649dbf721c'
237+
'user_id' => '8a88a590-e1c3-41e2-a502-e0649dbf721c',
236238
],
237239
'user' => [
238-
'email' => '[email protected]'
239-
]
240+
'email' => '[email protected]',
241+
],
240242
]);
241243

242244
/**
@@ -257,36 +259,38 @@ Retrieve `user_id` of a visitor via [the JavaScript API](https://developers.inte
257259
```php
258260
/** Update a visitor */
259261
$client->visitors->update([
262+
'custom_attributes' => ['nickname' => 'Teddy'],
260263
'user_id' => '8a88a590-e1c3-41e2-a502-e0649dbf721c',
261-
'custom_attributes' => ['foo' => 'bar']
262264
]);
263265

264266
/** Find a visitor by ID */
265267
$client->visitors->getVisitor('570680a8a1bcbca8a90000a9');
266268

267269
/** Find a visitor by User ID */
268-
$client->visitors->getVisitor('', ['user_id' => '8a88a590-e1c3-41e2-a502-e0649dbf721c']);
270+
$client->visitors->getVisitor('', [
271+
'user_id' => '8a88a590-e1c3-41e2-a502-e0649dbf721c',
272+
]);
269273

270274
/** Delete a visitor by ID */
271275
$client->visitors->deleteVisitor('570680a8a1bcbca8a90000a9');
272276

273277
/** Convert a Visitor to a Lead */
274278
$client->visitors->convertVisitor([
279+
'type' => 'lead',
275280
'visitor' => [
276-
'user_id' => '8a88a590-e1c3-41e2-a502-e0649dbf721c'
281+
'user_id' => '8a88a590-e1c3-41e2-a502-e0649dbf721c',
277282
],
278-
'type' => 'lead'
279283
]);
280284

281285
/** Convert a Visitor to a User */
282286
$client->visitors->convertVisitor([
283-
'visitor' => [
284-
'user_id' => '8a88a590-e1c3-41e2-a502-e0649dbf721c'
285-
],
287+
'type' => 'user',
286288
'user' => [
287-
'email' => '[email protected]'
289+
'email' => '[email protected]',
290+
],
291+
'visitor' => [
292+
'user_id' => '8a88a590-e1c3-41e2-a502-e0649dbf721c',
288293
],
289-
'type' => 'user'
290294
]);
291295
```
292296

@@ -303,8 +307,8 @@ $client->tags->getTags();
303307
$client->tags->tag([
304308
'name' => 'Test',
305309
'users' => [
306-
['id' => '1234']
307-
]
310+
['id' => '1234'],
311+
],
308312
]);
309313
```
310314

@@ -318,21 +322,23 @@ $client->segments->getSegments();
318322
$client->segments->getSegment('58a707924f6651b07b94376c');
319323

320324
/** View a segment with count */
321-
$client->segments->getSegment('59c124f770e00fd819b9ce81', ['include_count' => 'true']);
325+
$client->segments->getSegment('59c124f770e00fd819b9ce81', [
326+
'include_count' => 'true',
327+
]);
322328
```
323329

324330
## Events
325331

326332
```php
327333
/** Create an event */
328334
$client->events->create([
329-
'event_name' => 'testing',
330335
'created_at' => 1391691571,
331336
'email' => '[email protected]',
337+
'event_name' => 'testing',
332338
'metadata' => [
333339
'order_date' => 1392036272,
334-
'stripe_invoice' => 'inv_3434343434'
335-
]
340+
'stripe_invoice' => 'inv_3434343434',
341+
],
336342
]);
337343

338344
/** View events for a user */
@@ -344,26 +350,25 @@ $client->events->getEvents(['email' => '[email protected]']);
344350
```php
345351
/** Create a company */
346352
$client->companies->create([
353+
'company_id' => '3',
347354
'name' => 'foocorp',
348-
'company_id' => '3'
349355
]);
350356

351357
/**
352358
* Update a company
353359
*/
354360
$client->companies->update([
361+
'id' => '3',
355362
'name' => 'foocorp',
356-
'id' => '3'
357363
]);
358364

359365
/** Create or update a company with custom attributes. */
360366
$client->companies->update([
361-
'name' => 'foocorp',
362-
'id' => '3',
363367
'custom_attributes' => [
364-
'foo' => 'bar',
365-
'baz' => 'qux'
366-
]
368+
'short_name' => 'ABC Inc.',
369+
],
370+
'id' => '3',
371+
'name' => 'foocorp',
367372
]);
368373

369374
/** List Companies */
@@ -376,7 +381,10 @@ $client->companies->getCompany('531ee472cce572a6ec000006');
376381
$client->companies->getCompanyUsers('531ee472cce572a6ec000006');
377382

378383
/** List users belonging to a company by company_id */
379-
$client->companies->getCompanies(['type' => 'user', 'company_id' => '3']);
384+
$client->companies->getCompanies([
385+
'company_id' => '3',
386+
'type' => 'user',
387+
]);
380388

381389
/**
382390
* Add companies to a contact with IDs
@@ -407,17 +415,17 @@ $client->admins->getAdmins();
407415
* See more options here: https://developers.intercom.io/reference#conversations
408416
*/
409417
$client->messages->create([
410-
'message_type' => 'inapp',
411-
'subject' => 'Hey',
412418
'body' => 'Ponies, cute small horses or something more sinister?',
413419
'from' => [
420+
'id' => '1234',
414421
'type' => 'admin',
415-
'id' => '1234'
416422
],
423+
'message_type' => 'inapp',
424+
'subject' => 'Hey',
417425
'to' => [
426+
'email' => '[email protected]',
418427
'type' => 'user',
419-
'email' => '[email protected]'
420-
]
428+
],
421429
]);
422430
```
423431

@@ -429,24 +437,24 @@ $client->messages->create([
429437
* See more options here: https://developers.intercom.io/reference#list-conversations
430438
*/
431439
$client->conversations->getConversations([
440+
'admin_id' => '25610',
432441
'type' => 'admin',
433-
'admin_id' => '25610'
434442
]);
435443

436444
/** Get a single conversation */
437-
$client->conversations->getConversation('1234')
445+
$client->conversations->getConversation('1234');
438446

439447
/** Get a single conversation with plaintext comments */
440448
$client->conversations->getConversation('1234', [
441-
'display_as' => 'plaintext'
442-
])
449+
'display_as' => 'plaintext',
450+
]);
443451

444452
/** Search for conversations (API version >= 2.0) */
445453
$query = ['field' => 'updated_at', 'operator' => '>', 'value' => '1560436784'];
446454
$client->conversations->search([
455+
'pagination' => ['per_page' => 10],
447456
'query' => $query,
448457
'sort' => ['field' => 'updated_at', 'order' => 'ascending'],
449-
'pagination' => ['per_page' => 10]
450458
]);
451459

452460
/** Get next page of conversation search results (API version >= 2.0) */
@@ -457,21 +465,21 @@ $client->conversations->nextSearch($query, $response->pages);
457465
* See more options here: https://developers.intercom.io/reference#replying-to-a-conversation
458466
*/
459467
$client->conversations->replyToConversation('5678', [
460-
'email' => '[email protected]',
461468
'body' => 'Thanks :)',
469+
'email' => '[email protected]',
470+
'message_type' => 'comment',
462471
'type' => 'user',
463-
'message_type' => 'comment'
464472
]);
465473

466474
/**
467475
* Reply to a user's last conversation
468476
* See more options here: https://developers.intercom.com/reference#replying-to-users-last-conversation
469477
*/
470478
$client->conversations->replyToLastConversation([
471-
'email' => '[email protected]',
472479
'body' => 'Thanks :)',
480+
'email' => '[email protected]',
481+
'message_type' => 'comment',
473482
'type' => 'user',
474-
'message_type' => 'comment'
475483
]);
476484

477485
/**
@@ -488,7 +496,7 @@ $client->conversations->markConversationAsRead('7890');
488496
* List counts
489497
* See more options here: https://developers.intercom.io/reference#getting-counts
490498
*/
491-
$client->counts->getCounts([])
499+
$client->counts->getCounts([]);
492500
```
493501

494502
## Notes
@@ -499,13 +507,13 @@ $client->notes->create([
499507
'admin_id' => '21',
500508
'body' => 'Text for my note',
501509
'user' => [
502-
'id' => '5310d8e8598c9a0b24000005'
510+
'id' => '5310d8e8598c9a0b24000005',
503511
]
504512
]);
505513

506514
/** List notes for a user */
507515
$client->notes->getNotes([
508-
'user_id' => '25'
516+
'user_id' => '25',
509517
]);
510518

511519
/** Get a single Note by id */
@@ -522,7 +530,6 @@ $client->teams->getTeams();
522530
$client->teams->getTeam('1188');
523531
```
524532

525-
526533
## Rate Limits
527534

528535
Rate limit info is passed via the rate limit headers.

0 commit comments

Comments
 (0)