r6-data.js 2.0.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -301,6 +301,50 @@ The `getSeasonalStats()` function accepts the API Key and an object with the fol
301
301
  }
302
302
  ```
303
303
 
304
+ ## Getting Operator Statistics
305
+
306
+ The `getOperatorStats()` function allows you to get detailed operator statistics for a specific player.
307
+
308
+ ```javascript
309
+ const r6Info = require('r6-data.js');
310
+
311
+ async function main() {
312
+ try {
313
+ const apiKey = 'YOUR_API_KEY';
314
+
315
+ // Get operator statistics for a player
316
+ const operatorStats = await r6Info.getOperatorStats(apiKey, {
317
+ nameOnPlatform: 'PlayerName',
318
+ platformType: 'uplay',
319
+ // seasonYear: 'Y9S4', // Optional
320
+ // modes: 'ranked' // Optional, default is 'ranked'
321
+ });
322
+
323
+ console.log('Operator statistics:', operatorStats);
324
+ return operatorStats;
325
+
326
+ } catch (error) {
327
+ console.error('Error retrieving operator statistics:', error.message);
328
+ }
329
+ }
330
+
331
+ main();
332
+ ```
333
+
334
+ ### Parameters
335
+
336
+ The `getOperatorStats()` function accepts the API Key and an object with the following parameters:
337
+
338
+ - `apiKey`: (Required) Your API Key from r6data.eu
339
+ - `nameOnPlatform`: (Required) The player's name on the platform
340
+ - `platformType`: (Required) The platform type - "uplay", "psn", or "xbl"
341
+ - `seasonYear`: (Optional) Season year (e.g., Y9S4, Y10S4)
342
+ - `modes`: (Optional) Game mode (ranked, casual, unranked). Default is 'ranked'.
343
+
344
+ ### Operator Statistics Response
345
+
346
+ The response contains detailed statistics for each operator played by the user.
347
+
304
348
  ## Getting Game Statistics
305
349
 
306
350
  The `getGameStats()` function allows you to get real-time player count statistics across all platforms including Steam, Ubisoft Connect, PlayStation, Xbox, and total player counts
@@ -1,4 +1,5 @@
1
1
  const axios = require('axios');
2
+ const pkg = require('../package.json');
2
3
 
3
4
  const axiosInstance = axios.create({
4
5
  baseURL: 'https://api.r6data.eu/api',
@@ -6,6 +7,7 @@ const axiosInstance = axios.create({
6
7
  'Content-Type': 'application/json',
7
8
  'Accept': 'application/json',
8
9
  'Cache-Control': 'no-cache',
10
+ 'User-Agent': `r6-data.js/${pkg.version}`,
9
11
  },
10
12
  });
11
13
 
package/index.js CHANGED
@@ -13,6 +13,7 @@ const getPlayerStats = require('./methods/getPlayerStats');
13
13
  const createDiscordR6Webhook = require('./methods/createDiscordR6Webhook');
14
14
  const getGameStats = require('./methods/getGameStats');
15
15
  const getSeasonalStats = require('./methods/getSeasonalStats');
16
+ const getOperatorStats = require('./methods/getOperatorStats');
16
17
  const getPlayerComparisons = require('./methods/getPlayerComparisons');
17
18
  const getIsBanned = require('./methods/getIsBanned');
18
19
 
@@ -33,6 +34,7 @@ module.exports = {
33
34
  createDiscordR6Webhook,
34
35
  getGameStats,
35
36
  getSeasonalStats,
37
+ getOperatorStats,
36
38
  getPlayerComparisons,
37
39
  getIsBanned,
38
40
  };
@@ -53,5 +55,6 @@ module.exports.getPlayerStats = getPlayerStats;
53
55
  module.exports.createDiscordR6Webhook = createDiscordR6Webhook;
54
56
  module.exports.getGameStats = getGameStats;
55
57
  module.exports.getSeasonalStats = getSeasonalStats;
58
+ module.exports.getOperatorStats = getOperatorStats;
56
59
  module.exports.getPlayerComparisons = getPlayerComparisons;
57
60
  module.exports.getIsBanned = getIsBanned;
@@ -11,7 +11,8 @@ async function createDiscordR6Webhook(webhookUrl, playerData, options = {}) {
11
11
  }
12
12
 
13
13
  // Validate webhook URL format
14
- if (!webhookUrl.includes('discord.com/api/webhooks/')) {
14
+ const discordWebhookRegex = /^https:\/\/(?:ptb\.|canary\.)?discord\.com\/api\/webhooks\/\d+\/[A-Za-z0-9-_]+$/;
15
+ if (!discordWebhookRegex.test(webhookUrl)) {
15
16
  throw new Error('Invalid Discord webhook URL format');
16
17
  }
17
18
 
@@ -1,47 +1,47 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- /**
5
- * Get Rainbow Six Siege player account information
6
- * @param {string} apiKey - Your API Key from r6data.eu
7
- * @param {Object} params - Parameters for the request
8
- * @param {string} params.nameOnPlatform - Player name on the platform
9
- * @param {string} params.platformType - Platform type (uplay, psn, xbl)
10
- * @returns {Promise<Object>} - Player account information
11
- */
12
- async function getAccountInfo(apiKey, { nameOnPlatform, platformType } = {}) {
13
- try {
14
- // Validate required parameters
15
- if (!apiKey) {
16
- throw new Error('Missing required parameter: apiKey');
17
- }
18
- if (!nameOnPlatform || !platformType) {
19
- throw new Error('Missing required parameters: nameOnPlatform, platformType');
20
- }
21
-
22
- // Build the URL with parameters
23
- const params = {
24
- type: 'accountInfo',
25
- nameOnPlatform,
26
- platformType
27
- };
28
-
29
- const url = buildUrlAndParams('/stats', params);
30
-
31
- const response = await axiosInstance.get(url, {
32
- headers: {
33
- 'api-key': apiKey
34
- }
35
- });
36
-
37
- return response.data;
38
- } catch (error) {
39
- console.error('Error during the getAccountInfo request:', error.message);
40
- if (error.response && error.response.status === 401) {
41
- throw new Error('Authentication error');
42
- }
43
- throw error;
44
- }
45
- }
46
-
47
- module.exports = getAccountInfo;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ /**
5
+ * Get Rainbow Six Siege player account information
6
+ * @param {string} apiKey - Your API Key from r6data.eu
7
+ * @param {Object} params - Parameters for the request
8
+ * @param {string} params.nameOnPlatform - Player name on the platform
9
+ * @param {string} params.platformType - Platform type (uplay, psn, xbl)
10
+ * @returns {Promise<Object>} - Player account information
11
+ */
12
+ async function getAccountInfo(apiKey, { nameOnPlatform, platformType } = {}) {
13
+ try {
14
+ // Validate required parameters
15
+ if (!apiKey) {
16
+ throw new Error('Missing required parameter: apiKey');
17
+ }
18
+ if (!nameOnPlatform || !platformType) {
19
+ throw new Error('Missing required parameters: nameOnPlatform, platformType');
20
+ }
21
+
22
+ // Build the URL with parameters
23
+ const params = {
24
+ type: 'accountInfo',
25
+ nameOnPlatform,
26
+ platformType
27
+ };
28
+
29
+ const url = buildUrlAndParams('/stats', params);
30
+
31
+ const response = await axiosInstance.get(url, {
32
+ headers: {
33
+ 'api-key': apiKey
34
+ }
35
+ });
36
+
37
+ return response.data;
38
+ } catch (error) {
39
+ console.error('Error during the getAccountInfo request:', error.message);
40
+ if (error.response && error.response.status === 401) {
41
+ throw new Error('Authentication error');
42
+ }
43
+ throw error;
44
+ }
45
+ }
46
+
47
+ module.exports = getAccountInfo;
@@ -1,28 +1,28 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- async function getAttachment(apiKey, { name, style, rarity, availability, bundle, season } = {}) {
5
- try {
6
- if (!apiKey) {
7
- throw new Error('Missing required parameter: apiKey');
8
- }
9
-
10
- const url = buildUrlAndParams('/attachment', { name, style, rarity, availability, bundle, season });
11
-
12
- const response = await axiosInstance.get(url, {
13
- headers: {
14
- 'api-key': apiKey
15
- }
16
- });
17
-
18
- return response.data;
19
- } catch (error) {
20
- console.error('Error during the getAttachment request:', error.message);
21
- if (error.response && error.response.status === 401) {
22
- throw new Error('request error');
23
- }
24
- throw error;
25
- }
26
- }
27
-
28
- module.exports = getAttachment;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ async function getAttachment(apiKey, { name, style, rarity, availability, bundle, season } = {}) {
5
+ try {
6
+ if (!apiKey) {
7
+ throw new Error('Missing required parameter: apiKey');
8
+ }
9
+
10
+ const url = buildUrlAndParams('/attachment', { name, style, rarity, availability, bundle, season });
11
+
12
+ const response = await axiosInstance.get(url, {
13
+ headers: {
14
+ 'api-key': apiKey
15
+ }
16
+ });
17
+
18
+ return response.data;
19
+ } catch (error) {
20
+ console.error('Error during the getAttachment request:', error.message);
21
+ if (error.response && error.response.status === 401) {
22
+ throw new Error('request error');
23
+ }
24
+ throw error;
25
+ }
26
+ }
27
+
28
+ module.exports = getAttachment;
@@ -1,28 +1,28 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- async function getCharms(apiKey, { name, collection, rarity, availability, bundle, season } = {}) {
5
- try {
6
- if (!apiKey) {
7
- throw new Error('Missing required parameter: apiKey');
8
- }
9
-
10
- const url = buildUrlAndParams('/charms', { name, collection, rarity, availability, bundle, season });
11
-
12
- const response = await axiosInstance.get(url, {
13
- headers: {
14
- 'api-key': apiKey
15
- }
16
- });
17
-
18
- return response.data;
19
- } catch (error) {
20
- console.error('Errore during the getCharms request:', error.message);
21
- if (error.response && error.response.status === 401) {
22
- throw new Error('request error');
23
- }
24
- throw error;
25
- }
26
- }
27
-
28
- module.exports = getCharms;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ async function getCharms(apiKey, { name, collection, rarity, availability, bundle, season } = {}) {
5
+ try {
6
+ if (!apiKey) {
7
+ throw new Error('Missing required parameter: apiKey');
8
+ }
9
+
10
+ const url = buildUrlAndParams('/charms', { name, collection, rarity, availability, bundle, season });
11
+
12
+ const response = await axiosInstance.get(url, {
13
+ headers: {
14
+ 'api-key': apiKey
15
+ }
16
+ });
17
+
18
+ return response.data;
19
+ } catch (error) {
20
+ console.error('Errore during the getCharms request:', error.message);
21
+ if (error.response && error.response.status === 401) {
22
+ throw new Error('request error');
23
+ }
24
+ throw error;
25
+ }
26
+ }
27
+
28
+ module.exports = getCharms;
@@ -1,38 +1,38 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- /**
5
- * Get Rainbow Six Siege game stats for all platform
6
- * @param {string} apiKey - Your API Key from r6data.eu
7
- * @returns {Promise<Object>} - Game stats for all platform
8
- */
9
- async function getGameStats(apiKey) {
10
- try {
11
- if (!apiKey) {
12
- throw new Error('Missing required parameter: apiKey');
13
- }
14
-
15
- // Build the URL with parameters
16
- const params = {
17
- type: 'gameStats'
18
- };
19
-
20
- const url = buildUrlAndParams('/stats', params);
21
-
22
- const response = await axiosInstance.get(url, {
23
- headers: {
24
- 'api-key': apiKey
25
- }
26
- });
27
-
28
- return response.data;
29
- } catch (error) {
30
- console.error('Error during the game stats request:', error.message);
31
- if (error.response && error.response.status === 401) {
32
- throw new Error('request error');
33
- }
34
- throw error;
35
- }
36
- }
37
-
38
- module.exports = getGameStats;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ /**
5
+ * Get Rainbow Six Siege game stats for all platform
6
+ * @param {string} apiKey - Your API Key from r6data.eu
7
+ * @returns {Promise<Object>} - Game stats for all platform
8
+ */
9
+ async function getGameStats(apiKey) {
10
+ try {
11
+ if (!apiKey) {
12
+ throw new Error('Missing required parameter: apiKey');
13
+ }
14
+
15
+ // Build the URL with parameters
16
+ const params = {
17
+ type: 'gameStats'
18
+ };
19
+
20
+ const url = buildUrlAndParams('/stats', params);
21
+
22
+ const response = await axiosInstance.get(url, {
23
+ headers: {
24
+ 'api-key': apiKey
25
+ }
26
+ });
27
+
28
+ return response.data;
29
+ } catch (error) {
30
+ console.error('Error during the game stats request:', error.message);
31
+ if (error.response && error.response.status === 401) {
32
+ throw new Error('request error');
33
+ }
34
+ throw error;
35
+ }
36
+ }
37
+
38
+ module.exports = getGameStats;
@@ -1,47 +1,47 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- /**
5
- * Get Rainbow Six Siege player ban status
6
- * @param {string} apiKey - Your API Key from r6data.eu
7
- * @param {Object} params - Parameters for the request
8
- * @param {string} params.nameOnPlatform - Player name on the platform
9
- * @param {string} params.platformType - Platform type (uplay, psn, xbl)
10
- * @returns {Promise<Object>} - Player ban status
11
- */
12
- async function getIsBanned(apiKey, { nameOnPlatform, platformType } = {}) {
13
- try {
14
- // Validate required parameters
15
- if (!apiKey) {
16
- throw new Error('Missing required parameter: apiKey');
17
- }
18
- if (!nameOnPlatform || !platformType) {
19
- throw new Error('Missing required parameters: nameOnPlatform, platformType');
20
- }
21
-
22
- // Build the URL with parameters
23
- const params = {
24
- type: 'isBanned',
25
- nameOnPlatform,
26
- platformType
27
- };
28
-
29
- const url = buildUrlAndParams('/stats', params);
30
-
31
- const response = await axiosInstance.get(url, {
32
- headers: {
33
- 'api-key': apiKey
34
- }
35
- });
36
-
37
- return response.data;
38
- } catch (error) {
39
- console.error('Error during the getIsBanned request:', error.message);
40
- if (error.response && error.response.status === 401) {
41
- throw new Error('Authentication error');
42
- }
43
- throw error;
44
- }
45
- }
46
-
47
- module.exports = getIsBanned;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ /**
5
+ * Get Rainbow Six Siege player ban status
6
+ * @param {string} apiKey - Your API Key from r6data.eu
7
+ * @param {Object} params - Parameters for the request
8
+ * @param {string} params.nameOnPlatform - Player name on the platform
9
+ * @param {string} params.platformType - Platform type (uplay, psn, xbl)
10
+ * @returns {Promise<Object>} - Player ban status
11
+ */
12
+ async function getIsBanned(apiKey, { nameOnPlatform, platformType } = {}) {
13
+ try {
14
+ // Validate required parameters
15
+ if (!apiKey) {
16
+ throw new Error('Missing required parameter: apiKey');
17
+ }
18
+ if (!nameOnPlatform || !platformType) {
19
+ throw new Error('Missing required parameters: nameOnPlatform, platformType');
20
+ }
21
+
22
+ // Build the URL with parameters
23
+ const params = {
24
+ type: 'isBanned',
25
+ nameOnPlatform,
26
+ platformType
27
+ };
28
+
29
+ const url = buildUrlAndParams('/stats', params);
30
+
31
+ const response = await axiosInstance.get(url, {
32
+ headers: {
33
+ 'api-key': apiKey
34
+ }
35
+ });
36
+
37
+ return response.data;
38
+ } catch (error) {
39
+ console.error('Error during the getIsBanned request:', error.message);
40
+ if (error.response && error.response.status === 401) {
41
+ throw new Error('Authentication error');
42
+ }
43
+ throw error;
44
+ }
45
+ }
46
+
47
+ module.exports = getIsBanned;
@@ -1,28 +1,28 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- async function getMaps(apiKey, { name, location, releaseDate, playlists, mapReworked } = {}) {
5
- try {
6
- if (!apiKey) {
7
- throw new Error('Missing required parameter: apiKey');
8
- }
9
-
10
- const url = buildUrlAndParams('/maps', { name, location, releaseDate, playlists, mapReworked });
11
-
12
- const response = await axiosInstance.get(url, {
13
- headers: {
14
- 'api-key': apiKey
15
- }
16
- });
17
-
18
- return response.data;
19
- } catch (error) {
20
- console.error('Error during the getMaps request:', error.message);
21
- if (error.response && error.response.status === 401) {
22
- throw new Error('request error');
23
- }
24
- throw error;
25
- }
26
- }
27
-
28
- module.exports = getMaps;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ async function getMaps(apiKey, { name, location, releaseDate, playlists, mapReworked } = {}) {
5
+ try {
6
+ if (!apiKey) {
7
+ throw new Error('Missing required parameter: apiKey');
8
+ }
9
+
10
+ const url = buildUrlAndParams('/maps', { name, location, releaseDate, playlists, mapReworked });
11
+
12
+ const response = await axiosInstance.get(url, {
13
+ headers: {
14
+ 'api-key': apiKey
15
+ }
16
+ });
17
+
18
+ return response.data;
19
+ } catch (error) {
20
+ console.error('Error during the getMaps request:', error.message);
21
+ if (error.response && error.response.status === 401) {
22
+ throw new Error('request error');
23
+ }
24
+ throw error;
25
+ }
26
+ }
27
+
28
+ module.exports = getMaps;
@@ -0,0 +1,54 @@
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ /**
5
+ * Get Rainbow Six Siege operator stats
6
+ * @param {string} apiKey - Your API Key from r6data.eu
7
+ * @param {Object} params - Parameters for the request
8
+ * @param {string} params.nameOnPlatform - Player name on the platform
9
+ * @param {string} params.platformType - Platform type (uplay, psn, xbl)
10
+ * @param {string} [params.seasonYear] - Season year (e.g., Y9S4, Y10S4)
11
+ * @param {string} [params.modes] - Game mode (ranked, casual, unranked). Default is 'ranked'.
12
+ * @returns {Promise<Object>} - Operator stats
13
+ */
14
+ async function getOperatorStats(apiKey, { nameOnPlatform, platformType, seasonYear, modes } = {}) {
15
+ try {
16
+ // Validate required parameters
17
+ if (!apiKey) {
18
+ throw new Error('Missing required parameter: apiKey');
19
+ }
20
+ if (!nameOnPlatform || !platformType) {
21
+ throw new Error('Missing required parameters: nameOnPlatform, platformType');
22
+ }
23
+
24
+ // Build the URL with parameters
25
+ const params = {
26
+ type: 'operatorStats',
27
+ nameOnPlatform,
28
+ platformType,
29
+ modes
30
+ };
31
+
32
+ if (seasonYear) {
33
+ params.seasonYear = seasonYear;
34
+ }
35
+
36
+ const url = buildUrlAndParams('/stats', params);
37
+
38
+ const response = await axiosInstance.get(url, {
39
+ headers: {
40
+ 'api-key': apiKey
41
+ }
42
+ });
43
+
44
+ return response.data;
45
+ } catch (error) {
46
+ console.error('Error during the getOperatorStats request:', error.message);
47
+ if (error.response && error.response.status === 401) {
48
+ throw new Error('Authentication error');
49
+ }
50
+ throw error;
51
+ }
52
+ }
53
+
54
+ module.exports = getOperatorStats;
@@ -1,28 +1,28 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- async function getOperators(apiKey, { name, safename, realname, birthplace, age, date_of_birth, season_introduced, health, speed, unit, country_code, roles, side } = {}) {
5
- try {
6
- if (!apiKey) {
7
- throw new Error('Missing required parameter: apiKey');
8
- }
9
-
10
- const url = buildUrlAndParams('/operators', { name, safename, realname, birthplace, age, date_of_birth, season_introduced, health, speed, unit, country_code, roles, side });
11
-
12
- const response = await axiosInstance.get(url, {
13
- headers: {
14
- 'api-key': apiKey
15
- }
16
- });
17
-
18
- return response.data;
19
- } catch (error) {
20
- console.error('Error during the getOperators request:', error.message);
21
- if (error.response && error.response.status === 401) {
22
- throw new Error('request error');
23
- }
24
- throw error;
25
- }
26
- }
27
-
28
- module.exports = getOperators;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ async function getOperators(apiKey, { name, safename, realname, birthplace, age, date_of_birth, season_introduced, health, speed, unit, country_code, roles, side } = {}) {
5
+ try {
6
+ if (!apiKey) {
7
+ throw new Error('Missing required parameter: apiKey');
8
+ }
9
+
10
+ const url = buildUrlAndParams('/operators', { name, safename, realname, birthplace, age, date_of_birth, season_introduced, health, speed, unit, country_code, roles, side });
11
+
12
+ const response = await axiosInstance.get(url, {
13
+ headers: {
14
+ 'api-key': apiKey
15
+ }
16
+ });
17
+
18
+ return response.data;
19
+ } catch (error) {
20
+ console.error('Error during the getOperators request:', error.message);
21
+ if (error.response && error.response.status === 401) {
22
+ throw new Error('request error');
23
+ }
24
+ throw error;
25
+ }
26
+ }
27
+
28
+ module.exports = getOperators;