poe-api-manager 0.1.0 → 0.2.6

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.
Files changed (72) hide show
  1. package/Changelog.md +11 -2
  2. package/README.md +78 -17
  3. package/index.js +5 -1
  4. package/lib/NinjaAPI.js +27 -5
  5. package/lib/WatchAPI.js +56 -0
  6. package/lib/config/poeNinja/url.js +9 -0
  7. package/lib/config/poeWatch/url.js +12 -0
  8. package/lib/modules/mainfunctions/filter/propertyFilter.js +36 -0
  9. package/lib/modules/poe.ninja/currency/CurrencyWievModule.js +44 -5
  10. package/lib/modules/poe.ninja/currency/currencyFetch/fetchCurrency.js +11 -3
  11. package/lib/modules/poe.ninja/currency/currencyFetch/merge/mergeData.js +7 -0
  12. package/lib/modules/poe.ninja/currency/currencySubmodules/functions/getData.js +24 -1
  13. package/lib/modules/poe.ninja/currency/currencySubmodules/subModules/CurrencyModule.js +50 -4
  14. package/lib/modules/poe.ninja/currency/currencySubmodules/subModules/FragmentModule.js +50 -4
  15. package/lib/modules/poe.ninja/item/ItemWievModule.js +140 -5
  16. package/lib/modules/poe.ninja/item/itemFetch/fetchItem.js +23 -2
  17. package/lib/modules/poe.ninja/item/itemSubmodules/functions/getData.js +20 -1
  18. package/lib/modules/poe.ninja/item/itemSubmodules/itemSubModules.js +0 -2
  19. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/BaseTypeModule.js +45 -4
  20. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/BeastModule.js +45 -4
  21. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/BlightRavagedMapModule.js +50 -4
  22. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/BlightedMapModule.js +47 -4
  23. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/ClusterJewelModule.js +50 -4
  24. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/DeliriumOrbsModule.js +50 -4
  25. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/DivinationCardModule.js +50 -4
  26. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/EssenceModule.js +50 -4
  27. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/FossilModule.js +50 -4
  28. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/HelmetEnchantModule.js +50 -4
  29. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/IncubatorModule.js +50 -4
  30. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/InvitationModule.js +50 -4
  31. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/MapModule.js +50 -4
  32. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/MemoryModule.js +50 -4
  33. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/OilModule.js +50 -4
  34. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/OmenModule.js +50 -4
  35. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/ResonatorModule.js +50 -4
  36. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/ScarabModule.js +50 -4
  37. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/SkillGemModule.js +50 -4
  38. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/UniqueAccessoryModule.js +50 -4
  39. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/UniqueArmourModule.js +50 -4
  40. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/UniqueFlaskModule.js +50 -4
  41. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/UniqueJewelModule.js +50 -4
  42. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/UniqueMapModule.js +50 -4
  43. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/UniqueRelicModule.js +50 -4
  44. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/UniqueWeaponModule.js +50 -4
  45. package/lib/modules/poe.ninja/item/itemSubmodules/subModules/VialsModule.js +50 -4
  46. package/lib/modules/poe.watch/WatchWievModule.js +130 -0
  47. package/lib/modules/poe.watch/allModules/Modules.js +23 -0
  48. package/lib/modules/poe.watch/allModules/fetch/fetch.js +28 -0
  49. package/lib/modules/poe.watch/allModules/functions/getData.js +39 -0
  50. package/lib/modules/poe.watch/allModules/submodules/AccessoryModule.js +59 -0
  51. package/lib/modules/poe.watch/allModules/submodules/ArmourModule.js +59 -0
  52. package/lib/modules/poe.watch/allModules/submodules/BaseModule.js +59 -0
  53. package/lib/modules/poe.watch/allModules/submodules/BeastModule.js +59 -0
  54. package/lib/modules/poe.watch/allModules/submodules/CurrencyModule.js +60 -0
  55. package/lib/modules/poe.watch/allModules/submodules/DeliriumOrbModule.js +59 -0
  56. package/lib/modules/poe.watch/allModules/submodules/DivsModule.js +59 -0
  57. package/lib/modules/poe.watch/allModules/submodules/EssenceModule.js +59 -0
  58. package/lib/modules/poe.watch/allModules/submodules/FlaskModule.js +59 -0
  59. package/lib/modules/poe.watch/allModules/submodules/FossilModule.js +59 -0
  60. package/lib/modules/poe.watch/allModules/submodules/FragmentModule.js +59 -0
  61. package/lib/modules/poe.watch/allModules/submodules/GemModule.js +59 -0
  62. package/lib/modules/poe.watch/allModules/submodules/InscribedModule.js +61 -0
  63. package/lib/modules/poe.watch/allModules/submodules/InvitationModule.js +59 -0
  64. package/lib/modules/poe.watch/allModules/submodules/JewelModule.js +59 -0
  65. package/lib/modules/poe.watch/allModules/submodules/MapModule.js +59 -0
  66. package/lib/modules/poe.watch/allModules/submodules/OilModule.js +59 -0
  67. package/lib/modules/poe.watch/allModules/submodules/ScarabModule.js +59 -0
  68. package/lib/modules/poe.watch/allModules/submodules/SextantModule.js +59 -0
  69. package/lib/modules/poe.watch/allModules/submodules/UniqueMapsModule.js +59 -0
  70. package/lib/modules/poe.watch/allModules/submodules/WeaponModule.js +59 -0
  71. package/package.json +13 -5
  72. package/lib/modules/filter/propertyFilter.js +0 -18
