Class AirthingsClient
- Namespace
- Tudormobile.Airthings
- Assembly
- Tudormobile.Airthings.dll
Provides a client for interacting with the Airthings Consumer API.
public sealed class AirthingsClient : IAirthingsClient, IDisposable
- Inheritance
-
AirthingsClient
- Implements
- Inherited Members
Remarks
Automatically refreshes OAuth2 access tokens when requests receive unauthorized responses. Token refresh operations are serialized via a semaphore, but no double-check guard is applied. Under concurrent load, two callers may each trigger a sequential refresh. This is acceptable when an output cache limits upstream calls to a low frequency (e.g., once per 30–60 minutes).
Design constraints: This client is bound to a single ClientId / ClientSecret
pair supplied at construction time. It does not support per-request credentials and is therefore
suited only for single-account, single-user deployments. Pagination of multi-page API responses
is not implemented; callers that expect large result sets must account for this limitation.
Constructors
AirthingsClient(HttpClient, string, string, string)
Initializes a new instance of the AirthingsClient class.
public AirthingsClient(HttpClient httpClient, string clientId, string clientSecret, string accessToken = "")
Parameters
httpClientHttpClientThe HTTP client used for API requests. Callers are responsible to dispose of this instance.
clientIdstringThe client ID for authentication.
clientSecretstringThe client secret for authentication.
accessTokenstringThe optional access token. Defaults to an empty string.
Remarks
Callers can provide an optional access token from previous sessions, and also read and store refreshed tokens after successful API calls. Callers are responsible to managing the lifecycle of the provided HttpClient instance, including disposal. The client will not dispose of the provided HttpClient instance.
Properties
AccessToken
Gets the access token, which was possibly refreshed.
public string AccessToken { get; }
Property Value
Methods
Dispose()
public void Dispose()
ListAccounts(CancellationToken)
Lists all accounts accessible with the current credentials.
public Task<AccountsResponse> ListAccounts(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<AccountsResponse>
A task representing the asynchronous operation. The task result contains the accounts response with a list of accounts.
ListDevices(string, CancellationToken)
Lists all devices associated with the specified account.
public Task<DevicesResponse> ListDevices(string accountId, CancellationToken cancellationToken = default)
Parameters
accountIdstringThe unique identifier of the account.
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<DevicesResponse>
A task representing the asynchronous operation. The task result contains the devices response with a list of devices.
ReadSensors(string, IEnumerable<string>, UnitsType, CancellationToken)
Reads sensor data from the specified devices.
public Task<DevicesSamplesResponse> ReadSensors(string accountId, IEnumerable<string> serialNumbers, UnitsType unitsType = UnitsType.Metric, CancellationToken cancellationToken = default)
Parameters
accountIdstringThe unique identifier of the account.
serialNumbersIEnumerable<string>The serial numbers of the devices to read sensor data from.
unitsTypeUnitsTypeThe units type for the sensor data (e.g., Metric or Imperial).
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<DevicesSamplesResponse>
A task representing the asynchronous operation. The task result contains the sensors response with sensor data.