Skip to content

Commit

Permalink
feat: official api wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
klayveR committed Mar 23, 2021
1 parent 357ab27 commit 63c358f
Show file tree
Hide file tree
Showing 214 changed files with 13,441 additions and 43 deletions.
15 changes: 15 additions & 0 deletions .eslintrc.js
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"],
};
70 changes: 70 additions & 0 deletions .github/workflows/ci.yml
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
54 changes: 11 additions & 43 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,29 @@ logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Distribution
dist/

# Documentation
docs/

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
Expand All @@ -44,21 +45,12 @@ jspm_packages/
# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

Expand All @@ -70,35 +62,11 @@ typings/

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
# next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/
# VSCODE
.vscode

# TernJS port file
.tern-port
src/playground.ts
5 changes: 5 additions & 0 deletions .mocharc.js
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,
};
10 changes: 10 additions & 0 deletions .prettierrc
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 added CHANGELOG.md
Empty file.
40 changes: 40 additions & 0 deletions CONTRIBUTING.md
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.
21 changes: 21 additions & 0 deletions LICENSE
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.
97 changes: 97 additions & 0 deletions README.md
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...
}
```
8 changes: 8 additions & 0 deletions nyc-config.js
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"),
};
Loading

0 comments on commit 63c358f

Please sign in to comment.