poe-api-manager 0.2.6 → 1.0.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/Changelog.md CHANGED
@@ -1,23 +1,27 @@
1
1
  # Changelog
2
- ## 0.2.6
3
- JSDocs have been added for easy understanding.
2
+ ## 1.0.0
3
+ - 🚀[New] utils class
4
+ - 🚀[New] utils `getLeagues`function. Get league name.
5
+ - 📝 [Update] The documentation has been updated.
4
6
 
7
+ ## 0.2.8
8
+ - 🚀[Added] poe.watch API with `getCategory()` function.
9
+ - 🛠️ [Fixed] Typo in WatchAPI class
10
+ - 📝 [Update] The documentation has been updated.
11
+ ## 0.2.6
12
+ - 🎨[Added] JSDocs for easy understanding.
5
13
 
6
14
  ## 0.2.2
7
- poe.watch API add
8
-
9
- use getData() function
10
-
11
-
12
- ## 0.1.0
13
- poe.ninja API new
15
+ - 🚀[Added] poe.watch API with `getData()` function.
14
16
 
15
- - Omens
16
- - Unique Relics
17
- - Cluster Jewels
18
- - Blighted Maps
19
- - Blight Ravaged Maps
20
- - Invitations
21
- - Memories
17
+ ## 0.1.0
18
+ - 🚀[Added] poe.ninja API with the following features:
19
+ - Omens
20
+ - Unique Relics
21
+ - Cluster Jewels
22
+ - Blighted Maps
23
+ - Blight Ravaged Maps
24
+ - Invitations
25
+ - Memories
22
26
 
