Options
All
  • Public
  • Public/Protected
  • All
Menu

Class NsWeb

Provides access to some parts of NationStates not exposed through the standard API.

Hierarchy

  • NsWeb

Index

Constructors

constructor

  • new NsWeb(userAgent: string, delay?: boolean, requestDelayMillis?: number, allowImmediateRequests?: boolean): NsWeb
  • Initializes a new instance of the NsWeb class.

    Parameters

    • userAgent: string

      A string identifying you to NationStates. Using the name of your main nation is recommended.

    • Default value delay: boolean = true

      Whether a delay is introduced before requests. Defaults to true.

    • Default value requestDelayMillis: number = 6000

      The delay before requests in milliseconds. Defaults to 6000.

    • Default value allowImmediateRequests: boolean = true

      Allows requests immediately after this NsWeb instance is initialized.

    Returns NsWeb

Properties

Private _blockExistingRequests

_blockExistingRequests: boolean

Private _blockNewRequests

_blockNewRequests: boolean

Private _cleanup

_cleanup: boolean

Private _delay

_delay: boolean

Private _interval

_interval: any

Private _lastRequestTime

_lastRequestTime: number

Private _queue

_queue: object[]

Private _requestDelayMillis

_requestDelayMillis: number

Private _requestInProgress

_requestInProgress: boolean

Private _userAgent

_userAgent: string

Accessors

blockExistingRequests

  • get blockExistingRequests(): boolean
  • set blockExistingRequests(blockExistingRequests: boolean): void
  • Gets whether this NsWeb instance is blocked from performing any further requests.

    Returns boolean

  • Sets whether this NsWeb instance is blocked from performing any further requests.

    Parameters

    • blockExistingRequests: boolean

    Returns void

blockNewRequests

  • get blockNewRequests(): boolean
  • set blockNewRequests(blockNewRequests: boolean): void
  • Gets whether new requests are blocked from being added to the queue.

    Returns boolean

  • Sets whether new requests are blocked from being added to the queue.

    Parameters

    • blockNewRequests: boolean

    Returns void

delay

  • get delay(): boolean
  • set delay(delay: boolean): void
  • Gets whether a delay is introduced before requests.

    Setting this value re-initializes the scheduler.

    Returns boolean

  • Sets a value indicating whether a delay is introduced before requests.

    Setting this value re-initializes the scheduler.

    Parameters

    • delay: boolean

    Returns void

requestDelayMillis

  • get requestDelayMillis(): number
  • set requestDelayMillis(requestDelayMillis: number): void
  • Gets the delay before requests in milliseconds.

    Returns number

  • Sets the delay before requests in milliseconds. Must be greater than or equal to 6000.

    Parameters

    • requestDelayMillis: number

    Returns void

requestInProgress

  • get requestInProgress(): boolean
  • Gets whether a request is in progress.

    Returns boolean

requestsQueued

  • get requestsQueued(): boolean
  • Gets whether there is at least one request in the queue.

    Returns boolean

userAgent

  • get userAgent(): string
  • set userAgent(userAgent: string): void
  • Gets a string identifying you to NationStates.

    Returns string

  • Sets a string identifying you to NationStates. Using the name of your main nation is recommended.

    Parameters

    • userAgent: string

    Returns void

Methods

cleanup

  • cleanup(): void
  • Cancels all requests in the API queue and turns off the API scheduler.

    After this function is called, no further requests can be made using this API instance, including requests currently in the queue.

    Returns void

clearQueue

  • clearQueue(): void
  • Cancels all requests in the queue.

    Returns void

Private initInterval

  • initInterval(): void
  • Initializes the API scheduler.

    Returns void

Private postRequest

  • postRequest(data: string): Promise<HttpResponse>
  • Creates a POST request to the NationStates website with the specified data.

    Parameters

    • data: string

      The specified data.

    Returns Promise<HttpResponse>

    A promise returning the response and associated data.

restoreRequest

  • restoreRequest(nation: string, password: string): Promise<void>
  • Attempts to restore the specified NationStates nation using the specified password.

    This call affects parts of NationStates other than the specified nation. Automating this request is a violation of NationStates script rules.

    Parameters

    • nation: string

      The nation name to log in with.

    • password: string

      The password to log in with.

    Returns Promise<void>

    A void promise. An error will be thrown if restoration fails.

Static Private toId

  • toId(name: string): string
  • Converts names to a fixed form: all lowercase, with spaces replaced with underscores.

    Parameters

    • name: string

      The name to convert.

    Returns string

    The converted name.

Generated using TypeDoc