EzvizClient constructor
EzvizClient({})
Creates an EzvizClient with flexible authentication options.
Either provide:
accessTokenfor direct authentication, orappKeyandappSecretto authenticate via API
If accessToken is provided, it will be used directly.
If appKey and appSecret are provided, they will be used to obtain an access token.
region sets the EZVIZ API region (e.g., EzvizRegion.europe)
baseUrl allows customizing the EZVIZ API endpoint. Defaults to India region.
If both region and baseUrl are provided, baseUrl takes precedence.
Implementation
EzvizClient({
this.appKey,
this.appSecret,
String? accessToken,
String? areaDomain,
EzvizRegion? region,
String? baseUrl,
http.Client? httpClient,
}) : baseUrl = baseUrl ??
(region != null ? EzvizConstants.getRegionUrl(region) ?? EzvizConstants.baseUrl : EzvizConstants.baseUrl),
_http = httpClient ?? http.Client(),
_hasProvidedAccessToken = accessToken != null {
// Validate that we have either accessToken or both appKey+appSecret
if (accessToken == null && (appKey == null || appSecret == null)) {
throw ArgumentError(
'Either provide accessToken directly, or both appKey and appSecret for API authentication',
);
}
// If accessToken is provided, use it directly
if (accessToken != null) {
_accessToken = accessToken;
_areaDomain = areaDomain;
// For provided tokens, we don't know the expiry time, so we'll handle auth errors when they occur
}
}