package/Changelog.md CHANGED
@@ -1,6 +1,15 @@
1
1
  # Changelog
2
+ ## 0.2.6
3
+ JSDocs have been added for easy understanding.
2
4
 
3
- ## 0.1.0 17.02.1014
5
+
6
+ ## 0.2.2
7
+ poe.watch API add
8
+
9
+ use getData() function
10
+
11
+
12
+ ## 0.1.0
4
13
  poe.ninja API new
5
14
 
6
15
  - Omens
@@ -11,4 +20,4 @@ poe.ninja API new
11
20
  - Invitations
12
21
  - Memories
13
22
 
14
- ## 0.0.1 Publish 15.02.2024
23
+ ## 0.0.1 Publish
package/README.md CHANGED
@@ -1,16 +1,21 @@
1
- # poe-economy-manager
1
+ # poe-api-manager
2
2
 
3
3
  [![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/)
4
4
  ![Version](https://img.shields.io/github/package-json/v/ayberkgezer/poe-api-manager)
5
5
  ![GitHub top language](https://img.shields.io/github/languages/top/ayberkgezer/poe-api-manager?logo=javascript)
6
6
  [![ISSUES](https://img.shields.io/github/issues/ayberkgezer/poe-api-manager)](https://github.com/ayberkgezer/poe-api-manager/issues)
7
+ ![NPM Downloads](https://img.shields.io/npm/dt/poe-api-manager?logo=npm)
8
+
7
9
 
8
10
  - [Introduction](#introduction)
9
11
  - [Overwiev](#overwiev)
10
12
  - [Installation](#installation)
11
13
  - [Getting Started](#getting-started)
12
- - [currencyWiev](#currencywiev)
13
- - [itemWiev](#itemwiev)
14
+ - [poe.ninja](#ninjaapi)
15
+ - [currencyWiev](#currencywiev)
16
+ - [itemWiev](#itemwiev)
17
+ - [poe.watch](#watchapi)
18
+ - [wiev](#wiev)
14
19
  - [Changelog](https://github.com/ayberkgezer/poe-api-manager/blob/main/Changelog.md)
15
20
  - [Examples](#examples)
16
21
 
@@ -19,13 +24,13 @@
19
24
  ## Introduction
20
25
  The purpose of this library is to make the economic data in the Path of Exile game easily usable.
21
26
 
22
- >Important!: For economy, it is taken from the poe.ninja website. (for now)
27
+ >Important!: For economy, it is taken from the poe.ninja and poe.watch
23
28
 
24
- > Note: This product is in no way affiliated with or endorsed by Grinding Gear Games and poe.ninja.
29
+ > Note: This product is in no way affiliated with or endorsed by Grinding Gear Games, poe.ninja and poe.watch.
25
30
 
26
31
  ## Overwiev
27
32
 
28
- There are two types of usage for Poe: [currencywiev](#currencywiev) and [itemwiev](#itemwiev).
33
+ Permission to access two different services. poe.ninja and poe.watch
29
34
 
30
35
  ## Installation
31
36
  **Install with npm:**
@@ -34,13 +39,15 @@ $ npm install poe-api-manager
34
39
  ```
35
40
 
36
41
  ## Getting Started
42
+
43
+ ### ninjaAPI
37
44
  ```javascript
38
- const NinjaAPI = require("poe-api-manager");
45
+ const { NinjaAPI } = require("poe-api-manager");
39
46
 
40
47
  const ninjaAPI = new NinjaAPI("League-Name");
41
48
  ```
42
49
 
43
- ### currencyWiev
50
+ #### currencyWiev
44
51
  What we can get here is as follows.
45
52
  - Currency
46
53
  - Fragment
@@ -60,7 +67,7 @@ ninjaAPI.currencyWiev.currency.getData(["id", "name", "icon"]).then((data) => {
60
67
  console.log(data);
61
68
  });
62
69
  ```
63
- ### itemWiev
70
+ #### itemWiev
64
71
  What we can get here is as follows.
65
72
  - BaseType
66
73
  - Beast
@@ -105,48 +112,102 @@ ninjaAPI.itemWiev.baseType.getData(["id", "name", "icon"]).then((data) => {
105
112
  console.log(data);
106
113
  });
107
114
  ```
115
+ ### watchAPI
116
+ ```javascript
117
+ const { WatchAPI } = require("poe-api-manager");
118
+
119
+ const watchAPI = new WatchAPI("League-Name");
120
+ ```
121
+ #### wiev
122
+ What we can get here is as follows.
123
+ - Currency
124
+ - Essences
125
+ - Fossil
126
+ - Fragment
127
+ - Gem
128
+ - Invitation
129
+ - Jewel
130
+ - Map
131
+ - Oil
132
+ - Scarab
133
+ - Sextant
134
+ - Accessory
135
+ - Armour
136
+ - Weapon
137
+ - Flask
138
+ - Base
139
+ - Beast
140
+
141
+ ```javascript
142
+ //Example Currency
143
+ watchAPI.wiev.baseType.getData().then((data) => {
144
+ console.log(data);
145
+ });
146
+ ```
147
+ > Enter [poe.watch Document](https://docs.poe.watch/#get-all-armours) to access the values for the filter.
148
+ ```javascript
149
+ //Filtered data is returned
150
+ watchAPI.wiev.currency.getData(["id", "name", "icon"]).then((data) => {
151
+ console.log(data);
152
+ });
153
+ ```
108
154
 
109
155
  ## Examples
110
156
  ```javascript
111
- const NinjaAPI = require("poe-api-manager");
157
+ const { NinjaAPI , WatchAPI } = require("poe-api-manager");
112
158
 
113
159
  // Create NinjaAPI
114
160
  const ninjaAPI = new NinjaAPI("Affliction");
161
+ //Create WatchAPI
162
+ const watchAPI = new WatchAPI("Affliction")
115
163
 
116
164
  //We entered the filter data
117
165
  const requestedProperties = ["id", "name", "icon"];
118
166
 
119
- //filtered BaseType data
167
+ //filtered BaseType data ninjaAPI
120
168
  ninjaAPI.itemwiev.baseType.getData(requestedProperties).then((data) => {
121
169
  console.log(data);
122
170
  });
123
171
 
124
- //filtered Currency data
172
+ //filtered Currency data ninjaAPI
125
173
  ninjaAPI.currencyWiev.currency.getData(requestedProperties).then((data) => {
126
174
  console.log(data);
127
175
  });
176
+
177
+ // filtered Scarab data watchAPI
178
+ watchAPI.wiev.scarab.getData(requestedProperties).then((data) => {
179
+ console.log(data);
180
+ });
128
181
  ```
129
182
 
130
183
  ```javascript
131
- const NinjaAPI = require("poe-api-manager");
184
+ const { NinjaAPI , WatchAPI } = require("poe-api-manager");
132
185
 
133
186
  // Create NinjaAPI
134
187
  const ninjaAPI = new NinjaAPI("Affliction");
188
+ //Create WatchAPI
189
+ const watchAPI = new WatchAPI("Affliction")
135
190
 
136
191
  const requestedProperties = ["id", "name", "icon"];
137
192
 
138
193
  //Using await in an async function
139
194
  const fetchData = async () => {
140
195
  try {
141
- //Oil Data
196
+ //Oil Data poe.ninja
142
197
  const oilData = await ninjaAPI.item.oil.getData(requestedProperties);
143
198
 
144
- console.log("Oil Data:", oilData);
145
199
 
146
- //Currency Data
200
+ console.log("poe.ninja Oil Data:", oilData);
201
+
202
+ //Currency Data poe.ninja
147
203
  const currencyData = await ninjaAPI.currencyWiev.currency.getData(requestedProperties);
148
204
 
149
- console.log("Currency Data:", currencyData);
205
+ console.log("poe.ninja Currency Data:", currencyData);
206
+
207
+ //Scarab Data poe.watch
208
+ const scarabData = await watchAPI.wiev.scarab.getData(requestedProperties)
209
+
210
+ console.log("poe.watch Scarab Data", scarabData);
150
211
  } catch (error) {
151
212
  console.error("Error fetching data:", error);
152
213
  }
package/index.js CHANGED
@@ -1,3 +1,7 @@
1
1
  const NinjaAPI = require("./lib/NinjaAPI");
2
+ const WatchAPI = require("./lib/WatchAPI");
2
3
 
3
- module.exports = NinjaAPI;
4
+ module.exports = {
5
+ NinjaAPI: NinjaAPI,
6
+ WatchAPI: WatchAPI,
7
+ };
package/lib/NinjaAPI.js CHANGED
@@ -1,11 +1,33 @@
1
- const ItemWievModule = require("./modules/poe.ninja/item/ItemWievModule");
2
- const CurrencyWievModule = require("./modules/poe.ninja/currency/CurrencyWievModule");
1
+ const ItemViewModule = require("./modules/poe.ninja/item/ItemWievModule");
2
+ const CurrencyViewModule = require("./modules/poe.ninja/currency/CurrencyWievModule");
3
3
 
4
+ /**
5
+ * Represents an API for interacting with the poe.ninja API.
6
+ *
7
+ * @class
8
+ */
4
9
  class NinjaAPI {
10
+ /**
11
+ * Creates an instance of NinjaAPI.
12
+ *
13
+ * @param {string} league - The PoE league for which data is requested.
14
+ */
5
15
  constructor(league) {
6
- this.league = league;
7
- this.currencyWiev = new CurrencyWievModule(league);
8
- this.itemWiev = new ItemWievModule(league);
16
+ /**
17
+ * The CurrencyViewModule instance for fetching currency-related data.
18
+ *
19
+ * @type {CurrencyViewModule}
20
+ */
21
+ this.currencyView = new CurrencyViewModule(league);
22
+
23
+ /**
24
+ * The ItemViewModule instance for fetching item-related data.
25
+ *
26
+ * @type {ItemViewModule}
27
+ */
28
+ this.itemView = new ItemViewModule(league);
9
29
  }
10
30
  }
31
+
32
+ // Export the NinjaAPI class
11
33
  module.exports = NinjaAPI;
@@ -0,0 +1,56 @@
1
+ const WatchWievModule = require("./modules/poe.watch/WatchWievModule");
2
+
3
+ /**
4
+ * Represents an API for interacting with a poe.watch service.
5
+ *
6
+ * @class
7
+ */
8
+ class WatchAPI {
9
+ /**
10
+ * The league for which the API is initialized.
11
+ *
12
+ * @private
13
+ * @type {string}
14
+ */
15
+ #league;
16
+
17
+ /**
18
+ * The URL parameter for the league in the Path of Exile.
19
+ *
20
+ * @private
21
+ * @type {string}
22
+ */
23
+ #leagueUrl;
24
+
25
+ /**
26
+ * Creates an instance of WatchAPI.
27
+ *
28
+ * @param {string} league - The league for which the API should be initialized.
29
+ */
30
+ constructor(league) {
31
+ /**
32
+ * The league for which the API is initialized.
33
+ *
34
+ * @private
35
+ * @type {string}
36
+ */
37
+ this.#league = league;
38
+
39
+ /**
40
+ * The URL parameter for the league in the Path of Exile watch service.
41
+ *
42
+ * @private
43
+ * @type {string}
44
+ */
45
+ this.#leagueUrl = `&league=${this.#league}`;
46
+
47
+ /**
48
+ * The WatchWievModule instance associated with this API.
49
+ *
50
+ * @type {WatchWievModule}
51
+ */
52
+ this.wiev = new WatchWievModule(this.#leagueUrl);
53
+ }
54
+ }
55
+
56
+ module.exports = WatchAPI;
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Configuration module for poe.ninja API URL.
3
+ * @module config/poeNinja/url
4
+ */
5
+
6
+ /**
7
+ * Base URL for the poe.ninja API.
8
+ * @type {string}
9
+ */
1
10
  module.exports = {
2
11
  baseurl: "https://poe.ninja/api/data/",
3
12
  };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Configuration module for poe.watch API URL.
3
+ * @module config/poeWatch/url
4
+ */
5
+
6
+ /**
7
+ * Base URL for the poe.watch API.
8
+ * @type {string}
9
+ */
10
+ module.exports = {
11
+ baseurl: "https://api.poe.watch/get?category=",
12
+ };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Filters properties of objects in an array based on the specified properties.
3
+ *
4
+ * @param {Array<Object>} data - The array of objects to filter.
5
+ * @param {Array<string>} requestedProperties - The array of property names to include in the result.
6
+ * @returns {Array<Object>} - An array of objects with only the specified properties.
7
+ */
8
+ module.exports = function filterProperties(data, requestedProperties) {
9
+ /**
10
+ * @type {Array<Object>} result - The filtered array of objects.
11
+ */
12
+ const result = [];
13
+
14
+ data.forEach((item) => {
15
+ /**
16
+ * @type {Object} itemResult - The filtered object with requested properties.
17
+ */
18
+ const itemResult = {};
19
+
20
+ requestedProperties.forEach((prop) => {
21
+ if (item.hasOwnProperty(prop)) {
22
+ itemResult[prop] = item[prop];
23
+ } else {
24
+ /**
25
+ * Warn if the requested property is not found in the object.
26
+ * @type {string}
27
+ */
28
+ console.warn(`Property not found: ${prop}`);
29
+ }
30
+ });
31
+
32
+ result.push(itemResult);
33
+ });
34
+
35
+ return result;
36
+ };
@@ -1,17 +1,56 @@
1
1
  const currencySubmodules = require("./currencySubmodules/CurrencySubModules");
2
2
  const baseurl = require("../../../config/poeNinja/url");
3
3
 
4
- //currencywiev module
4
+ /**
5
+ * Represents a module for fetching currency overview data.
6
+ *
7
+ * @class
8
+ */
5
9
  class CurrencyWievModule {
10
+ #league;
11
+ #baseurl;
12
+ /**
13
+ * Creates a new CurrencyWievModule instance.
14
+ *
15
+ * @constructor
16
+ * @param {string} league - The name of the Path of Exile league.
17
+ */
6
18
  constructor(league) {
7
- this.league = league;
8
- this.baseurl = baseurl.baseurl;
9
- const url = `${this.baseurl}currencyoverview?league=${this.league}&type=`;
19
+ /**
20
+ * The league for which the currency overview data is fetched.
21
+ *
22
+ * @private
23
+ * @type {string}
24
+ */
25
+ this.#league = league;
10
26
 
27
+ /**
28
+ * The base URL for fetching currency overview data.
29
+ *
30
+ * @private
31
+ * @type {string}
32
+ */
33
+ this.#baseurl = baseurl.baseurl;
34
+
35
+ /**
36
+ * The URL for currency overview data specific to the league.
37
+ *
38
+ * @private
39
+ * @type {string}
40
+ */
41
+ const url = `${this.#baseurl}currencyoverview?league=${this.#league}&type=`;
42
+
43
+ /**
44
+ * Represents a module for fetching currency data.
45
+ */
11
46
  this.currency = new currencySubmodules.CurrencyModule(url);
47
+
48
+ /**
49
+ * Represents a module for fetching fragment data.
50
+ */
12
51
  this.fragment = new currencySubmodules.FragmentModule(url);
13
52
  }
14
53
  }
15
54
 
16
- //export CurrencyWievModule;
55
+ // Export the CurrencyWievModule class
17
56
  module.exports = CurrencyWievModule;
@@ -1,7 +1,14 @@
1
1
  const axios = require("axios");
2
2
  const mergeData = require("./merge/mergeData");
3
3
 
4
- // items for a specific fetch function
4
+ /**
5
+ * Fetches data from a specified API endpoint, merges relevant data, and returns the result.
6
+ *
7
+ * @param {string} baseurl - The base URL of the API.
8
+ * @param {string} type - The type of data to fetch. (e.g. "Currency", "Fragment")
9
+ * @returns {Promise<Array<Object>>} - A promise that resolves to an array of merged objects containing both line and currency details.
10
+ * @throws {Error} - Throws an error if there's an issue with the API response or data fetching process.
11
+ */
5
12
  async function fetchData(baseurl, type) {
6
13
  try {
7
14
  const url = `${baseurl}${type}`;
@@ -10,11 +17,13 @@ async function fetchData(baseurl, type) {
10
17
  if (response.data && response.data.lines && response.data.currencyDetails) {
11
18
  const lines = response.data.lines;
12
19
  const currencyDetails = response.data.currencyDetails;
20
+
21
+ // Merge data using the mergeData function
13
22
  const mergedData = mergeData(lines, currencyDetails);
14
23
  return mergedData;
15
24
  } else {
16
25
  throw new Error(
17
- "Invalid response format from POE Ninja API Currencywiev"
26
+ "Invalid response format from POE Ninja API Currencyview"
18
27
  );
19
28
  }
20
29
  } catch (error) {
@@ -22,5 +31,4 @@ async function fetchData(baseurl, type) {
22
31
  }
23
32
  }
24
33
 
25
- // export fetchData;
26
34
  module.exports = fetchData;
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Merges the provided lines with the corresponding currency details.
3
+ *
4
+ * @param {Array} lines - The lines to be merged.
5
+ * @param {Array} currencyDetails - The currency details to be merged with the lines.
6
+ * @returns {Array} - The merged data.
7
+ */
1
8
  function mergeData(lines, currencyDetails) {
2
9
  const mergedData = [];
3
10
 
@@ -1,6 +1,19 @@
1
1
  const fetchData = require("../../currencyFetch/fetchCurrency");
2
- const filterProperties = require("../../../../filter/propertyFilter");
2
+ const filterProperties = require("../../../../mainfunctions/filter/propertyFilter");
3
3
 
4
+ /**
5
+ * Retrieves data from a specified API endpoint, optionally filters the data based on requested properties, and returns the result.
6
+ *
7
+ * @param {string} url - The URL of the API endpoint.
8
+ * @param {string} type - The type of data to fetch.
9
+ * @param {Array<string>} [requestedProperties] - An optional array of property names to filter the fetched data.
10
+ * @returns {Promise<Array<Object>>} - A promise that resolves to an array of objects containing the fetched and possibly filtered data.
11
+ * @throws {Error} - Throws an error if there's an issue with the data fetching process or filtering process.
12
+ *
13
+ * @async
14
+ * @function
15
+ *
16
+ */
4
17
  async function getData(url, type, requestedProperties) {
5
18
  try {
6
19
  // Fetch data using the fetchData function
@@ -8,6 +21,11 @@ async function getData(url, type, requestedProperties) {
8
21
 
9
22
  // If requestedProperties are specified, filter the data based on those properties
10
23
  if (requestedProperties) {
24
+ /**
25
+ * Filter the fetched data based on the specified properties.
26
+ *
27
+ * @type {Array<Object>}
28
+ */
11
29
  const result = filterProperties(fetchedData, requestedProperties);
12
30
  return result;
13
31
  } else {
@@ -15,6 +33,11 @@ async function getData(url, type, requestedProperties) {
15
33
  return fetchedData;
16
34
  }
17
35
  } catch (error) {
36
+ /**
37
+ * An error indicating an issue with the data fetching or filtering process.
38
+ *
39
+ * @throws {Error} - Throws an error with a descriptive message.
40
+ */
18
41
  throw new Error(`Error fetching data: ${error.message}`);
19
42
  }
20
43
  }
@@ -1,15 +1,61 @@
1
1
  const getData = require("../functions/getData");
2
2
 
3
+ /**
4
+ * Represents a module for fetching data related to Currency.
5
+ *
6
+ * @class
7
+ */
3
8
  class CurrencyModule {
9
+ /**
10
+ * The URL for fetching data.
11
+ *
12
+ * @private
13
+ * @type {string}
14
+ */
15
+ #url;
16
+
17
+ /**
18
+ * The type of data (Currency in this case).
19
+ *
20
+ * @private
21
+ * @type {string}
22
+ */
23
+ #type;
24
+
25
+ /**
26
+ * Creates an instance of CurrencyModule.
27
+ *
28
+ * @param {string} url - The URL to fetch data from.
29
+ */
4
30
  constructor(url) {
5
- this.url = url;
6
- this.type = "Currency";
31
+ this.#url = url;
32
+ this.#type = "Currency";
7
33
  }
8
34
 
35
+ /**
36
+ * Asynchronously retrieves data based on the specified properties.
37
+ *
38
+ * @async
39
+ * @param {Array<string>} requestedProperties - An array of properties to retrieve.
40
+ * @returns {Promise<Object>} A promise that resolves to the retrieved data.
41
+ */
9
42
  async getData(requestedProperties) {
10
- return getData(this.url, this.type, requestedProperties);
43
+ try {
44
+ /**
45
+ * Calls the getData function to fetch Currency data.
46
+ *
47
+ * @type {Promise<Array<Object>>}
48
+ */
49
+ return getData(this.#url, this.#type, requestedProperties);
50
+ } catch (error) {
51
+ /**
52
+ * Throws an error if there's an issue fetching or processing the Currency data.
53
+ *
54
+ * @throws {Error}
55
+ */
56
+ throw new Error(`Error fetching Currency data: ${error.message}`);
57
+ }
11
58
  }
12
59
  }
13
60
 
14
- //export CurrencyModule;
15
61
  module.exports = CurrencyModule;
@@ -1,15 +1,61 @@
1
1
  const getData = require("../functions/getData");
2
2
 
3
+ /**
4
+ * Represents a module for fetching data related to Fragments.
5
+ *
6
+ * @class
7
+ */
3
8
  class FragmentModule {
9
+ /**
10
+ * The URL for fetching data.
11
+ *
12
+ * @private
13
+ * @type {string}
14
+ */
15
+ #url;
16
+
17
+ /**
18
+ * The type of data (Fragment in this case).
19
+ *
20
+ * @private
21
+ * @type {string}
22
+ */
23
+ #type;
24
+
25
+ /**
26
+ * Creates an instance of FragmentModule.
27
+ *
28
+ * @param {string} url - The URL to fetch data from.
29
+ */
4
30
  constructor(url) {
5
- this.url = url;
6
- this.type = "Fragment";
31
+ this.#url = url;
32
+ this.#type = "Fragment";
7
33
  }
8
34
 
35
+ /**
36
+ * Asynchronously retrieves data based on the specified properties.
37
+ *
38
+ * @async
39
+ * @param {Array<string>} requestedProperties - An array of properties to retrieve.
40
+ * @returns {Promise<Object>} A promise that resolves to the retrieved data.
41
+ */
9
42
  async getData(requestedProperties) {
10
- return getData(this.url, this.type, requestedProperties);
43
+ try {
44
+ /**
45
+ * Calls the getData function to fetch Fragment data.
46
+ *
47
+ * @type {Promise<Array<Object>>}
48
+ */
49
+ return getData(this.#url, this.#type, requestedProperties);
50
+ } catch (error) {
51
+ /**
52
+ * Throws an error if there's an issue fetching or processing the Fragment data.
53
+ *
54
+ * @throws {Error}
55
+ */
56
+ throw new Error(`Error fetching Fragment data: ${error.message}`);
57
+ }
11
58
  }
12
59
  }
13
60
 
14
- //export FragmentModule;
15
61
  module.exports = FragmentModule;