@@ -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>
0 commit comments