File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed
Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,24 @@ client.events.create({
8080});
8181```
8282
83+ ## Pagination
84+
85+ When listing, the Intercom API may return a pagination object:
86+
87+ ``` json
88+ {
89+ "pages" : {
90+ "next" : " ..."
91+ }
92+ }
93+ ```
94+
95+ You can grab the next page of results using the client:
96+
97+ ```
98+ client.nextPage(response.pages, callback);
99+ ```
100+
83101## License
84102
85103Apache-2.0
Original file line number Diff line number Diff line change @@ -32,6 +32,13 @@ export class Client {
3232 . header ( 'Accept' , 'application/json' )
3333 . end ( r => f ( r ) ) ;
3434 }
35+ nextPage ( paginationObject , f ) {
36+ unirest . get ( paginationObject . next )
37+ . auth ( this . appId , this . appApiKey )
38+ . type ( 'json' )
39+ . header ( 'Accept' , 'application/json' )
40+ . end ( r => f ( r ) ) ;
41+ }
3542 delete ( endpoint , data , f ) {
3643 unirest . delete ( `https://api.intercom.io${ endpoint } ` )
3744 . auth ( this . appId , this . appApiKey )
Original file line number Diff line number Diff line change @@ -16,4 +16,13 @@ describe('clients', function () {
1616 done ( ) ;
1717 } ) ;
1818 } ) ;
19+ it ( 'paginate' , function ( done ) {
20+ nock ( 'https://api.intercom.io' ) . get ( '/foo/bar/baz' ) . query ( { blue : 'red' } ) . reply ( 200 , { foo : 'bar' } ) ;
21+ let client = new Client ( 'foo' , 'bar' ) ;
22+ let paginationObject = { next : 'https://api.intercom.io/foo/bar/baz?blue=red' } ;
23+ client . nextPage ( paginationObject , function ( r ) {
24+ assert . deepEqual ( { foo : 'bar' } , r . body ) ;
25+ done ( ) ;
26+ } ) ;
27+ } ) ;
1928} ) ;
You can’t perform that action at this time.
0 commit comments