CocApi 0.20.0-alpha

This is a Clash of Clans library that will return responses from developer.clashofclans.com

https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json
Use this feed to get Reflection while this is in prerelease.

This is a prerelease version of CocApi.
There is a newer prerelease version of this package available.
See the version list below for details.
This package is considered a SemVer 2.0.0 package as it has a package dependency on SemVer 2.0.0 package(s).
This package will only be available to download with SemVer 2.0.0 compatible NuGet clients, such as Visual Studio 2017 (version 15.3) and above or NuGet client 4.3.0 and above. Read more
Install-Package CocApi -Version 0.20.0-alpha
dotnet add package CocApi --version 0.20.0-alpha
<PackageReference Include="CocApi" Version="0.20.0-alpha" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CocApi --version 0.20.0-alpha
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

CocApiLibrary

This .NET Standard 2.1 library will provide responses from developer.clashofclans.com.

CocApiConsoleTest

The test program shows you how to set up the library.
The library can grab SC API objects on command.
It can also automatically keep these objects up to date by polling the API.
When an object changes, it will fire an event which you can subscribe to.
You may optionally provide an ILogger to observe what the library is doing.
The test program will output the following:<br/><br/>
Test Program console output
If you choose to keep the objects up to date, the library will constantly write to the ILogger.
Of course, the ILogger is in your program, so you can choose what to print.

CocApi

The CocApi class is the entry point to this library.
You likely want this class to be a singleton that lives for the life of your application.
This class is disposable, don't forget to call Dispose when you end your applicaiton.
This program has the potential to consume a lot of memory.

CocApiConfiguration

Use this to configure the CocApi class.
This class can control how often your SC API token is used.
You can also control how long a downloaded object is considered good for.
The default values are very conservative just in case the SC API key you provide is used for something else.
This is to avoid rate limiting your key.
If your key is only used in CocApi, you can make the time spans much shorter.
The API allows about 10 requests a second per key.

WebResponse

This is an internal static class.
If it prints to the ILogger, that indicates that the library is polling the API.

UpdateService

This is an internal class.
If it prints to the ILogger, it is updating an object. If the object being updated is not expired, it will not ask the WebResponse class to poll the API.

ICurrentWarAPIModel

This interface is implemented by CurrentWarAPIModel and LeagueWarAPIModel.
The only difference is LeagueWarAPIModel has a WarTag property, and the WarType enum will be SCCWL.
When CocApi returns an ICurrentWarAPIModel, you can cast it to the appropriate type when necessary.
LeagueWarAPIModel also inherits from CurrentWarAPIModel. If you have to cast, ensure you start with LeagueWarAPIModel.

IWar

This empty interface is implemented by ICurrentWarAPIModel and the NotInWar model. The library will never return an ICurrentWarAPIModel with state = notInWar.

ILeagueGroup

This empty interface is implemented by LeagueGroupApiModel and LeagueGroupNotFound. Clans that are not in CWL war will return a LeagueGroupNotFound.

Extensions

The static Extensions class contains some things that may be useful, especially for Discord bots.
DiscordSafe will strip Discord markup characters from a given string.
LeftToRight will force characters to display left to right. This is especially helpful while making tables.
ToDateTime will convert SC API date time objects to C# DateTime, though the library already handles this when downloading your object.

Outages

When the API goes down, the IsAvailableChanged event will fire.
CocApi will not stop trying to update expired objects unless you tell it to in this event.
When an outage is detected, it will poll the API every five seconds to see if the server is back up.
If an error occurs while watching clans, a CrashDetected event will fire.
You may handle it by StartWatchingClans, or any other means you wish.

Issues

If you have problems finding one of the required nuget packages, add https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json as a source.</br></br>
If the objects update too slow or two fast, modify the properties of the CocApiConfiguration. TokenObject rate limits are bad. TokenObject preemptive rate limits are okay, though it does indicate the library is updating as fast as the TokenTimeOut allows.

Entity Framework

These classes should translate to working tables with little or no effort. Paste the below code into your OnModelCreating.

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    //composite keys
    modelBuilder.Entity<ClanLabelAPIModel>().HasKey(p => new { p.Id,  p.ClanTag });
    modelBuilder.Entity<AchievementAPIModel>().HasKey(p => new { p.Name, p.VillageTag });
    modelBuilder.Entity<SpellAPIModel>().HasKey(p => new { p.Name, p.VillageTag });
    modelBuilder.Entity<TroopAPIModel>().HasKey(p => new { p.Name, p.VillageTag, p.Village });
    modelBuilder.Entity<LegendLeagueResultAPIModel>().HasKey(p => new { p.Id, p.VillageTag, p.Village });
    modelBuilder.Entity<VillageLabelAPIModel>().HasKey(p => new { p.Id, p.VillageTag });
    modelBuilder.Entity<AttackAPIModel>().HasKey(p => new { p.WarId, p.Order });

    //define one-to-zero(or one) relationship between villages and legends league
    modelBuilder.Entity<VillageAPIModel>()
                .HasOne(p => p.LegendStatistics)
                .WithOne(p => p!.Village!)
                .HasForeignKey<LegendLeagueStatisticsAPIModel>(p => p.VillageTag)
                .OnDelete(DeleteBehavior.Restrict);

    //define one-to-one relationship between current war and flags
    modelBuilder.Entity<CurrentWarAPIModel>()
        .HasOne(p => p.Flags)
        .WithOne(p => p.CurrentWarAPIModel)
        .HasForeignKey<CurrentWarFlagsModel>(p => p.WarId);
}

Disclaimer

This content is not affiliated with, endorsed, sponsored, or specifically approved by Supercell and Supercell is not responsible for it. For more information see Supercell's Fan Content Policy.

CocApiLibrary

This .NET Standard 2.1 library will provide responses from developer.clashofclans.com.

CocApiConsoleTest

The test program shows you how to set up the library.
The library can grab SC API objects on command.
It can also automatically keep these objects up to date by polling the API.
When an object changes, it will fire an event which you can subscribe to.
You may optionally provide an ILogger to observe what the library is doing.
The test program will output the following:<br/><br/>
Test Program console output
If you choose to keep the objects up to date, the library will constantly write to the ILogger.
Of course, the ILogger is in your program, so you can choose what to print.

CocApi

The CocApi class is the entry point to this library.
You likely want this class to be a singleton that lives for the life of your application.
This class is disposable, don't forget to call Dispose when you end your applicaiton.
This program has the potential to consume a lot of memory.

CocApiConfiguration

Use this to configure the CocApi class.
This class can control how often your SC API token is used.
You can also control how long a downloaded object is considered good for.
The default values are very conservative just in case the SC API key you provide is used for something else.
This is to avoid rate limiting your key.
If your key is only used in CocApi, you can make the time spans much shorter.
The API allows about 10 requests a second per key.

WebResponse

This is an internal static class.
If it prints to the ILogger, that indicates that the library is polling the API.

UpdateService

This is an internal class.
If it prints to the ILogger, it is updating an object. If the object being updated is not expired, it will not ask the WebResponse class to poll the API.

ICurrentWarAPIModel

This interface is implemented by CurrentWarAPIModel and LeagueWarAPIModel.
The only difference is LeagueWarAPIModel has a WarTag property, and the WarType enum will be SCCWL.
When CocApi returns an ICurrentWarAPIModel, you can cast it to the appropriate type when necessary.
LeagueWarAPIModel also inherits from CurrentWarAPIModel. If you have to cast, ensure you start with LeagueWarAPIModel.

IWar

This empty interface is implemented by ICurrentWarAPIModel and the NotInWar model. The library will never return an ICurrentWarAPIModel with state = notInWar.

ILeagueGroup

This empty interface is implemented by LeagueGroupApiModel and LeagueGroupNotFound. Clans that are not in CWL war will return a LeagueGroupNotFound.

Extensions

The static Extensions class contains some things that may be useful, especially for Discord bots.
DiscordSafe will strip Discord markup characters from a given string.
LeftToRight will force characters to display left to right. This is especially helpful while making tables.
ToDateTime will convert SC API date time objects to C# DateTime, though the library already handles this when downloading your object.

Outages

When the API goes down, the IsAvailableChanged event will fire.
CocApi will not stop trying to update expired objects unless you tell it to in this event.
When an outage is detected, it will poll the API every five seconds to see if the server is back up.
If an error occurs while watching clans, a CrashDetected event will fire.
You may handle it by StartWatchingClans, or any other means you wish.

Issues

If you have problems finding one of the required nuget packages, add https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json as a source.</br></br>
If the objects update too slow or two fast, modify the properties of the CocApiConfiguration. TokenObject rate limits are bad. TokenObject preemptive rate limits are okay, though it does indicate the library is updating as fast as the TokenTimeOut allows.

Entity Framework

These classes should translate to working tables with little or no effort. Paste the below code into your OnModelCreating.

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    //composite keys
    modelBuilder.Entity<ClanLabelAPIModel>().HasKey(p => new { p.Id,  p.ClanTag });
    modelBuilder.Entity<AchievementAPIModel>().HasKey(p => new { p.Name, p.VillageTag });
    modelBuilder.Entity<SpellAPIModel>().HasKey(p => new { p.Name, p.VillageTag });
    modelBuilder.Entity<TroopAPIModel>().HasKey(p => new { p.Name, p.VillageTag, p.Village });
    modelBuilder.Entity<LegendLeagueResultAPIModel>().HasKey(p => new { p.Id, p.VillageTag, p.Village });
    modelBuilder.Entity<VillageLabelAPIModel>().HasKey(p => new { p.Id, p.VillageTag });
    modelBuilder.Entity<AttackAPIModel>().HasKey(p => new { p.WarId, p.Order });

    //define one-to-zero(or one) relationship between villages and legends league
    modelBuilder.Entity<VillageAPIModel>()
                .HasOne(p => p.LegendStatistics)
                .WithOne(p => p!.Village!)
                .HasForeignKey<LegendLeagueStatisticsAPIModel>(p => p.VillageTag)
                .OnDelete(DeleteBehavior.Restrict);

    //define one-to-one relationship between current war and flags
    modelBuilder.Entity<CurrentWarAPIModel>()
        .HasOne(p => p.Flags)
        .WithOne(p => p.CurrentWarAPIModel)
        .HasForeignKey<CurrentWarFlagsModel>(p => p.WarId);
}

Disclaimer

This content is not affiliated with, endorsed, sponsored, or specifically approved by Supercell and Supercell is not responsible for it. For more information see Supercell's Fan Content Policy.

Release Notes

Initial Release

https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json
Use this feed to get Reflection while this is in prerelease.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
0.23.0-alpha 58 1/7/2020
0.22.0-alpha 30 1/5/2020
0.21.0-alpha 44 12/15/2019
0.20.0-alpha 32 11/27/2019
0.19.0-alpha 33 11/24/2019
0.18.0-alpha 33 11/23/2019
0.17.0-alpha 31 11/11/2019