r6-data.js 1.8.3 → 2.0.1

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.
@@ -1,75 +1,83 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- /**
5
- * Get Rainbow Six Siege player statistics
6
- * @param {Object} params - Parameters for the request
7
- * @param {string} params.nameOnPlatform - Player name on the platform
8
- * @param {string} params.platformType - Platform type (uplay, psn, xbl)
9
- * @param {string} params.platform_families - Platform families: "pc" or "console"
10
- * @param {string} [params.board_id] - Game mode to filter stats (casual, event, warmup, standard, ranked)
11
- * @returns {Promise<Object>} - Player statistics
12
- */
13
- async function getPlayerStats({ nameOnPlatform, platformType, platform_families, board_id } = {}) {
14
- try {
15
- // Validate required parameters
16
- if (!nameOnPlatform || !platformType || !platform_families) {
17
- throw new Error('Missing required parameters: nameOnPlatform, platformType, platform_families');
18
- }
19
-
20
- // Validate board_id if provided
21
- if (board_id && !['casual', 'event', 'warmup', 'standard', 'ranked'].includes(board_id)) {
22
- throw new Error('Invalid board_id. Must be one of: casual, event, warmup, standard, ranked');
23
- }
24
-
25
- // Build the URL with parameters
26
- const params = {
27
- type: 'stats',
28
- nameOnPlatform,
29
- platformType,
30
- platform_families
31
- };
32
-
33
- // Add board_id if provided
34
- if (board_id) {
35
- params.board_id = board_id;
36
- }
37
-
38
- const url = buildUrlAndParams('/stats', params);
39
-
40
- const response = await axiosInstance.get(url);
41
-
42
- if (response.data &&
43
- response.data.platform_families_full_profiles &&
44
- response.data.platform_families_full_profiles.length > 0) {
45
-
46
- // If board_id is specified, filter the response data
47
- if (board_id && response.data.platform_families_full_profiles) {
48
- response.data.platform_families_full_profiles.forEach(profile => {
49
- if (profile.board_ids_full_profiles) {
50
- // Filter to only include the specified board_id
51
- profile.board_ids_full_profiles = profile.board_ids_full_profiles.filter(
52
- board => board.board_id === board_id
53
- );
54
- }
55
- });
56
- }
57
-
58
- response.data.platform_families_full_profiles.forEach(profile => {
59
- if (profile.board_ids_full_profiles) {
60
- console.log(JSON.stringify(profile.board_ids_full_profiles, null, 2));
61
- }
62
- });
63
- }
64
-
65
- return response.data;
66
- } catch (error) {
67
- console.error('Error during the getPlayerStats request:', error.message);
68
- if (error.response && error.response.status === 401) {
69
- throw new Error('Authentication error');
70
- }
71
- throw error;
72
- }
73
- }
74
-
75
- module.exports = getPlayerStats;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ /**
5
+ * Get Rainbow Six Siege player statistics
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.platform_families - Platform families: "pc" or "console"
11
+ * @param {string} [params.board_id] - Game mode to filter stats (casual, event, warmup, standard, ranked)
12
+ * @returns {Promise<Object>} - Player statistics
13
+ */
14
+ async function getPlayerStats(apiKey, { nameOnPlatform, platformType, platform_families, board_id } = {}) {
15
+ try {
16
+ // Validate required parameters
17
+ if (!apiKey) {
18
+ throw new Error('Missing required parameter: apiKey');
19
+ }
20
+ if (!nameOnPlatform || !platformType || !platform_families) {
21
+ throw new Error('Missing required parameters: nameOnPlatform, platformType, platform_families');
22
+ }
23
+
24
+ // Validate board_id if provided
25
+ if (board_id && !['casual', 'event', 'warmup', 'standard', 'ranked'].includes(board_id)) {
26
+ throw new Error('Invalid board_id. Must be one of: casual, event, warmup, standard, ranked');
27
+ }
28
+
29
+ // Build the URL with parameters
30
+ const params = {
31
+ type: 'stats',
32
+ nameOnPlatform,
33
+ platformType,
34
+ platform_families
35
+ };
36
+
37
+ // Add board_id if provided
38
+ if (board_id) {
39
+ params.board_id = board_id;
40
+ }
41
+
42
+ const url = buildUrlAndParams('/stats', params);
43
+
44
+ const response = await axiosInstance.get(url, {
45
+ headers: {
46
+ 'api-key': apiKey
47
+ }
48
+ });
49
+
50
+ if (response.data &&
51
+ response.data.platform_families_full_profiles &&
52
+ response.data.platform_families_full_profiles.length > 0) {
53
+
54
+ // If board_id is specified, filter the response data
55
+ if (board_id && response.data.platform_families_full_profiles) {
56
+ response.data.platform_families_full_profiles.forEach(profile => {
57
+ if (profile.board_ids_full_profiles) {
58
+ // Filter to only include the specified board_id
59
+ profile.board_ids_full_profiles = profile.board_ids_full_profiles.filter(
60
+ board => board.board_id === board_id
61
+ );
62
+ }
63
+ });
64
+ }
65
+
66
+ response.data.platform_families_full_profiles.forEach(profile => {
67
+ if (profile.board_ids_full_profiles) {
68
+ console.log(JSON.stringify(profile.board_ids_full_profiles, null, 2));
69
+ }
70
+ });
71
+ }
72
+
73
+ return response.data;
74
+ } catch (error) {
75
+ console.error('Error during the getPlayerStats request:', error.message);
76
+ if (error.response && error.response.status === 401) {
77
+ throw new Error('Authentication error');
78
+ }
79
+ throw error;
80
+ }
81
+ }
82
+
83
+ module.exports = getPlayerStats;
@@ -1,25 +1,32 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- async function getRanks({ name, min_mmr, max_mmr, version } = {}) {
5
- try {
6
-
7
- if (!['v1', 'v2', 'v3', 'v4', 'v5', 'v6'].includes(version)) {
8
- throw new Error('Version not valid. Choose between v1, v2, v3, v4, v5, and v6.');
9
- }
10
-
11
- const url = buildUrlAndParams('/ranks', { name, min_mmr, max_mmr, version });
12
-
13
- const response = await axiosInstance.get(url);
14
-
15
- return response.data;
16
- } catch (error) {
17
- console.error('Error during the getRanks request:', error.message);
18
- if (error.response && error.response.status === 401) {
19
- throw new Error('request error');
20
- }
21
- throw error;
22
- }
23
- }
24
-
25
- module.exports = getRanks;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ async function getRanks(apiKey, { name, min_mmr, max_mmr, version } = {}) {
5
+ try {
6
+ if (!apiKey) {
7
+ throw new Error('Missing required parameter: apiKey');
8
+ }
9
+
10
+ if (!['v1', 'v2', 'v3', 'v4', 'v5', 'v6'].includes(version)) {
11
+ throw new Error('Version not valid. Choose between v1, v2, v3, v4, v5, and v6.');
12
+ }
13
+
14
+ const url = buildUrlAndParams('/ranks', { name, min_mmr, max_mmr, version });
15
+
16
+ const response = await axiosInstance.get(url, {
17
+ headers: {
18
+ 'api-key': apiKey
19
+ }
20
+ });
21
+
22
+ return response.data;
23
+ } catch (error) {
24
+ console.error('Error during the getRanks request:', error.message);
25
+ if (error.response && error.response.status === 401) {
26
+ throw new Error('request error');
27
+ }
28
+ throw error;
29
+ }
30
+ }
31
+
32
+ module.exports = getRanks;
@@ -1,27 +1,35 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- /**
5
- * Search across all R6 entities (operators, weapons, maps, etc.)
6
- * @param {string} query - The search term to query across all entities
7
- * @returns {Promise<Object>} - Search results organized by entity type
8
- */
9
- async function getSearchAll(query) {
10
- if (!query || typeof query !== 'string') {
11
- throw new Error('Search query is required and must be a string');
12
- }
13
-
14
- try {
15
- const url = buildUrlAndParams('/searchAll', { q: query });
16
- const response = await axiosInstance.get(url);
17
- return response.data;
18
- } catch (error) {
19
- console.error('Error during the getSearchAll request:', error.message);
20
- if (error.response && error.response.status === 401) {
21
- throw new Error('Authentication error');
22
- }
23
- throw error;
24
- }
25
- }
26
-
27
- module.exports = getSearchAll;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ /**
5
+ * Search across all R6 entities (operators, weapons, maps, etc.)
6
+ * @param {string} apiKey - Your API Key from r6data.eu
7
+ * @param {string} query - The search term to query across all entities
8
+ * @returns {Promise<Object>} - Search results organized by entity type
9
+ */
10
+ async function getSearchAll(apiKey, query) {
11
+ if (!apiKey) {
12
+ throw new Error('Missing required parameter: apiKey');
13
+ }
14
+ if (!query || typeof query !== 'string') {
15
+ throw new Error('Search query is required and must be a string');
16
+ }
17
+
18
+ try {
19
+ const url = buildUrlAndParams('/searchAll', { q: query });
20
+ const response = await axiosInstance.get(url, {
21
+ headers: {
22
+ 'api-key': apiKey
23
+ }
24
+ });
25
+ return response.data;
26
+ } catch (error) {
27
+ console.error('Error during the getSearchAll request:', error.message);
28
+ if (error.response && error.response.status === 401) {
29
+ throw new Error('Authentication error');
30
+ }
31
+ throw error;
32
+ }
33
+ }
34
+
35
+ module.exports = getSearchAll;
@@ -1,39 +1,47 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- /**
5
- * Get Rainbow Six Siege player stats for current season
6
- * @param {Object} params - Parameters for the request
7
- * @param {string} params.nameOnPlatform - Player name on the platform
8
- * @param {string} params.platformType - Platform type (uplay, psn, xbl)
9
- * @returns {Promise<Object>} - Player stats for current season
10
- */
11
- async function getSeasonalStats({ nameOnPlatform, platformType } = {}) {
12
- try {
13
- // Validate required parameters
14
- if (!nameOnPlatform || !platformType) {
15
- throw new Error('Missing required parameters: nameOnPlatform, platformType');
16
- }
17
-
18
- // Build the URL with parameters
19
- const params = {
20
- type: 'seasonalStats',
21
- nameOnPlatform,
22
- platformType
23
- };
24
-
25
- const url = buildUrlAndParams('/stats', params);
26
-
27
- const response = await axiosInstance.get(url);
28
-
29
- return response.data;
30
- } catch (error) {
31
- console.error('Error during the getSeasonalStats request:', error.message);
32
- if (error.response && error.response.status === 401) {
33
- throw new Error('Authentication error');
34
- }
35
- throw error;
36
- }
37
- }
38
-
39
- module.exports = getSeasonalStats;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ /**
5
+ * Get Rainbow Six Siege player stats for current season
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 stats for current season
11
+ */
12
+ async function getSeasonalStats(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: 'seasonalStats',
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 getSeasonalStats 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 = getSeasonalStats;
@@ -1,21 +1,28 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- async function getSeasons({ name, map, operators, weapons, description, code, startDate } = {}) {
5
- try {
6
-
7
- const url = buildUrlAndParams('/seasons', { name, map, operators, weapons, description, code, startDate });
8
-
9
- const response = await axiosInstance.get(url);
10
-
11
- return response.data;
12
- } catch (error) {
13
- console.error('Error during the getSeasons request:', error.message);
14
- if (error.response && error.response.status === 401) {
15
- throw new Error('request error');
16
- }
17
- throw error;
18
- }
19
- }
20
-
21
- module.exports = getSeasons;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ async function getSeasons(apiKey, { name, map, operators, weapons, description, code, startDate } = {}) {
5
+ try {
6
+ if (!apiKey) {
7
+ throw new Error('Missing required parameter: apiKey');
8
+ }
9
+
10
+ const url = buildUrlAndParams('/seasons', { name, map, operators, weapons, description, code, startDate });
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 getSeasons 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 = getSeasons;
@@ -1,19 +1,26 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
-
3
- async function getServiceStatus() {
4
- try {
5
-
6
- let url = '/serviceStatus';
7
- const response = await axiosInstance.get(url);
8
-
9
- return response.data;
10
- } catch (error) {
11
- console.error('Error during the service status request:', error.message);
12
- if (error.response && error.response.status === 401) {
13
- throw new Error('request error');
14
- }
15
- throw error;
16
- }
17
- }
18
-
19
- module.exports = getServiceStatus;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+
3
+ async function getServiceStatus(apiKey) {
4
+ try {
5
+ if (!apiKey) {
6
+ throw new Error('Missing required parameter: apiKey');
7
+ }
8
+
9
+ let url = '/serviceStatus';
10
+ const response = await axiosInstance.get(url, {
11
+ headers: {
12
+ 'api-key': apiKey
13
+ }
14
+ });
15
+
16
+ return response.data;
17
+ } catch (error) {
18
+ console.error('Error during the service status request:', error.message);
19
+ if (error.response && error.response.status === 401) {
20
+ throw new Error('request error');
21
+ }
22
+ throw error;
23
+ }
24
+ }
25
+
26
+ module.exports = getServiceStatus;