Skip to content

Commit

Permalink
chore(*): deprecate events (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
csuvajit committed Dec 24, 2023
1 parent 2775232 commit 8b4dbb1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 34 deletions.
58 changes: 24 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,62 +11,52 @@

### Installation

- **`npm i clashofclans.js`**
- **Node.js v16 or newer is required.**
- **`npm i clashofclans.js`**
- **Node.js v16 or newer is required.**

### Links

- [Documentation](https://clashofclans.js.org/docs/)
- [Clash of Clans Developer Website](https://developer.clashofclans.com/)
- [Clash of Clans API Community Discord](https://discord.gg/Eaja7gJ)
- [Documentation](https://clashofclans.js.org/docs/)
- [Clash of Clans Developer Website](https://developer.clashofclans.com/)
- [Clash of Clans API Community Discord](https://discord.gg/Eaja7gJ)

### Examples

```js
const { Client } = require('clashofclans.js');
```

#### Login with Email Password

```js
const client = new Client();
// const client = new Client({ keys: [], cache: true, retryLimit: 2, restRequestTimeout: 5000 });

(async function () {
await client.login({ email: 'developer@email.com', password: '***' });
// This method should be called once when application starts.
await client.login({ email: 'developer@email.com', password: '***' });

const clan = await client.getClan('#2PP');
console.log(`${clan.name} (${clan.tag})`);
const clan = await client.getClan('#2PP');
console.log(`${clan.name} (${clan.tag})`);
})();
```

### Custom Polling Event

> **Warning** <br />
> Events are neither real-time nor supported by the API. They are polled frequently and compared with the cached data. If there is a difference, the event is emitted.
#### Login with API Keys

```js
const { PollingClient, BatchThrottler } = require('clashofclans.js');
const pollingClient = new PollingClient({
cache: true,
retryLimit: 1,
restRequestTimeout: 5000,
throttler: new BatchThrottler(20)
});

pollingClient.addClans(['#8QU8J9LP', '#8P2QG08P']);
pollingClient.setClanEvent({
name: 'clanDescriptionChange',
filter: (oldClan, newClan) => {
return oldClan.description !== newClan.description;
}
});

pollingClient.on('clanDescriptionChange', (oldClan, newClan) => {
console.log(oldClan.description, newClan.description);
});
const client = new Client({ keys: ['api_key_goes_here'] });

(async function () {
await pollingClient.login({ email: 'developer@email.com', password: '***' });
await pollingClient.init();
const clan = await client.getClan('#2PP');
console.log(`${clan.name} (${clan.tag})`);
})();
```

### Events

The API lacks socket-based real-time events. It is recommended to implement your own custom polling system.
Pull data at specified intervals, compare with previous values, and emit events on change.
Consider using Node.js clusters and threads for efficient parallel processing.

### Disclaimer

> This content is not affiliated with, endorsed, sponsored, or specifically approved by Supercell and Supercell is not responsible for it. For more information see [Supercell's Fan Content Policy](https://supercell.com/en/fan-content-policy/).
3 changes: 3 additions & 0 deletions src/client/PollingClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { Client } from './Client';
* const { PollingClient } = require('clashofclans.js');
* const pollingClient = new PollingClient({ keys: ['***'] });
* ```
* @deprecated The API lacks socket-based real-time events. It is recommended to implement your own custom polling system.
* Pull data at specified intervals, compare with previous values, and emit events on change.
* Consider using Node.js clusters for efficient parallel processing.
*/
export class PollingClient extends Client {
private readonly _clanTags = new Set<string>();
Expand Down

1 comment on commit 8b4dbb1

@csuvajit
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for clashofclans-js ready!

✅ Preview
https://clashofclans-55o2f9gzv-csuvajit.vercel.app

Built with commit 8b4dbb1.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.