Constructor
new ThunderAPI(optionsopt)
Creates a new instance of ThunderAPI
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
options |
ThunderAPIOptions |
<optional> |
{}
|
The timeout in milliseconds to sweep the cache, defaults to 180000 milliseconds |
Members
(private) _intervals :Set.<Timeout>
Intervals set by ThunderAPI#setInterval
that are still active
Type:
- Set.<Timeout>
(private) _timeouts :Set.<Timeout>
Timeouts set by ThunderAPI#setTimeout
that are still active
Type:
- Set.<Timeout>
(readonly) cacheSweepInterval :number
The time cache should be sweeped, in milliseconds
Type:
- number
clans :Collection.<string, Clan>
A collection of cached squadrons. The collection will be sweeped after the time passed
Type:
- Collection.<string, Clan>
(nullable) lastNews :Array.<NewsInfo>
The cached array of news items
Type:
- Array.<NewsInfo>
(private) rest :RequestHandler
The Request Handler for ThunderApi
Type:
- RequestHandler
users :Collection.<string, Profile>
A collection of cached profiles. The collection will be sweeped after the time passed
Type:
- Collection.<string, Profile>
Methods
clearInterval(interval)
Clears an interval.
Parameters:
Name | Type | Description |
---|---|---|
interval |
Timeout | Interval to cancel |
clearTimeout(timeout)
Clears a timeout.
Parameters:
Name | Type | Description |
---|---|---|
timeout |
Timeout | Timeout to cancel |
destroy()
Destroys all assets used by ThunderAPI.
fetchClan(name, cacheopt) → {Promise.<Clan>}
Get's info about a squadron.
Example
// The following example gets info about
// the squadron 35th Gopnik nation battle group,
// and logs the squadron description, and the
// date this squadron was created
ThunderAPI.getSquadron("35th Gopnik nation battle group")
.then(data => {
console.log(data.description);
console.log(data.createdAt);
})
.catch(err => console.error("Oh no, an error occurred!", err));
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
string | The full name of the squadron |
||
cache |
boolean |
<optional> |
true
|
If it should get the squadron from the cache, if cached. Defaults to true |
Returns:
- Type
- Promise.<Clan>
fetchUser(player, cacheopt) → {Promise.<User>}
Get a player's profile
Example
// The following example gets the profile of the player
// TheDutchy0412 and logs the squadron name
// and the registration date
ThunderAPI.getPlayer("TheDutchy0412")
.then(profile => {
console.log(profile.squadron);
console.log(profile.registered);
})
.catch(err => console.error("Oh no, an error occurred!", err));
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
player |
string | The profile of the player to fetch |
||
cache |
boolean |
<optional> |
true
|
If it should get the player from the cache. Defaults to true |
Returns:
- Type
- Promise.<User>
getNews(cacheopt) → {Promise.<Array.<NewsInfo>>}
Returns an array of news objects
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
cache |
boolean |
<optional> |
true
|
If it should return the cached news object. Defaults to true |
Returns:
- Type
- Promise.<Array.<NewsInfo>>
isUser(player) → {Promise.<boolean>}
Verifies the given player's in-game nickname
Parameters:
Name | Type | Description |
---|---|---|
player |
string | The player to verify |
Returns:
- Type
- Promise.<boolean>
searchWiki(query) → {Promise.<Array.<Wiki>>}
Searches on the War Thunder wiki
Parameters:
Name | Type | Description |
---|---|---|
query |
string | The query to search on |
Returns:
- Type
- Promise.<Array.<Wiki>>
setInterval(fn, delay, …args) → {Timeout}
Sets an interval that will be automatically cancelled if the client is destroyed.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fn |
function | Function to execute |
|
delay |
number | Time to wait between executions (in milliseconds) |
|
args |
* |
<repeatable> |
Arguments for the function |
Returns:
- Type
- Timeout
setTimeout(fn, delay, …args) → {Timeout}
Sets a timeout that will be automatically cancelled if the instance of ThunderAPI is destroyed.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fn |
function | Function to execute |
|
delay |
number | Time to wait before executing (in milliseconds) |
|
args |
* |
<repeatable> |
Arguments for the function |
Returns:
- Type
- Timeout
sweepCache() → {boolean}
Sweeps the cache
Returns:
If the cache sweep was successful
- Type
- boolean