UNPKG

nationstates.js

Version:

A wrapper to interact with the NationStates API.

63 lines (62 loc) 2.63 kB
import { API, Client } from "../client"; import { RequestBuilder } from "../request_builder/request_builder"; /** * Defines the options for downloading dumps and what to do with them. */ export interface IDumpOptions { extract?: boolean; deleteXMLGz?: boolean; deleteXML?: boolean; convertToJson?: boolean; } /** * As opposed to building requests manually, this class has built-in methods for easily accessing and handling * common information one looks for. You do not build, send, or parse requests manually. * @example const methods = new NSMethods(api); * @param { API } client The client object to enforce rate limiting and user agents. */ export declare class NSMethods extends RequestBuilder { constructor(api: API | Client); /** * Returns a boolean response, if nation1 is endorsing nation2. * Does not modify the URL of the request. * @example console.log(await methods.isEndorsing('Testlandia', 'Testlandia')); // false * @param nation1 - The endorser. * @param nation2 - The endorsee. */ isEndorsing(nation1: string, nation2: string): Promise<boolean>; /** * Use the NS Verification client to verify the validity of a verification code. * Returns either a 0 or 1 as a number, as described in the NS client documentation. * @example console.log(await methods.verify('Testlandia', '12345')); // 0 * @param nation * @param checksum * @param siteSpecificToken */ verify(nation: string, checksum: string, siteSpecificToken?: string): Promise<number>; /** * Download the nation data dump from the client. * Note that it can take a while to download the dump, especially for nations or when converting to JSON. * Future feature: Decode utf-8 within the dump. * @example methods.downloadDump('Testlandia', {extract: true, deleteXMLGz: true, deleteXML: true, convertToJson: true}); // Returns just a .json file * @param type - Either 'nation' or 'region' * @param directoryToSave - The directory to save the dump to. Should be ended by a slash. Ex: "./downloads/" * @param options - If left blank, just downloads the {type}.xml.gz file. */ downloadDumpAsync(type: string, directoryToSave: string, options?: IDumpOptions): Promise<NSMethods>; /** * Extracts a gzipped file. * @param file * @param savePath * @private */ private gunzip; /** * Converts an XML file to JSON and saves it to the specified path. * Uses the XML2Js library. * @param file * @param savePath * @private */ private xmlToJson; }