Skip to content

Commit dd1b4dc

Browse files
committed
Update to .NET 9.0 and enhance video retrieval methods
- Target framework updated to .NET 9.0 in `Blink.ConsoleTest.csproj`. - Replaced `GetVideosAsync` with `GetVideosFromSingleModuleAsync` in `Program.cs`. - Changed authentication key from "username" to "email" in `secrets.json`. - Updated `System.Net.Http.Json` and `System.Text.Json` packages to version 9.0.8 in `Blink.csproj`. - Enhanced XML documentation for `UniqueId` and `AuthorizeAsync` methods in `BlinkClient.cs`. - Renamed `GetVideoAsync` to `GetVideoBytesAsync` with updated documentation. - Introduced `GetVideosFromModuleAsync` requiring a `SyncModule` parameter. - Added new method `GetVideosFromSingleModuleAsync` with exception handling for multiple modules. - Improved documentation across various methods for better clarity and usability.
1 parent 2f94623 commit dd1b4dc

File tree

6 files changed

+62
-27
lines changed

6 files changed

+62
-27
lines changed

Sources/Blink.ConsoleTest/Blink.ConsoleTest.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
5+
<TargetFramework>net9.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>

Sources/Blink.ConsoleTest/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ private static async Task Start()
2323
Console.WriteLine("Auth data: " + authData.ToJson());
2424
}
2525

26-
var videos = await client.GetVideosAsync();
26+
var videos = await client.GetVideosFromSingleModuleAsync();
2727
int count = videos.Count();
2828

2929
Console.WriteLine("Videos count: " + count);
3030

3131
foreach (var video in videos)
3232
{
33-
byte[] bytes = await client.GetVideoAsync(video);
33+
byte[] bytes = await client.GetVideoBytesAsync(video);
3434
Console.WriteLine($"Video {video.Id} bytes: {bytes.Length}");
3535
// await client.DeleteVideoAsync(video);
3636
}

Sources/Blink.ConsoleTest/secrets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"username": "[email protected]",
2+
"email": "[email protected]",
33
"password": "aaaaA6E2242RIglFonsbjDgl321jrO6c1!",
44
"token": "gwfws_Xxggx1eh-A1N-Iiw",
55
"tier": "u018",

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.1" />
34-
<PackageReference Include="System.Text.Json" Version="8.0.5" />
33+
<PackageReference Include="System.Net.Http.Json" Version="9.0.8" />
34+
<PackageReference Include="System.Text.Json" Version="9.0.8" />
3535
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
3636
</ItemGroup>
3737