23
- ## 0.0.1 Publish
27
+ ## 0.0.1 Publish
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
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
- ![Version](https://img.shields.io/github/package-json/v/ayberkgezer/poe-api-manager)
4
+ ![GitHub package.json 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
7
  ![NPM Downloads](https://img.shields.io/npm/dt/poe-api-manager?logo=npm)
@@ -12,10 +12,10 @@
12
12
  - [Installation](#installation)
13
13
  - [Getting Started](#getting-started)
14
14
  - [poe.ninja](#ninjaapi)
15
- - [currencyWiev](#currencywiev)
16
- - [itemWiev](#itemwiev)
15
+ - [currencyView](#currencywiev)
16
+ - [itemView](#itemwiev)
17
17
  - [poe.watch](#watchapi)
18
- - [wiev](#wiev)
18
+ - [view](#view)
19
19
  - [Changelog](https://github.com/ayberkgezer/poe-api-manager/blob/main/Changelog.md)
20
20
  - [Examples](#examples)
21
21
 
@@ -47,7 +47,7 @@ const { NinjaAPI } = require("poe-api-manager");
47
47
  const ninjaAPI = new NinjaAPI("League-Name");
48
48
  ```
49
49
 
50
- #### currencyWiev
50
+ #### currencyView
51
51
  What we can get here is as follows.
52
52
  - Currency
53
53
  - Fragment
@@ -55,7 +55,7 @@ What we can get here is as follows.
55
55
  getData() => function returns data purely.
56
56
  ```javascript
57
57
  //Example Currency
58
- ninjaAPI.currencyWiev.currency.getData().then((data) => {
58
+ ninjaAPI.currencyView.currency.getData().then((data) => {
59
59
  console.log(data);
60
60
  });
61
61
  ```
@@ -63,11 +63,11 @@ getdata(requestedProperties) => The function filters the data as desired.
63
63
  >Note: Enter [poe.ninja Document](https://github.com/ayberkgezer/poe.ninja-API-Document?tab=readme-ov-file#poeninja-api) to access the values for the filter.
64
64
  ```javascript
65
65
  //Filtered data is returned
66
- ninjaAPI.currencyWiev.currency.getData(["id", "name", "icon"]).then((data) => {
66
+ ninjaAPI.currencyView.currency.getData(["id", "name", "icon"]).then((data) => {
67
67
  console.log(data);
68
68
  });
69
69
  ```
70
- #### itemWiev
70
+ #### itemView
71
71
  What we can get here is as follows.
72
72
  - BaseType
73
73
  - Beast
@@ -100,7 +100,7 @@ What we can get here is as follows.
100
100
  getData() => function returns data purely.
101
101
  ```javascript
102
102
  //Example BaseType
103
- ninjaAPI.itemWiev.baseType.getData().then((data) => {
103
+ ninjaAPI.itemView.baseType.getData().then((data) => {
104
104
  console.log(data);
105
105
  });
106
106
  ```
@@ -108,7 +108,7 @@ getdata(requestedProperties) => The function filters the data as desired.
108
108
  >Note: Enter [poe.ninja Document](https://github.com/ayberkgezer/poe.ninja-API-Document?tab=readme-ov-file#poeninja-api) to access the values for the filter.
109
109
  ```javascript
110
110
  //Filtered data is returned
111
- ninjaAPI.itemWiev.baseType.getData(["id", "name", "icon"]).then((data) => {
111
+ ninjaAPI.itemView.baseType.getData(["id", "name", "icon"]).then((data) => {
112
112
  console.log(data);
113
113
  });
114
114
  ```
@@ -118,7 +118,7 @@ const { WatchAPI } = require("poe-api-manager");
118
118
 
119
119
  const watchAPI = new WatchAPI("League-Name");
120
120
  ```
121
- #### wiev
121
+ #### view
122
122
  What we can get here is as follows.
123
123
  - Currency
124
124
  - Essences
@@ -138,19 +138,48 @@ What we can get here is as follows.
138
138
  - Base
139
139
  - Beast
140
140
 
141
+ getData() => function returns data purely.
141
142
  ```javascript
142
143
  //Example Currency
143
- watchAPI.wiev.baseType.getData().then((data) => {
144
+ watchAPI.view.baseType.getData().then((data) => {
144
145
  console.log(data);
145
146
  });
146
147
  ```
147
148
  > Enter [poe.watch Document](https://docs.poe.watch/#get-all-armours) to access the values for the filter.
149
+
150
+ getdata(requestedProperties) => The function filters the data as desired.
148
151
  ```javascript
149
152
  //Filtered data is returned
150
- watchAPI.wiev.currency.getData(["id", "name", "icon"]).then((data) => {
153
+ watchAPI.view.currency.getData(["id", "name", "icon"]).then((data) => {
151
154
  console.log(data);
152
155
  });
153
156
  ```
157
+ getCategory("categoryName") => The function quickly filters through specific categories.
158
+
159
+ > Note: Used in accessory, armour, base, gem and weapon.
160
+
161
+ ```javascript
162
+ //Returns the chest category in Armor.
163
+ watchAPI.view.armour.getCategory("chest").then((data) => {
164
+ console.log(data);
165
+ });
166
+ ```
167
+ ## Utils
168
+ Utils class is a class that contains some auxiliary tools.
169
+ ```javascript
170
+ const { Utils } = require("poe-api-manager");
171
+ const utils = new Utils();
172
+ ```
173
+ getLeagues() => Returns available league names.
174
+
175
+ ```javascript
176
+ const utils = new Utils();
177
+
178
+ utils.getLeagues().then((data) => {
179
+ console.log(data);
180
+ });
181
+ ```
182
+
154
183
 
155
184
  ## Examples
156
185
  ```javascript
@@ -165,17 +194,17 @@ const watchAPI = new WatchAPI("Affliction")
165
194
  const requestedProperties = ["id", "name", "icon"];
166
195
 
167
196
  //filtered BaseType data ninjaAPI
168
- ninjaAPI.itemwiev.baseType.getData(requestedProperties).then((data) => {
197
+ ninjaAPI.itemView.baseType.getData(requestedProperties).then((data) => {
169
198
  console.log(data);
170
199
  });
171
200
 
172
201
  //filtered Currency data ninjaAPI
173
- ninjaAPI.currencyWiev.currency.getData(requestedProperties).then((data) => {
202
+ ninjaAPI.currencyView.currency.getData(requestedProperties).then((data) => {
174
203
  console.log(data);
175
204
  });
176
205
 
177
206
  // filtered Scarab data watchAPI
178
- watchAPI.wiev.scarab.getData(requestedProperties).then((data) => {
207
+ watchAPI.view.scarab.getData(requestedProperties).then((data) => {
179
208
  console.log(data);
180
209
  });
181
210
  ```
@@ -194,22 +223,22 @@ const requestedProperties = ["id", "name", "icon"];
194
223
  const fetchData = async () => {
195
224
  try {
196
225
  //Oil Data poe.ninja
197
- const oilData = await ninjaAPI.item.oil.getData(requestedProperties);
226
+ const oilData = await ninjaAPI.itemView.oil.getData(requestedProperties);
198
227
 
199
228
 
200
229
  console.log("poe.ninja Oil Data:", oilData);
201
230
 
202
231
  //Currency Data poe.ninja
203
- const currencyData = await ninjaAPI.currencyWiev.currency.getData(requestedProperties);
232
+ const currencyData = await ninjaAPI.currencyView.currency.getData(requestedProperties);
204
233
 
205
234
  console.log("poe.ninja Currency Data:", currencyData);
206
235
 
207
236
  //Scarab Data poe.watch
208
- const scarabData = await watchAPI.wiev.scarab.getData(requestedProperties)
237
+ const scarabData = await watchAPI.view.scarab.getData(requestedProperties)
209
238
 
210
239
  console.log("poe.watch Scarab Data", scarabData);
211
240
  } catch (error) {
212
241
  console.error("Error fetching data:", error);
213
242
  }
214
243
  };
215
- ```
244
+ ```
package/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  const NinjaAPI = require("./lib/NinjaAPI");
2
2
  const WatchAPI = require("./lib/WatchAPI");
3
+ const Utils = require("./lib/Utils");
3
4
 
4
5
  module.exports = {
5
6
  NinjaAPI: NinjaAPI,
6
7
  WatchAPI: WatchAPI,
8
+ Utils: Utils,
7
9
  };
package/lib/Utils.js ADDED
@@ -0,0 +1,26 @@
1
+ const getLeagues = require("./modules/utils/getLeagues");
2
+
3
+ /**
4
+ * A utility class.
5
+ *
6
+ * @class
7
+ */
8
+ class Utils {
9
+ constructor() {}
10
+ /**
11
+ * Fetches the list of leagues for the game.
12
+ * @async
13
+ * @function getLeagues
14
+ * @returns {Promise<string[]>} The array of league names.
15
+ * @throws {Error} If there's an error fetching the leagues.
16
+ */
17
+ async getLeagues() {
18
+ try {
19
+ return getLeagues();
20
+ } catch (error) {
21
+ throw new Error(`Error fetching data Leagues: ${error.message}`);
22
+ }
23
+ }
24
+ }
25
+
26
+ module.exports = Utils;
package/lib/WatchAPI.js CHANGED
@@ -49,7 +49,7 @@ class WatchAPI {
49
49
  *
50
50
  * @type {WatchWievModule}
51
51
  */
52
- this.wiev = new WatchWievModule(this.#leagueUrl);
52
+ this.view = new WatchWievModule(this.#leagueUrl);
53
53
  }
54
54
  }
55
55
 
@@ -0,0 +1,55 @@
1
+ const fetchData = require("../fetch/fetch");
2
+
3
+ /**
4
+ * Fetches data based on the provided query URL and filters it by category name.
5
+ *
6
+ * @async
7
+ * @function
8
+ * @param {string} queryUrl - The URL to fetch the data from.
9
+ * @param {string} categoryName - The name of the category to filter the data by.
10
+ * @returns {Promise<Array<Object>|Object>} - A promise that resolves to an array of filtered data items.
11
+ * @throws {Error} Throws an error if category name is not provided or if there is an issue fetching or filtering the data.
12
+ */
13
+ const getCategory = async (queryUrl, categoryName) => {
14
+ try {
15
+ /**
16
+ * @type {Array<Object>} fetchedData - The fetched data.
17
+ */
18
+ const fetchedData = await fetchData(queryUrl);
19
+
20
+ // Validate category name
21
+ if (!categoryName && categoryName !== 0) {
22
+ /**
23
+ * Throws an error if the category name is not provided.
24
+ * @throws {Error}
25
+ */
26
+ throw new Error("Category name is required.");
27
+ }
28
+
29
+ // Filter data by category name
30
+ const filteredData = fetchedData.filter(
31
+ (item) => item.group === categoryName
32
+ );
33
+
34
+ // Check if filtered data is empty
35
+ if (filteredData.length === 0) {
36
+ /**
37
+ * Throws an error if no data is found for the specified category.
38
+ * @throws {Error}
39
+ */
40
+ throw new Error(`No data found for category: ${categoryName}`);
41
+ }
42
+
43
+ return filteredData;
44
+ } catch (error) {
45
+ /**
46
+ * Throws an error if there's an issue fetching or filtering data for the category.
47
+ * @throws {Error}
48
+ */
49
+ throw new Error(
50
+ `Error fetching or filtering data for category: ${error.message}`
51
+ );
52
+ }
53
+ };
54
+
55
+ module.exports = getCategory;
@@ -1,4 +1,5 @@
1
1
  const getData = require("../functions/getData");
2
+ const getCategory = require("../functions/getCategory");
2
3
 
3
4
  /**
4
5
  * Represents a module for fetching data related to Accessories.
@@ -53,6 +54,35 @@ class AccessoryModule {
53
54
  throw new Error(`Error fetching accessory data: ${error.message}`);
54
55
  }
55
56
  }
57
+ /**
58
+ * Asynchronously retrieves accessory data based on the specified category name.
59
+ *
60
+ * @async
61
+ * @param {string} categoryName - The name of the category to retrieve.
62
+ * * Possible values: "amulets", "rings", "belts", "quivers".
63
+ * @returns {Promise<Array<Object>>} - A promise that resolves to the retrieved data.
64
+ * @throws {Error} - Throws an error if there is an issue fetching or processing the accessory data for the specified category.
65
+ *
66
+ */
67
+ async getCategory(categoryName) {
68
+ try {
69
+ /**
70
+ * Calls the getCategory function to fetch accessory data based on category name.
71
+ *
72
+ * @type {Promise<Array<Object>>}
73
+ */
74
+ return getCategory(this.#queryUrl, categoryName);
75
+ } catch (error) {
76
+ /**
77
+ * Throws an error if there's an issue fetching or processing the accessory data for the specified category.
78
+ *
79
+ * @throws {Error}
80
+ */
81
+ throw new Error(
82
+ `Error fetching data Accessory Category: ${error.message}`
83
+ );
84
+ }
85
+ }
56
86
  }
57
87
 
58
88
  // Export the AccessoryModule class
@@ -1,4 +1,5 @@
1
1
  const getData = require("../functions/getData");
2
+ const getCategory = require("../functions/getCategory");
2
3
 
3
4
  /**
4
5
  * Represents a module for fetching data related to Armour.
@@ -53,6 +54,33 @@ class ArmourModule {
53
54
  throw new Error(`Error fetching armour data: ${error.message}`);
54
55
  }
55
56
  }
57
+ /**
58
+ * Asynchronously retrieves armour data based on the specified category name.
59
+ *
60
+ * @async
61
+ * @param {string} categoryName - The name of the category to retrieve.
62
+ * * Possible values: "chest", "bodyarmours", "shield", "boots", "gloves", "shields", "helmets", "quiver".
63
+ * @returns {Promise<Array<Object>>} - A promise that resolves to the retrieved data.
64
+ * @throws {Error} - Throws an error if there is an issue fetching or processing the armour data for the specified category.
65
+ *
66
+ */
67
+ async getCategory(categoryName) {
68
+ try {
69
+ /**
70
+ * Calls the getCategory function to fetch armour data based on category name.
71
+ *
72
+ * @type {Promise<Array<Object>>}
73
+ */
74
+ return getCategory(this.#queryUrl, categoryName);
75
+ } catch (error) {
76
+ /**
77
+ * Throws an error if there's an issue fetching or processing the armour data for the specified category.
78
+ *
79
+ * @throws {Error}
80
+ */
81
+ throw new Error(`Error fetching data Armour Category: ${error.message}`);
82
+ }
83
+ }
56
84
  }
57
85
 
58
86
  // Export the ArmourModule class
@@ -1,4 +1,5 @@
1
1
  const getData = require("../functions/getData");
2
+ const getCategory = require("../functions/getCategory");
2
3
 
3
4
  /**
4
5
  * Represents a module for fetching data related to Bases.
@@ -53,6 +54,33 @@ class BaseModule {
53
54
  throw new Error(`Error fetching base data: ${error.message}`);
54
55
  }
55
56
  }
57
+ /**
58
+ * Asynchronously retrieves base data based on the specified category name.
59
+ *
60
+ * @async
61
+ * @param {string} categoryName - The name of the category to retrieve.
62
+ * * Possible values: "armour", "weapons", "accessories".
63
+ * @returns {Promise<Array<Object>>} - A promise that resolves to the retrieved data.
64
+ * @throws {Error} - Throws an error if there is an issue fetching or processing the base data for the specified category.
65
+ *
66
+ */
67
+ async getCategory(categoryName) {
68
+ try {
69
+ /**
70
+ * Calls the getCategory function to fetch base data based on category name.
71
+ *
72
+ * @type {Promise<Array<Object>>}
73
+ */
74
+ return getCategory(this.#queryUrl, categoryName);
75
+ } catch (error) {
76
+ /**
77
+ * Throws an error if there's an issue fetching or processing the base data for the specified category.
78
+ *
79
+ * @throws {Error}
80
+ */
81
+ throw new Error(`Error fetching data Base Category: ${error.message}`);
82
+ }
83
+ }
56
84
  }
57
85
 
58
86
  // Export the BaseModule class
@@ -53,6 +53,35 @@ class GemModule {
53
53
  throw new Error(`Error fetching Skill Gem data: ${error.message}`);
54
54
  }
55
55
  }
56
+ /**
57
+ * Asynchronously retrieves gems data based on the specified category name.
58
+ *
59
+ * @async
60
+ * @param {string} categoryName - The name of the category to retrieve.
61
+ * * Possible values: "supportgem", "gems".
62
+ * @returns {Promise<Array<Object>>} - A promise that resolves to the retrieved data.
63
+ * @throws {Error} - Throws an error if there is an issue fetching or processing the gems data for the specified category.
64
+ *
65
+ */
66
+ async getCategory(categoryName) {
67
+ try {
68
+ /**
69
+ * Calls the getCategory function to fetch gems data based on category name.
70
+ *
71
+ * @type {Promise<Array<Object>>}
72
+ */
73
+ return getCategory(this.#queryUrl, categoryName);
74
+ } catch (error) {
75
+ /**
76
+ * Throws an error if there's an issue fetching or processing the gems data for the specified category.
77
+ *
78
+ * @throws {Error}
79
+ */
80
+ throw new Error(
81
+ `Error fetching data Skill Gem Category: ${error.message}`
82
+ );
83
+ }
84
+ }
56
85
  }
57
86
 
58
87
  // Export the GemModule class
@@ -1,4 +1,5 @@
1
1
  const getData = require("../functions/getData");
2
+ const getCategory = require("../functions/getCategory");
2
3
 
3
4
  /**
4
5
  * Represents a module for fetching data related to Weapons.
@@ -53,6 +54,33 @@ class WeaponModule {
53
54
  throw new Error(`Error fetching Weapon data: ${error.message}`);
54
55
  }
55
56
  }
57
+ /**
58
+ * Asynchronously retrieves weapon data based on the specified category name.
59
+ *
60
+ * @async
61
+ * @param {string} categoryName - The name of the category to retrieve.
62
+ * * Possible values: "twohandswords", "fishingrods", "onehandswords", "twohandaxes", "staves", "warstaff", "daggers", "scepters".
63
+ * @returns {Promise<Array<Object>>} - A promise that resolves to the retrieved data.
64
+ * @throws {Error} - Throws an error if there is an issue fetching or processing the weapon data for the specified category.
65
+ *
66
+ */
67
+ async getCategory(categoryName) {
68
+ try {
69
+ /**
70
+ * Calls the getCategory function to fetch weapon data based on category name.
71
+ *
72
+ * @type {Promise<Array<Object>>}
73
+ */
74
+ return getCategory(this.#queryUrl, categoryName);
75
+ } catch (error) {
76
+ /**
77
+ * Throws an error if there's an issue fetching or processing the weapon data for the specified category.
78
+ *
79
+ * @throws {Error}
80
+ */
81
+ throw new Error(`Error fetching data Weapon Category: ${error.message}`);
82
+ }
83
+ }
56
84
  }
57
85
 
58
86
  // Export the WeaponModule class
@@ -0,0 +1,22 @@
1
+ const axios = require("axios");
2
+
3
+ /**
4
+ * Fetches data from the provided URL using Axios.
5
+ * @param {string} url The URL to fetch data from.
6
+ * @returns {Promise<any>} A Promise that resolves with the fetched data.
7
+ * @throws {Error} If an error occurs during the fetch process.
8
+ */
9
+ async function fetchData(url) {
10
+ try {
11
+ const response = await axios.get(url);
12
+ if (response.data) {
13
+ return response.data;
14
+ } else {
15
+ throw new Error("Invalid response fetched");
16
+ }
17
+ } catch (error) {
18
+ throw new Error(`Error fetching data: ${error.message}`);
19
+ }
20
+ }
21
+
22
+ module.exports = fetchData;
@@ -0,0 +1,24 @@
1
+ const fetchData = require("./functions/fetch/fetch");
2
+
3
+ /**
4
+ * Fetches league names from the provided URL.
5
+ *
6
+ * This function fetches data from the specified URL which contains information about
7
+ * Path of Exile leagues. It then extracts the names of the leagues from the fetched data
8
+ * and returns them as an array.
9
+ *
10
+ * @returns {Promise<string[]>} A Promise that resolves with an array of league names.
11
+ * @throws {Error} If an error occurs during the fetch process or if the response data is empty.
12
+ */
13
+ async function getLeagues() {
14
+ const url = "https://api.poe.watch/leagues";
15
+ try {
16
+ const fetchedData = await fetchData(url);
17
+ const names = fetchedData.map((item) => item.name);
18
+ return names;
19
+ } catch (error) {
20
+ throw new Error(`Error fetching League Names: ${error.message}`);
21
+ }
22
+ }
23
+
24
+ module.exports = getLeagues;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poe-api-manager",
3
- "version": "0.2.6",
3
+ "version": "1.0.0",
4
4
  "description": "API management for poe.ninja and poe.watch",
5
5
  "main": "index.js",
6
6
  "scripts": {