poe-api-manager 0.2.8 → 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 +7 -2
- package/README.md +18 -2
- package/index.js +2 -0
- package/lib/Utils.js +26 -0
- package/lib/modules/utils/functions/fetch/fetch.js +22 -0
- package/lib/modules/utils/getLeagues.js +24 -0
- package/package.json +1 -1
package/Changelog.md
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
|
+
## 1.0.0
|
|
3
|
+
- 🚀[New] utils class
|
|
4
|
+
- 🚀[New] utils `getLeagues`function. Get league name.
|
|
5
|
+
- 📝 [Update] The documentation has been updated.
|
|
6
|
+
|
|
2
7
|
## 0.2.8
|
|
3
8
|
- 🚀[Added] poe.watch API with `getCategory()` function.
|
|
4
|
-
- 🛠️ [Fixed]
|
|
9
|
+
- 🛠️ [Fixed] Typo in WatchAPI class
|
|
5
10
|
- 📝 [Update] The documentation has been updated.
|
|
6
11
|
## 0.2.6
|
|
7
12
|
- 🎨[Added] JSDocs for easy understanding.
|
|
@@ -19,4 +24,4 @@
|
|
|
19
24
|
- Invitations
|
|
20
25
|
- Memories
|
|
21
26
|
|
|
22
|
-
## 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
|
[](https://choosealicense.com/licenses/mit/)
|
|
4
|
-

|
|
5
5
|

|
|
6
6
|
[](https://github.com/ayberkgezer/poe-api-manager/issues)
|
|
7
7
|

|
|
@@ -164,6 +164,22 @@ watchAPI.view.armour.getCategory("chest").then((data) => {
|
|
|
164
164
|
console.log(data);
|
|
165
165
|
});
|
|
166
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
|
+
|
|
167
183
|
|
|
168
184
|
## Examples
|
|
169
185
|
```javascript
|
|
@@ -225,4 +241,4 @@ const fetchData = async () => {
|
|
|
225
241
|
console.error("Error fetching data:", error);
|
|
226
242
|
}
|
|
227
243
|
};
|
|
228
|
-
```
|
|
244
|
+
```
|
package/index.js
CHANGED
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;
|
|
@@ -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;
|