Skip to content

Commit dc63527

Browse files
committed
Update package versions and refactor BlinkClient.cs
Updated `System.Net.Http.Json` to `8.0.1` and `System.Text.Json` to `8.0.5` in `Blink.csproj`. Refactored `BlinkClient.cs`: - Removed `_userAgent` field and `_baseUrl` constant. - Defined `baseUrl` within method scope. - Modified `CreateHttpClient` to: - Remove exception for null/whitespace `token`. - Add `TOKEN-AUTH` header only if `token` is not null/whitespace.
1 parent 7eb98e9 commit dc63527

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

Sources/Blink/Blink.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
3131
<None Include="package-icon.png" Pack="true" PackagePath="\" />
3232
<None Include="..\..\LICENSE.md" Pack="true" PackagePath="LICENSE.md" />
33-
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
34-
<PackageReference Include="System.Text.Json" Version="8.0.4" />
33+
<PackageReference Include="System.Net.Http.Json" Version="8.0.1" />
34+
<PackageReference Include="System.Text.Json" Version="8.0.5" />
3535
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
3636
</ItemGroup>
3737

Sources/Blink/BlinkClient.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ public class BlinkClient
2828
private HttpClient? _http;
2929
private readonly string _email;
3030
private readonly string _password;
31-
private readonly string _userAgent;
32-
private const string _baseUrl = "https://rest-prod.immedia-semi.com";
3331

3432
/// <summary>
3533
/// Create Blink client with email and password.
@@ -98,6 +96,8 @@ public async Task<BlinkAuthorizationData> AuthorizeAsync()
9896
email = _email,
9997
password = _password
10098
};
99+
string baseUrl = "https://rest-prod.immedia-semi.com";
100+
_http = CreateHttpClient(baseUrl, string.Empty);
101101
var response = await _http.PostAsJsonAsync("/api/v5/account/login", body);
102102
if (!response.IsSuccessStatusCode)
103103
{
@@ -107,7 +107,7 @@ public async Task<BlinkAuthorizationData> AuthorizeAsync()
107107
?? throw new BlinkClientException("Failed to authorize - no content");
108108
if (!string.IsNullOrWhiteSpace(loginResult.Account.Tier) && !string.IsNullOrWhiteSpace(loginResult.Auth.Token))
109109
{
110-
string baseUrl = $"https://rest-{loginResult.Account.Tier}.immedia-semi.com";
110+
baseUrl = $"https://rest-{loginResult.Account.Tier}.immedia-semi.com";
111111
_http = CreateHttpClient(baseUrl, loginResult.Auth.Token);
112112
}
113113
_accountId = loginResult.Account.AccountId;
@@ -123,10 +123,6 @@ public async Task<BlinkAuthorizationData> AuthorizeAsync()
123123

124124
private HttpClient CreateHttpClient(string baseUrl, string token)
125125
{
126-
if (string.IsNullOrWhiteSpace(token))
127-
{
128-
throw new BlinkClientException("Token is required to authorize");
129-
}
130126
if (string.IsNullOrWhiteSpace(baseUrl))
131127
{
132128
throw new BlinkClientException("Base URL is required to authorize");
@@ -135,13 +131,16 @@ private HttpClient CreateHttpClient(string baseUrl, string token)
135131
{
136132
BaseAddress = new Uri(baseUrl)
137133
};
138-
_http.DefaultRequestHeaders.TryAddWithoutValidation("TOKEN-AUTH", token);
139134
string appBuild = "ANDROID_28746173";
140135
string userAgent = "35.1" + appBuild;
141136
_http.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", userAgent);
142137
_http.DefaultRequestHeaders.TryAddWithoutValidation("APP-BUILD", appBuild);
143138
_http.DefaultRequestHeaders.TryAddWithoutValidation("LOCALE", "en_US");
144139
_http.DefaultRequestHeaders.TryAddWithoutValidation("X-Blink-Time-Zone", "America/Los_Angeles");
140+
if (!string.IsNullOrWhiteSpace(token))
141+
{
142+
_http.DefaultRequestHeaders.TryAddWithoutValidation("TOKEN-AUTH", token);
143+
}
145144
return _http;
146145
}
147146

0 commit comments

Comments
 (0)