Giter Site home page Giter Site logo

pnwkit.gs's Introduction

Open in Visual Studio Code

Logo

PnWKit.gs

Politics & War V3 API Library
Explore the docs »

JS/TS Version · Python Version · Report Bug · Request Feature

PnWKit is here to make interacting with the V3 Politics and War API easy. All you have to do is import the library, add your key, and make a query.

Getting Started

This version of the PnWKit Library is for Google Apps Scripts so you can use the V3 API in spreadsheets easily. You will have to add it as a library using the library code.

Prerequisites

Install the library using the code: 1Of_sAY3Me77EKy14A5tQdcNY57SPC9KpI739YYio8t04XqkFSd0pPfjQ.

Usage

To use PnWKit just add your key, then you can make asyncronous queries.

pnwkit.setKey('xxxxx');

const nations = await pnwkit.nationQuery({id: [100541], first: 1}, `name`);

console.log(`Nation name: ${nations[0].name}`);

If you want to paginate your query for more results, just enable pagination after your query.

const nations = await pnwkit.nationQuery({id: [100541], first: 1}, `name`, true);

console.log(`Nation name: ${nations.data[0].name}, current page: ${nations.paginatorInfo.currentPage}`);

The queries are written in normal GraphQL, so you can get all the cities in a nation like this

const nations = await pnwkit.nationQuery({id: [100541], first: 1}, 
  `
  name,
  cities {
    name  
  }`);

console.log(`First city of ${nations[0].name}: ${nations[0].cities[0].name}`);

If you want to have multiple copies of PnWKit running at the same time, you can use the Kit class export.

const {Kit} = pnwkit;

const pnwkit = new Kit();
pnwkit.setKey('xxxx');

// queries...

Caching

PnWKit has caching built right in for your convenience. Just create a cache function with PnWKit.cached and define how long it can be cached for. Then call it like normal.

Different calls return different cached versions too.

const cachableNationQuery = pnwkit.cached(
  pnwkit.nationQuery, // The query you want to cache
  1                   // How long that query can be cached at a time, in minutes
);

const nations = await cachableNationQuery({id: [100541], first: 1}, `name`);

// If you call it again within the age limit you'll get a cached version
const nationsCached = await cachableNationQuery({id: [100541], first: 1}, `name`);

Rate-limit Information

Currently, PnWKit for GAS cannot collect rate-limit information, however JS/TS and Python can.

You can also do the following queries in PnWKit:

  • nationQuery
  • allianceQuery
  • tradePricesQuery
  • tradeQuery
  • warQuery
  • treasureQuery
  • colorQuery
  • bountyQuery
  • cityQuery
  • warAttackQuery
  • bankRecordsQuery

You can look at the arguments and possible data to collect here at the docs.

Development

Testing

Setup

Tests won't work right away, you have to specify private information inside the test/testconfig.json file.

It should look like this:

{
  "apiKey": "xxxxx"
}

After that just run npm run test

Generating Docs

To generate documentation use the script: npm run docs.

pnwkit.gs's People

Contributors

bsnk-dev avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

pnwkit.gs's Issues

:V

I hate this product.
It works too well.
Code is ment to be buggy and trash.
Why does this work.
Illigal.
U go to jail for being too good at your job.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.