Sources/Blink/BlinkClient.cs

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Blink
1616
public class BlinkClient : IBlinkClient
1717
{
1818
/// <summary>
19-
/// Unique ID to avoid reauthorization by pin code
19+
/// Unique ID to avoid reauthorization by pin code, for example: "a1b2c3d4-e5f6-7g8h-9i0j-k1l2m3n4o5p6" (<see cref="Guid.NewGuid()"/>)
2020
/// </summary>
2121
public string UniqueId { get; set; } = Guid.NewGuid().ToString();
2222

@@ -35,6 +35,9 @@ public class BlinkClient : IBlinkClient
3535
/// <summary>
3636
/// Authorize with email and password provided in constructor.
3737
/// </summary>
38+
/// <param name="email">Email address</param>
39+
/// <param name="password">Password</param>
40+
/// <param name="reauth">Set to true if you already authorized with pin code and want to reauthorize. This is from Blink app behavior.</param>
3841
/// <returns><see cref="LoginResult"/> object with authorization data</returns>
3942
/// <exception cref="BlinkClientException">Thrown when email or password is not provided in constructor</exception>
4043
/// <exception cref="BlinkClientException">Thrown when authorization fails</exception>
@@ -43,14 +46,14 @@ public async Task<LoginResult> AuthorizeAsync(string email, string password, boo
4346
{
4447
if (string.IsNullOrWhiteSpace(email))
4548
{
46-
throw new BlinkClientException("Email is required to authorize");
49+
throw new BlinkClientException("Email is required to authorize but not provided");
4750
}
4851
if (string.IsNullOrWhiteSpace(password))
4952
{
50-
throw new BlinkClientException("Password is required to authorize");
53+
throw new BlinkClientException("Password is required to authorize but not provided");
5154
}
5255

53-
string clientName = Assembly.GetEntryAssembly()!.GetName().Name + "_v" + Assembly.GetEntryAssembly()!.GetName().Version;
56+
string clientName = Assembly.GetEntryAssembly().GetName().Name + "_v" + Assembly.GetEntryAssembly().GetName().Version;
5457
var body = new
5558
{
5659
unique_id = UniqueId,
@@ -59,6 +62,7 @@ public async Task<LoginResult> AuthorizeAsync(string email, string password, boo
5962
client_name = clientName,
6063
reauth = reauth ? "true" : "false",
6164

65+
// Disabled optional parameters - it works without them for now
6266
//app_version = "",
6367
//client_type = "",
6468
//device_identifier = "Amazon ",
@@ -123,7 +127,7 @@ private HttpClient CreateHttpClient(string baseUrl, string? token = "")
123127
}
124128

125129
/// <summary>
126-
/// Verify pin code from text message received after authorization.
130+
/// Verify pin code from text message received after authorization. You'll receive the code to your phone number.
127131
/// </summary>
128132
/// <param name="code">Pin code from text message</param>
129133
/// <exception cref="BlinkClientException">Thrown when not authorized</exception>
@@ -175,20 +179,13 @@ public async Task<Dashboard> GetDashboardAsync()
175179
}
176180

177181
/// <summary>
178-
/// Get videos from Blink camera.
182+
/// Get videos from specified module. Get modules from <see cref="GetDashboardAsync"/> method - <see cref="Dashboard.SyncModules"/>.
179183
/// </summary>
180184
/// <returns>Collection of <see cref="BlinkVideoInfo"/> objects with video data</returns>
181185
/// <exception cref="BlinkClientException">Thrown when not authorized</exception>
182186
/// <exception cref="BlinkClientException">Thrown when failed to get videos</exception>
183-
public async Task<IEnumerable<BlinkVideoInfo>> GetVideosAsync()
187+
public async Task<IEnumerable<BlinkVideoInfo>> GetVideosFromModuleAsync(SyncModule module)
184188
{
185-
if (_accountId == null)
186-
{
187-
throw new BlinkClientException("Not authorized");
188-
}
189-
var dashboard = await GetDashboardAsync();
190-
var module = dashboard.SyncModules.FirstOrDefault()
191-
?? throw new BlinkClientException("No sync modules found");
192189
string url = $"/api/v1/accounts/{_accountId}/networks/{module.NetworkId}/" +
193190
$"sync_modules/{module.Id}/local_storage/manifest/request";
194191
await Task.Delay(GeneralSleepTime); // I don't know why, but their server returns empty response without this delay
@@ -215,13 +212,37 @@ public async Task<IEnumerable<BlinkVideoInfo>> GetVideosAsync()
215212
}
216213

217214
/// <summary>
218-
/// Get video from Blink camera.
215+
/// Get videos from single module (the first one in the dashboard). Throws exception if more than one module found.
216+
/// </summary>
217+
/// <returns>Collection of <see cref="BlinkVideoInfo"/> objects with video data</returns>
218+
/// <exception cref="BlinkClientException">Thrown when not authorized</exception>
219+
/// <exception cref="BlinkClientException">Thrown when failed to get videos</exception>
220+
/// <exception cref="BlinkClientException">Thrown when more than one module found</exception>
221+
public async Task<IEnumerable<BlinkVideoInfo>> GetVideosFromSingleModuleAsync()
222+
{
223+
if (_accountId == null)
224+
{
225+
throw new BlinkClientException("Not authorized");
226+
}
227+
var dashboard = await GetDashboardAsync();
228+
if (dashboard.SyncModules.Length > 1)
229+
{
230+
throw new BlinkClientException("More than one sync module found. Use GetVideosAsync() instead.");
231+
}
232+
var module = dashboard.SyncModules.SingleOrDefault()
233+
?? throw new BlinkClientException("No sync modules found");
234+
return await GetVideosFromModuleAsync(module);
235+
}
236+
237+
/// <summary>
238+
/// Get video file as byte array.
219239
/// </summary>
220240
/// <param name="video"><see cref="BlinkVideoInfo"/> object with video data</param>
221241
/// <param name="tryCount">Number of tries to get video</param>
222242
/// <returns>Video as byte array</returns>
223243
/// <exception cref="BlinkClientException">Thrown when not authorized</exception>
224-
public async Task<byte[]> GetVideoAsync(BlinkVideoInfo video, int tryCount = 3)
244+
/// <exception cref="BlinkClientException">Thrown when video data is not valid. Please create an issue if you see this error.</exception>
245+
public async Task<byte[]> GetVideoBytesAsync(BlinkVideoInfo video, int tryCount = 3)
225246
{
226247
if (_accountId == null)
227248
{
@@ -250,7 +271,7 @@ public async Task<byte[]> GetVideoAsync(BlinkVideoInfo video, int tryCount = 3)
250271
return await response.Content.ReadAsByteArrayAsync();
251272
}
252273
}
253-
throw new BlinkClientException($"Failed to get video {video.Id}, contentType {contentType} - {response?.ReasonPhrase ?? "Unknown Error"}");
274+
throw new BlinkClientException($"Failed to get video {video.Id}, contentType {contentType} - {response?.ReasonPhrase ?? "Unknown Error"}. Please create an issue if you see this error.");
254275
}
255276

256277
/// <summary>

Sources/Blink/IBlinkClient.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public interface IBlinkClient
2020
/// <summary>
2121
/// Authorize with email and password provided in constructor.
2222
/// </summary>
23+
/// <param name="email">Email address</param>
24+
/// <param name="password">Password</param>
25+
/// <param name="reauth">Set to true if you already authorized with pin code and want to reauthorize. This is from Blink app behavior.</param>
2326
/// <returns><see cref="LoginResult"/> object with authorization data</returns>
2427
/// <exception cref="BlinkClientException">Thrown when email or password is not provided in constructor</exception>
2528
/// <exception cref="BlinkClientException">Thrown when authorization fails</exception>
@@ -45,13 +48,24 @@ public interface IBlinkClient
4548
/// <param name="video">The video information to retrieve.</param>
4649
/// <param name="tryCount">The number of attempts to retrieve the video. Default is 3.</param>
4750
/// <returns>A task that represents the asynchronous operation. The task result contains the video data as a byte array.</returns>
48-
Task<byte[]> GetVideoAsync(BlinkVideoInfo video, int tryCount = 3);
51+
Task<byte[]> GetVideoBytesAsync(BlinkVideoInfo video, int tryCount = 3);
4952

5053
/// <summary>
51-
/// Retrieves a list of videos asynchronously.
54+
/// Get videos from single module (the first one in the dashboard). Throws exception if more than one module found.
5255
/// </summary>
53-
/// <returns>A task that represents the asynchronous operation. The task result contains an enumerable collection of video information.</returns>
54-
Task<IEnumerable<BlinkVideoInfo>> GetVideosAsync();
56+
/// <returns>Collection of <see cref="BlinkVideoInfo"/> objects with video data</returns>
57+
/// <exception cref="BlinkClientException">Thrown when not authorized</exception>
58+
/// <exception cref="BlinkClientException">Thrown when failed to get videos</exception>
59+
/// <exception cref="BlinkClientException">Thrown when more than one module found</exception>
60+
Task<IEnumerable<BlinkVideoInfo>> GetVideosFromSingleModuleAsync();
61+
62+
/// <summary>
63+
/// Get videos from specified module. Get modules from <see cref="GetDashboardAsync"/> method - <see cref="Dashboard.SyncModules"/>.
64+
/// </summary>
65+
/// <returns>Collection of <see cref="BlinkVideoInfo"/> objects with video data</returns>
66+
/// <exception cref="BlinkClientException">Thrown when not authorized</exception>
67+
/// <exception cref="BlinkClientException">Thrown when failed to get videos</exception>
68+
Task<IEnumerable<BlinkVideoInfo>> GetVideosFromModuleAsync(SyncModule module);
5569

5670
/// <summary>
5771
/// Verifies a specified PIN code asynchronously.

0 commit comments

Comments
 (0)