Skip to content

A super simple npm library for interacting with Politics and War using JavaScript/TypeScript.

License

Notifications You must be signed in to change notification settings

dkantereivin/pnw4js

Repository files navigation

pnw4js

pnw4js is a simple, type safe, promise-based JavaScript library for accessing the Politics & War API. It is written in TypeScript for CommonJS, NodeJS and TypeScript. Compiles to ES5.

Features

Why use pnw4js?

  • Extremely Simple To Install, Setup and Use
  • Clear, Extensive Documentation
  • Constant Support
  • Async, promise-based
  • Type Safe
  • Only JavaScript library for PnW

Installation

The easiest way to install pnw4js is using npm in your project directory.

cd project_dir
npm install pnw4js

For greater flexibility — such as the ability to edit the code or manually configure the APIs — you are able to manually clone the project from the github. In your project directory, you will want to clone the Git repository. Note that you can still make changes to an npm installation of pnw4js, at the risk of it being lost in an update.

cd project_dir
git clone https://github.com/dkantereivin/pnw4js # Project from Github
npm install # Installs all dependencies
npm install typescript # for compiling github project
tsc

You will then see a dist folder which contains .js files. Copy the entire contents of the folder into your project folder. To edit the files, you should perform any edits in .ts source files and then recompile using tsc.

Usage

For standard installation using npm, the following code outlines usage.

NodeJS:
const PoliticsAndWar = require("pnw4js");
let pnw = new PoliticsAndWar("key", "password");

let nationCall = await pnw.nation(64060); // test call
CommonJS/TypeScript:
import PoliticsAndWar from "pnw4js";
let pnw = new PoliticsAndWar("key", "password");

let nationCall = await pnw.nation(64060);

This library is compatible with TypeScript. Please see Documentation for in-depth documentation. The PoliticsAndWar(key, [pass]) constructor requires a string parameter for the key, and the default password is pnw. The password is readonly, however key can be updated using the setKey(key) method.

Documentation & Support

In order to promote ease of use and accessibility, this library is straightforward and documented on Github Pages written and generated using TSDoc.

Please click here to view generated documentation. Alternatively, just read through source code, type annotations and inline documentation.

Support

This library is actively supported and developed by the creator. Feel free to post an issue on the page, or contact me on Discord @Canter#0548 (send a friend request). You can also join the my Discord and ping me.

Testing & Updates

This library has been tested and deployed in NodeJS and browser environments. That being said, there likely exist undiscovered bugs. Please submit an issue request if you encounter any problems using the library.

This is current Version 1 of pnw4js. Future versions are likely to include:

  • addition of POST functions (i.e. send message, send alliance bank resources/money); approved by Alex
  • caching of recent calls; either based on expiry time, cache memory size, or number of cached records
  • support for the game's APIv2, when it is released
  • creating an exposed "raw" api function, and a function to call an api by string (for convenience)
  • filtering of API calls on top of those provided by the API, and analysis of results
  • compatability with Google Sheets using Babel and clasp (unlikely, if you want this, please contact me)
  • Wiki and better documentation (on Github)

Any code written using current project versions will continue to be supported in future versions.

New in v1.0.6

  • added missing wars and warAttacks api, contributed by luketp
  • updated README: corrected future plans and installation instructions
  • distribution code being run by JavaScript is now optimized and minified using the Closure Compiler
  • documentation removed from npm package to reduce size
  • minor miscellaneous changes to functions.ts
  • updated all dependencies to latest versions

Contributing

As an open-source project, any pull requests are welcome! If you implement the library and create any major features, please feel free to send me a message if you're unsure on how to implement them into the library.

Pull requests are welcome. Please include a description of each commit, and keep your contributions atomic - one major feature per pull request please!

License

MIT

About

A super simple npm library for interacting with Politics and War using JavaScript/TypeScript.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •