build.rudder.sdk (1.0.1)
Installation
registry=https://hub.rudder.build/api/packages/rudder/npm/npm install build.rudder.sdk@1.0.1"build.rudder.sdk": "1.0.1"About this package
Rudder for C#
The game client of Rudder for Unity (WebGL included) and .NET. It signs a device in and calls the functions of the modules of a project through a typed client generated for that project. It has no dependencies.
Install
-
Unity 6: add the Rudder registry and the package to
Packages/manifest.json. Requests go throughUnityWebRequest.{ "scopedRegistries": [ { "name": "Rudder", "url": "https://hub.rudder.build/api/packages/rudder/npm/", "scopes": ["build.rudder"] } ], "dependencies": { "build.rudder.sdk": "1.0.0" } } -
.NET: reference
Rudder.Sdk.csprojof the package (.NET Standard 2.1). Requests go throughHttpClient.
Generate the client
In a repository where rudder project use chose the project:
rudder client generate --lang csharp --output Assets/Rudder/Rudder.g.cs \
--game-address https://api.rudder.build [--environment staging|prod] [--namespace Game]
The client follows the newest release of the environment, staging by default: the class
Rudder with a property per module, a method per function a game client may call (functions
marked server are left out), and the types of their arguments and results in the namespace
<namespace>.<Module>. Generate it again when a release changes them.
Use
using Game;
using Game.Stores;
var rudder = await Rudder.SignInDevice(sdkKey, deviceId);
var stores = await rudder.Stores.Stores();
await rudder.Stores.Buy(new BuyArguments { Offer = "pumpkin-pack" });
var balances = await rudder.Session.Wallet();
SignInDevice takes Options: Address (required when the client was generated without
--game-address), Attempts, Transport and the Nickname, Avatar, Language and Region of
the player.
- Errors. A refused call throws
RudderExceptionwith theCode,Messageand HTTPStatusof the answer: a code the module declares (such aslimit_reached) or one of Rudder (such asplayer_banned,idempotency_key_reusedorrate_limited). - Retries. A request that got no answer or the answer
try_againis sent again after theRetry-Afterit gave or a short backoff, at mostAttemptstimes (5). A mutation keeps itsIdempotency-Keyacross them, so it runs once. Pass your own key, such as the id of a purchase, to keep that promise across restarts:new MutationOptions { IdempotencyKey = ... }. - Session. The access token stays in memory; when it expires the device signs in again.
- Types. An optional field is
nullwhen missing. A value of an enum is astring, with its values as constants of a class of the same name. A field named like its type gets the suffixValue. JSON is read and written without reflection, so the client runs under IL2CPP. - Transport.
ITransportsends the requests and waits between attempts; replace it to route or observe them.