NATION

PASSWORD

DotNS - NationStates API for C#

Bug reports, general help, ideas for improvements, and questions about how things are meant to work.
User avatar
IKTeam
Lobbyist
 
Posts: 20
Founded: Apr 26, 2020
Ex-Nation

DotNS - NationStates API for C#

Postby IKTeam » Sat May 08, 2021 7:29 am

This is an official topic for DotNS, a NationStates API wrapper/library for C#.

It allows both high and low level API access.

Features so far:
    - Actively developed with bug fixes and new features being added
    - Simple and readable code that is easy to work with
    - High level API access to most of shards, basic region and nation information, addressing issues
    - Access to all private and public shards
    - Low API access with a ton of different utilities to make your API interaction simpler
    - Verification API
    - Custom UserAgent set
    - Enumerables for shards, authority in regions
    - Basic Telegram API support
    - Get information about cards using Trading Cards API
    - Get flags of cards/nations/regions

Link: GitHub Repository (MIT)

Code examples:
High level access
Code: Select all
// 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}");

Low level access
Code: Select all
// This will be used for GET request parameters
NameValueCollection nvc = new NameValueCollection();
nvc.Add("nation", "ikteam");
nvc.Add("q", "leader");
var resp = Utilities.API(nvc); // You can also define pass (null by default) and pin (null by default) like Utilities.API(nvc, pass, PIN);
// Use StrResp to convert the API response to XML string
string xml = Utilities.StrResp(resp);
 // Use Parse to convert the XML string to NodeList
XmlNodeList nodelist = Utilities.Parse(xml); // By default, it takes nodes by path `/NATION/*`. Use second argument to define the path, like Utilities.Parse(xml, "*");
// Use FindProperty to find a property or attribute by name. Returns first occurance.
string leaderName = nodelist.FindProperty("leader");
Console.WriteLine($"Leader is {leaderName}"); // "Leader is Overlord"

(Find more examples at GitHub page)

More high-level wrappers for shards are coming soon!
Last edited by IKTeam on Fri Jun 18, 2021 7:13 am, edited 1 time in total.

User avatar
IKTeam
Lobbyist
 
Posts: 20
Founded: Apr 26, 2020
Ex-Nation

Postby IKTeam » Tue Jun 15, 2021 8:26 am

Version 0.2 release!

Following recent NationStates changes, a new update has recently rolled out.

New features include:
- GetFlag() to get a flag of any nation or region,
- Verification API
- Proper way to set UserAgent
- Easy access to daily dumps of regions and nations
- Bugfixes
- You can now access statistics of specified census
- Added new census (Patriotism and Food quality)
- You can now find us on NuGet!
- The package is now .NET Standard, we no longer require .NET Core to be installed!

We are looking for new feature requests and suggestions. Feel free to fork and pull request! :)

User avatar
Bormiar
Ambassador
 
Posts: 1563
Founded: Mar 25, 2019
Inoffensive Centrist Democracy

Postby Bormiar » Tue Jun 15, 2021 8:53 am

I might have to switch to C# for NS coding. This library seems more practically designed to me than pynationstates or sans.

User avatar
IKTeam
Lobbyist
 
Posts: 20
Founded: Apr 26, 2020
Ex-Nation

Postby IKTeam » Fri Jun 18, 2021 7:12 am

Version 0.3 release!


New features!

    * Added GetCard() to get information of a card
    * Added GetDeck() to get all cards of a nation
    * Added basic Telegram API support (requires some testing)
    * Dump support extended to Trading Cards
    * Bugfixes
    * GetFlag() method replaced with Flag property

Feel free to telegram/PM me your suggestions or feature requests! :)
I hope updates log doesn't make it too spammy


Return to Technical

Who is online

Users browsing this forum: 9003, Alinek, Almighty Biden, Armbruster, Bormiar, Cartialiag, Chenzorian Viatrok, Da Netherlands, Dazchan, DeltaSource, Geopolity, Grays Harbor, Ioudaia, Kakastania, Khantin, Shirahime, Tamocordia, The Last World, The Turnip Path, The United British Kingdom, Tupoina

Advertisement

Remove ads