-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2119 from ably/EDU-362-update-docs-js-code-sample…
…s-to-use-promise-based-sdk-functionality [EDU-362] - Update Channels docs Javascript and NodeJS examples to use Promise based SDK functionality
- Loading branch information
Showing
22 changed files
with
708 additions
and
650 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,20 +93,21 @@ A sample request to revoke an Ably token based on @clientId@, using the REST int | |
```[rest_javascript] | ||
const Ably = require('ably'); | ||
|
||
const ablyRest = new Ably.Rest({ key: '{{API_KEY}}' }); | ||
const ablyRest = new Ably.Rest.Promise({ key: '{{API_KEY}}' }); | ||
const requestBody = { targets: ['clientId:[email protected]'] }; | ||
|
||
ablyRest.request('post', '/keys/{{API_KEY_NAME}}/revokeTokens', null, requestBody, null, | ||
|
||
function (err, response) { | ||
console.log(response); | ||
if (!response.success) { | ||
console.log('An error occurred; err = ' + response.errorMessage); | ||
} else { | ||
console.log('Success! status code was ' + response.statusCode); | ||
} | ||
} | ||
const revocationResponse = await ablyRest.request( | ||
'post', | ||
'/keys/{{API_KEY_NAME}}/revokeTokens', | ||
null, | ||
requestBody | ||
); | ||
|
||
if (!revocationResponse.success) { | ||
console.log('An error occurred; err = ' + revocationResponse.errorMessage); | ||
} else { | ||
console.log('Success! status code was ' + revocationResponse.statusCode); | ||
} | ||
``` | ||
|
||
In this example, the token with the unique client ID <code>[email protected]</code> would be revoked. | ||
|
@@ -128,18 +129,21 @@ A sample request to revoke a JWT based on @revocationKey@, using the REST interf | |
```[rest_javascript] | ||
const Ably = require('ably'); | ||
|
||
const ablyRest = new Ably.Rest({ key: '{{API_KEY}}' }) | ||
const ablyRest = new Ably.Rest.Promise({ key: '{{API_KEY}}' }) | ||
const requestBody = { targets: ['revocationKey:[email protected]'] }; | ||
ablyRest.request('post', '/keys/{{API_KEY_NAME}}/revokeTokens', null, requestBody, null, | ||
function (err, response) { | ||
console.log(response); | ||
if (!response.success) { | ||
console.log('An error occurred; err = ' + response.errorMessage); | ||
} else { | ||
console.log('Success! status code was ' + response.statusCode); | ||
} | ||
} | ||
const revocationResponse = await ablyRest.request( | ||
'post', | ||
'/keys/{{API_KEY_NAME}}/revokeTokens', | ||
null, | ||
requestBody, | ||
null | ||
); | ||
|
||
if (!revocationResponse.success) { | ||
console.log('An error occurred; err = ' + revocationResponse.errorMessage); | ||
} else { | ||
console.log('Success! status code was ' + revocationResponse.statusCode); | ||
} | ||
``` | ||
|
||
In this example, all users that have been assigned the revocation key <code>[email protected]</code> would have their tokens revoked. | ||
|
Oops, something went wrong.