Dimo.Client
1.1.1
dotnet add package Dimo.Client --version 1.1.1
NuGet\Install-Package Dimo.Client -Version 1.1.1
<PackageReference Include="Dimo.Client" Version="1.1.1" />
<PackageVersion Include="Dimo.Client" Version="1.1.1" />
<PackageReference Include="Dimo.Client" />
paket add Dimo.Client --version 1.1.1
#r "nuget: Dimo.Client, 1.1.1"
#:package Dimo.Client@1.1.1
#addin nuget:?package=Dimo.Client&version=1.1.1
#tool nuget:?package=Dimo.Client&version=1.1.1
DIMO Client for .NET
This is a .NET client for the DIMO API. It is a simple wrapper around the DIMO API, which allows you to interact with the DIMO API using .NET.
Installation
You can install the DIMO Client for .NET using NuGet. To install the DIMO Client for .NET, run the following command in the Package Manager Console:
For Windows Users:
Install-Package Dimo.Client
For Linux/Mac Users:
dotnet add package Dimo.Client
API Documentation
Please visit the DIMO Developer Documentation to learn more about building on DIMO and detailed information on the API.
Developer Registration
As part of the authentication process, you will need to obtain a Developer License via the DIMO Developer Console. To get started with registration, follow the steps below:
- Sign up on the DIMO Developer Console.
- Connect a web3 wallet (if you didn't sign up with one)
- Click on
Create appand fill out the details about your project namespace (external-facing, e.g.Drive2Survive LLC.) and your application name (internal, e.g.app-prod) - Generate an API key and add in your preferred redirect URI
Usage
DIMO Client for .NET is can be used with dependency injection or without it. Below are examples of how to use the DIMO Client for .NET with and without dependency injection.
Without Dependency Injection
You can add each service individually to the DIMO Client. Below is an example of how to add the core services, GraphQL services, and Streamr services to the DIMO Client.
using Dimo.Client;
var dimoClient = new DimoClientBuilder()
.WithEnvironment(DimoEnvironment.Production)
.AddRestServices()
.AddGraphQLServices()
.Build();
Or you can add all services at once.
var dimoClient = new DimoClientBuilder().AddAllServices().Build();
With Dependency Injection
You can also use the DIMO Client for .NET with dependency injection. Below is an example of how to add the DIMO Client to the service collection.
using Dimo.Client;
services.AddDimoClient(options =>
{
options.Environment = DimoEnvironment.Production;
});
NOTE: Using dependency injection grants you access to all individual interfaces that make up the DIMO Client. You can inject them into your services as needed.
Configuration
You can configure the DIMO Client using the DimoClientOptions class. Below is an example of how to configure the DIMO Client.
using Dimo.Client;
services.AddDimoClient(options =>
{
options.Environment = DimoEnvironment.Production;
});
NOTE: by default, the DIMO Client for .NET uses the Production environment. You can change the environment by setting the Environment property of the DimoClientOptions class.
Services
REST Services
The rest services provide the following functionality:
- Authentication
- Device Data
- Device Definitions
- Events
- Token Exchange
- Trips
- Users
- Valuations
- Vehicle Signal Decoding
GraphQL Services
The GraphQL services provide the following functionality:
- Identity API
- Telemetry API
Streamr Services
Coming soon...
Examples
Below are examples of how to use the DIMO Client for .NET.
Authentication
In order to authenticate and access private API data, you will need to authenticate with the DIMO Auth Server. The SDK provides you with all the steps needed in the Wallet-based Authentication Flow in case you need it to build a wallet integration around it. We also offer expedited functions to streamline the multiple calls needed.
Prerequisites for Authentication
- A valid Developer License
- A valid API key
At its core, the API key is the private key to a Web3 wallet. Unlike traditional wallets, which store physical currency, Web3 wallets store digital assets such as Bitcoin, Ethereum, and NFTs. In DIMO's Developer Console, we provision a randomly-generated Web3 wallet for you as the enabled signer of your Developer License, decoupling the operations from wallets that may have assets in them for extra safety.
NOTE: The wallet related to the API key is different from the spender or holder wallet for your DIMO Developer License. This gives users peace of mind that their assets are safely in their spender wallet, and the Developer License NFT is in their holder wallet.
There three ways to authenticate with the DIMO Auth Server based on the steps listed in Wallet-based Authentication Flow:
- Using
GenerateChallengeAsync,SignChallengeAsync, andSubmitChallengeAsyncmethods.
using Dimo.Client;
var dimoClient = new DimoClientBuilder()
.AddAllServices()
.WithEnvironment(DimoEnvironment.Production)
.Build();
var challenge = await dimoClient.AuthenticationService.GenerateChallengeAsync(
clientId: "<your client id>",
domain: "<your domain>",
address: "<your address>",
);
var signedChallenge = await dimoClient.AuthenticationService.SignChallengeAsync(
message: challenge.Challenge,
privateKey: "<your private key>"
);
var auth = await dimoClient.AuthenticationService.SubmitChallengeAsync(
clientId: "<your client id>",
domain: "<your domain>",
state: challenge.State,
signature: signedChallenge
);
- Using the
GetTokenAsyncmethod in theAuthenticationServiceclass.
using Dimo.Client;
var dimoClient = new DimoClientBuilder()
.AddAllServices()
.WithEnvironment(DimoEnvironment.Production)
.Build();
var auth = await dimoClient.AuthenticationService.GetTokenAsync(
clientId: "<your client id>",
domain: "<your domain>",
privateKey: "<your private key>",
address: "<your address>"
);
Console.WriteLine(auth.AccessToken);
- Using the
GetTokenAsyncmethod in theAuthenticationServiceclass with aClientCredentialsobject.
using Dimo.Client;
var dimoClient = new DimoClientBuilder()
.AddAllServices()
.WithEnvironment(DimoEnvironment.Production)
.WithCredentials(new ClientCredentials
{
Address = "<your address>",
ClientId = "<your client id>",
Domain = "<your domain>",
PrivateKey = "<your private key>"
})
.Build();
var auth = await dimoClient.AuthenticationService.GetTokenAsync();
Console.WriteLine(auth.AccessToken);
NOTE:
- The
GetTokenAsyncmethod in theAuthenticationServicewill expect you to setClientCredentialsobjects on build configuration. - When using dependency injection, you can set the
ClientCredentialsobject in theAddDimoClientmethod or use Options Pattern to add it configuring anIOptions<ClientCrendentials>. - If you call this method and neither is set it will throw an exception
Device Data API
using Dimo.Client;
var dimoClient = new DimoClientBuilder()
.AddAllServices()
.WithEnvironment(DimoEnvironment.Production)
.Build();
var tokenId = 123456; // The token id of the device you want to get the data for
var auth = await dimoClient.AuthenticationService.GetTokenAsync(
clientId: "<your client id>",
domain: "<your domain>",
privateKey: "<your private key>",
address: "<your address>"
);
var privilegeToken = await dimoClient.TokenExchangeService.GetPrivilegeTokenAsync(
accessToken: auth.AccessToken,
tokenId: tokenId,
privileges: [
PrivilegeSharing.AllTimeNoLocationData,
PrivilegeSharing.Commands,
PrivilegeSharing.CurrentLocation,
PrivilegeSharing.AllTimeLocation
]); // The privileges you want to get for the device
var vehicleStatus = await dimoClient.DeviceDataService.GetVehicleStatusAsync(tokenId, privilegeToken.Token);
Console.WriteLine(vehicleStatus);
NOTE: for the privileges parameter you can check the DIMO API documentation for the available privileges.
Querying the GraphQL API
The SDK accepts any type of valid custom GraphQL queries, but we've also included a few sample queries to help you understand the DIMO GraphQL APIs.
using Dimo.Client;
var dimoClient = new DimoClientBuilder()
.AddAllServices()
.WithEnvironment(DimoEnvironment.Production)
.Build();
// Code to authenticate with the DIMO Auth Server and get the privilege token
// ...
var query = @"
{
some_valid_GraphQL_query
}
";
var variables = new
{
VariableName = "VariableValue"
};
var result = await dimoClient.TelemetryService.ExecuteQueryAsync<TResponse>(query, variables, privilegeToken.Token);
Console.WriteLine(result);
NOTE: The ExecuteQueryAsync method accepts a generic type TResponse which is the type of the response you expect from the GraphQL query.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. 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 is compatible. 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 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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. |
-
.NETStandard 2.0
- GraphQL.Client (>= 6.1.0)
- GraphQL.Client.Serializer.Newtonsoft (>= 6.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Http (>= 8.0.0)
- Nethereum.Web3 (>= 4.21.3)
- Newtonsoft.Json (>= 13.0.3)
-
net6.0
- GraphQL.Client (>= 6.1.0)
- GraphQL.Client.Serializer.SystemTextJson (>= 6.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Http (>= 8.0.0)
- Nethereum.Web3 (>= 4.21.3)
-
net7.0
- GraphQL.Client (>= 6.1.0)
- GraphQL.Client.Serializer.SystemTextJson (>= 6.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Http (>= 8.0.0)
- Nethereum.Web3 (>= 4.21.3)
-
net8.0
- GraphQL.Client (>= 6.1.0)
- GraphQL.Client.Serializer.SystemTextJson (>= 6.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Http (>= 8.0.0)
- Nethereum.Web3 (>= 4.21.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.