dotNS 0.5.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package dotNS --version 0.5.0
NuGet\Install-Package dotNS -Version 0.5.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="dotNS" Version="0.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add dotNS --version 0.5.0
#r "nuget: dotNS, 0.5.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install dotNS as a Cake Addin
#addin nuget:?package=dotNS&version=0.5.0

// Install dotNS as a Cake Tool
#tool nuget:?package=dotNS&version=0.5.0

dotNS - NationStates API access in C#

A C# library for NationStates API access. Developed by The Empire of IKTeam (Our Glorious Nation)

Flag of Our Glorious Nation

We are now on NuGet! We are now on NuGet!

Features

  • High level API access to nation and region information, some public and private shards.
  • Low level API access for public and private shards
  • Issues interaction
  • PIN-code authentication
  • May act like both a low-level wrapper and high-level OOP library

Usage

Initialization

For public shards only, this should be sufficient:

using dotNS;
<...>
DotNS api = new DotNS();

If you later wish to authenticate, you can use this method call:

// Updates PIN value of the class. Can be used to re-auth.
api.UpdatePin("nation name", "password");

or just use this constructor:

// Initializes NS API wrapper and automatically acquires a PIN for private API
DotNS api = new DotNS("nation name", "password");

You can (and actually should) also define your own UserAgent. You can do it either using a constructor:

DotNS api = new DotNS("nation name", "password", "UserAgent");

or after initialization

api.UserAgent = "UserAgent";

Also, to disable our API ratelimiting feature (enabled by default), use

api.RateLimit = false;

High level API example

Get basic nation information
using dotNS;
using dotNS.Classes;
<...>
// Create an API wrapper
DotNS api = new DotNS();
// Use it to acquire nation information
PublicNationInfo nation = api.GetNationInfo("nation name");
// Access information you need
Console.WriteLine($"Population: {nation.Population}, motto: {nation.Motto}");
Get basic public shard information
using dotNS;
using dotNS.Classes;
<...>
// Create an API wrapper
DotNS api = new DotNS();
// Use it to acquire basic public shard
string shard = api.PublicShard("nation name", Shards.PublicShard.Capital);
// Access information you've requested
Console.WriteLine($"The capital is {shard}");
Get basic region information
using dotNS;
using dotNS.Classes;
<...>
// Create an API wrapper
DotNS api = new DotNS();
// Use it to acquire basic region info
PublicRegionInfo info = api.GetRegionInfo("region name");
// Access information you need
Console.WriteLine($"The founder is {info.Founder} and there are {info.NumNations} in this region.");
Verification API
using dotNS;
<...>
// Create an API wrapper
DotNS api = new DotNS();
// Make a call to the API
bool result = api.Verify("nation name", "code");
// Output "Correct!" if the code is correct, or "Incorrect!" if it isn't
Console.WriteLine(result ? "Correct!" : "Incorrect!");
Respond to an issue
using dotNS;
using dotNS.Classes;
<...>
// Create an authenticated API wrapper
DotNS api = new DotNS("nation name", "password");
// Use it to acquire private nation info
PrivateNationInfo info = api.GetPrivateNation();
// Access the first issue
Issue issue = info.Issues[0];
Console.WriteLine($"The title of the first issue is {issue.Title}, and there are {issue.Options.Length} options.");
// Resolve the issue using the first option.
api.AddressIssue(issue, issue.Options[0]);
// OR, to dismiss the issue
api.AddressIssue(issue, IssueOption.DISMISS);
Access multiple private shards
using dotNS;
using dotNS.Classes;
<...>
// Create an authenticated API wrapper
DotNS api = new DotNS("nation name", "password");
// Get several shards
string[] info = api.PrivateShard(new Shards.PrivateShard[] { Shards.PrivateShard.NextIssueTime, Shards.PrivateShard.NextIssue });
// Response to the first shard will be first element of the result array
Console.WriteLine($"Next issue time: {info[0]}"); // "Next issue time: 123456789"
Console.WriteLine($"Next issue {info[1]}"); // "Next issue in 3 hours"
World daily dumps
using dotNS;
using dotNS.Classes;
using System.Xml;
<...>
// Create an API wrapper
DotNS api = new DotNS();
// Get region dump
DailyDataDump dump = api.GetDump(RequestType.Region);
// -> DailyDataDump dump = api.GetDump(RequestType.Nation);
// -> DailyDataDump dump = api.GetDump(CardSeason.Season1);
// Save as region.xml.gz
File.WriteAllBytes("region.xml.gz", dump.Content);
// Save as region.xml
File.WriteAllBytes("region.xml", dump.Decompress());
// Open as XML
XmlNodeList xml = dump.GetXml();
XmlNodeList regionsXml = xml.TakeNodes("regions");
Console.WriteLine($"There seem to be {regionsXml.Count} regions!");
Nation census statistics
using dotNS;
using dotNS.Classes;
<...>
// Create an API wrapper
DotNS api = new DotNS();
// Get Black Market data for "IKTeam" nation between Feb 4 2021 and May 31 2021 (UNIX timestamp)
List<CensusNode> censusData = api.GetCensus("IKTeam", Census.BlackMarket, 1612456412, 1622456426);
// Output required information
CensusNode node = censusData[10];
Console.WriteLine($"On {DateTimeOffset.FromUnixTimeSeconds(node.timestamp):dd/MM/yyyy HH:mm:ss} the value of Black Market in IKTeam was {node.value}");
Get flag of a nation or region
using dotNS;
using dotNS.Classes;
<...>
// Create an API wrapper
DotNS api = new DotNS();
// Get basic information of nation/region
// -> PublicRegionInfo info = api.GetRegionInfo("region");
PublicNationInfo info = api.GetNationInfo("nation");
// Get flag.
System.Drawing.Bitmap bmp = info.Flag;
bmp.Save("flag.png");
Get all cards of a nation
using dotNS;
using dotNS.Classes;
<...>
// Create an API wrapper
DotNS api = new DotNS();
// Get deck of a nation
List<IncompleteTradingCard> deck = api.GetDeck("nation");
// Output info
Console.WriteLine($"This nation has {deck.Count} total cards!");
Get information of a card
using dotNS;
using dotNS.Classes;
<...>
// Create an API wrapper
DotNS api = new DotNS();
// Get information of a card
TradingCard card = api.GetCard(1, CardSeason.Season2);
// Output information
Console.WriteLine($"Card name: {card.Name}, Market value: {card.MarketValue}");
Console.WriteLine($"Card flag resolution: {card.Flag.Width}:{card.Flag.Height}");
Send a telegram
using dotNS;
using dotNS.Classes;
<...>
// Create an API wrapper
DotNS api = new DotNS();
// Prepare a message
string clientId = "Your client ID";
string tgID = "ID of the telegram";
string secretKey = "Key to send the telegram";
string recipient = "nation";
// Send telegram
api.SendTelegram(clientId, tgID, secretKey, recipient);
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.5.1 146 1/5/2024
0.5.0 292 1/27/2023
0.4.1 252 1/21/2023
0.4.0 361 10/28/2021
0.3.4 359 7/30/2021
0.3.3 365 6/30/2021
0.3.2 321 6/26/2021
0.3.1 289 6/25/2021
0.3.0 300 6/18/2021
0.2.0 318 6/15/2021