-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
214 changed files
with
13,441 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
extends: [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:@typescript-eslint/recommended-requiring-type-checking", | ||
"prettier", | ||
], | ||
parser: "@typescript-eslint/parser", | ||
ignorePatterns: [".eslintrc.js"], | ||
parserOptions: { | ||
project: "./tsconfig.json", | ||
}, | ||
plugins: ["@typescript-eslint"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [10.x, 12.x, 14.x, 15.x] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Setup Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Run unit tests | ||
env: | ||
POESESSID: ${{ secrets.POESESSID }} | ||
run: env POESESSID=$POESESSID npm run test:ci | ||
|
||
docs: | ||
name: Generate documentation | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: npm ci --ignore-scripts | ||
- run: npm run build:docs | ||
- name: Deploy to GitHub Pages | ||
uses: peaceiris/actions-gh-pages@v3 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./docs | ||
|
||
release: | ||
name: Release | ||
needs: test | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12 | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Build | ||
run: npm run build --if-present | ||
- name: Release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: npx semantic-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
spec: ["src/**/*.spec.ts"], | ||
require: ["ts-node/register/transpile-only", "./src/mochaFixtures.ts"], | ||
recursive: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"tabWidth": 4, | ||
"useTabs": false, | ||
"semi": true, | ||
"singleQuote": false, | ||
"trailingComma": "es5", | ||
"bracketSpacing": true, | ||
"arrowParens": "always", | ||
"printWidth": 100 | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Contributing | ||
|
||
Thanks for wanting to contribute to this project! | ||
|
||
When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change. | ||
|
||
## Report bugs using Github's [issues](https://github.com/klayveR/poe-api-wrappers/issues) | ||
|
||
We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/klayveR/poe-api-wrappers/issues/new). | ||
|
||
## Code contribution guidelines | ||
|
||
To make changes to the codebase, fork the repository from the `main` branch. When you are done, please submit a pull request. Please do **not** update the version in `package.json`. | ||
|
||
### Tests | ||
|
||
If you've added code that needs to be tested, add tests and make sure the tests pass. | ||
To run the test suite, create a `.env` file in the root directory with the following content. | ||
|
||
``` | ||
POESESSID=your-poe-session-id | ||
``` | ||
|
||
Then, run the tests with `npm run test` or `npm run test:coverage` to also generate coverage reports. | ||
|
||
### Documentation | ||
|
||
APIs that are available to the end-user should be documented using [TypeDoc doc comments](https://typedoc.org/guides/doccomments/). Code that is only used internally does not necessarily need to be documented if it's intuitive and easy to understand, but it's obviously preferred to document it. | ||
|
||
### Commits | ||
|
||
Commit messages should follow the [angular commit message format](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-format). | ||
|
||
### Code Style | ||
|
||
To guarantee a uniform code style, please run `npm run prettier`. Also, make sure your code lints (`npm run lint`). | ||
|
||
## License | ||
|
||
By contributing, you agree that your contributions will be licensed under its MIT License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Tobias Hoffmann | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Path of Exile API Wrappers | ||
|
||
This library was created to make interacting with the official and third-party APIs for Path of Exile easier. Data can be requested with a simple function call, the responses are then converted into fully typed class objects which you can interact with. For example, when posting a search query to the trade API, you can immediately request the listings by calling a function on the search result object which contains the hashes (see [Examples](#examples)). Please check out the documentation for more information. | ||
|
||
Since there are so many APIs with varying response structures, things may be incorrect or missing. If you notice something that needs to be added or fixed, please submit an [issue](https://github.com/klayveR/poe-api-wrappers/issues). | ||
|
||
# Getting started | ||
|
||
**Install with npm:** | ||
|
||
```bash | ||
$ npm i @klayver/poe-api-wrappers --save | ||
``` | ||
|
||
# Contributing | ||
|
||
Please refer to [CONTRIBUTING.md](https://github.com/klayveR/poe-api-wrappers/blob/main/CONTRIBUTING.md). | ||
|
||
# Examples | ||
|
||
## Path of Exile API | ||
|
||
> ⚠️ The following examples do not handle errors to keep it simple. You should wrap your calls in a try/catch block or do whatever you do to catch errors (see [Handling errors](#handling-errors)). Also, keep in mind that many APIs are rate limited, so if you want to hit an API often in a short timeframe, consider implementing logic to comply with rate limits. | ||
Before making requests to the official API, you should set your user agent, as requested by GGG [here](https://www.pathofexile.com/forum/view-thread/3019033/page/1#p23790007). | ||
|
||
```typescript | ||
import { PathOfExile } from "@klayver/poe-api-wrappers"; | ||
|
||
PathOfExile.Settings.userAgent = "my-awesome-tool-name, contact@me.com"; | ||
``` | ||
|
||
**Get 10 public stash tab chunks and do something with them** | ||
|
||
```typescript | ||
let chunk = await PathOfExile.PublicStashTabs.get(); | ||
|
||
for (let i = 0; i < 9; i++) { | ||
console.log(`This chunk has ${chunk.stashes.length} stashes.`); | ||
chunk = await chunk.getNext(); | ||
} | ||
``` | ||
|
||
**Get the entire Standard league ladder and filter it by online players** | ||
|
||
```typescript | ||
// Get the ladder with the first 200 entries | ||
const ladder = await PathOfExile.Ladders.get("Standard", { limit: 200 }); | ||
|
||
// Request the remaining entries in chunks of 200 until there are no entries left | ||
while ((await ladder.getNextEntries()) != null) { | ||
console.log(`Current entries: ${ladder.entries.length}`); | ||
} | ||
|
||
// Filter by online players | ||
const online = ladder.filterBy("online", true); | ||
console.log(`${online.length}/${ladder.total} players are currently online.`); | ||
``` | ||
|
||
**Execute a search query and get the prices for the first 10 results** | ||
|
||
```typescript | ||
const query = { | ||
query: { | ||
status: { option: "online" }, | ||
name: "Shavronne's Wrappings", | ||
type: "Occultist's Vestment", | ||
}, | ||
sort: { price: "asc" }, | ||
}; | ||
|
||
const search = await PathOfExile.Trade.search("Standard", query); | ||
const results = await search.getNextItems(); | ||
|
||
if (results != null) { | ||
for (const result of results) { | ||
const price = result.listing.price; | ||
console.log(`Item is being sold for ${price.amount} ${price.currency}`); | ||
} | ||
} | ||
``` | ||
|
||
### Handling errors | ||
|
||
Requests to the Path of Exile API throw custom errors when something goes wrong. The thrown custom error class include the same error codes as the ones documented in the [official developer API documentation](https://th.pathofexile.com/developer/docs/api-errors). Please note that you should also check for other errors, which might occur when, for example, no internet connection is available. | ||
|
||
```typescript | ||
try { | ||
await PathOfExile.Account.getAvatars("invalid"); | ||
} catch (error: unknown) { | ||
if (error instanceof PathOfExile.APIError) { | ||
console.log(`Request failed with code ${error.code}: ${error.message}`); | ||
} | ||
|
||
// Handle other errors... | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"use strict"; | ||
|
||
const { parserPlugins } = require("@istanbuljs/schema").defaults.nyc; | ||
|
||
module.exports = { | ||
cache: false, | ||
parserPlugins: parserPlugins.concat("typescript", "decorators-legacy"), | ||
}; |
Oops, something went wrong.