Skip to content

A C# Wrapper for the Torn City API based on TornCityAPISharp by CarlHalstead.

License

Notifications You must be signed in to change notification settings

YuumiPie/TornSharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TornSharp

NuGet version

A C# Wrapper for the Torn City API based on the now depreciated wrapper by CarlHalstead.

Features

  • Asynchronous Calls
  • Support for most endpoints
  • Logging unknown Json properties

Installation

Install RiotSharp through NuGet:

PM> Install-Package TornSharp   

Usage

You first have to create API key here.

Entry point for the API:

var api = new TornApiWrapper("YOUR_API_KEY");

Specifying rate limit (unspecified defaults to unlimited):

var api = new TornApiWrapper("YOUR_API_KEY", yourRateLimit);

Disabling unknown Json logging:

var api = new TornApiWrapper("YOUR_API_KEY", yourRateLimit, false);

To get basic data of a Torn User:

try
{
  //example: Chedburn [1]
  var user = api.GetFromUserApi<UserBasic>("1").Result;
  var name = user.Name;
  var level = user.Level;
  var playerId = user.PlayerId;
}
catch (Exception e)
{
  // Handle the exception
}

Note: calls require matching the method to the associated endpoint category
Ex. For torn calls you must do:

//example: Getting Torn education
var education = api.GetFromTornApi<TornEducation>().Result;

instead of

//will not work
var education = api.GetFromUserApi<TornEducation>().Result;

Support for combined api calls are possible

//gets two endpoint objects in one call
List<object> market = api.GetFromMarketApi<MarketBazaar, MarketItemMarket>().Result;
//type muse be casted
MarketBazaar bazaar = (MarketBazaar)market[0];
MarketItemMarket ItemMarket = (MarketItemMarket)market[1];

Note: like above, combined calls must be part of the same endpoints and some combinations may not work

These are the current endpoint categories available:

  • User
  • Property
  • Faction
  • Company
  • Market
  • Torn
  • Key

More details on endpoints can be found on the Unofficial Torn Api.

Notes

  • Some endpoints/types are incomplete due to unknown variable types/enum types
  • Incorrect data or errors may occur on integer types (int vs long)

These problems are mostly due to incomplete/unknown data from the unofficial documentation.

If any of these problems above occur you can open an issue here.
(Please report unknown/incomplete data to the Unofficial Torn Api as well)!

Contributing

Contributions can be made by opening a pull request here.

Dependencies

  • System.Text.Json
  • System.Text.Json.EnumExtensions

Licence

This wrapper is under the Apache 2.0 License.

Credits

This is heavily based on TornCityApiSharp by CarlHalstead.
All the Json models are based on the Unofficial Torn Api.

About

A C# Wrapper for the Torn City API based on TornCityAPISharp by CarlHalstead.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages