@@ -30,15 +30,13 @@ public sealed class TodoistClient : IDisposable, IAdvancedTodoistClient
30
30
31
31
private readonly ITodoistRestClient _restClient ;
32
32
33
- private readonly string _token ;
34
-
35
33
/// <summary>
36
34
/// Initializes a new instance of the <see cref="TodoistClient" /> class.
37
35
/// </summary>
38
36
/// <param name="token">The token.</param>
39
37
/// <exception cref="ArgumentException">Value cannot be null or empty - token</exception>
40
38
public TodoistClient ( string token )
41
- : this ( token , new TodoistRestClient ( ) )
39
+ : this ( token , null )
42
40
{
43
41
}
44
42
@@ -49,25 +47,22 @@ public TodoistClient(string token)
49
47
/// <param name="proxy">The proxy.</param>
50
48
/// <exception cref="ArgumentException">Value cannot be null or empty - token</exception>
51
49
public TodoistClient ( string token , IWebProxy proxy )
52
- : this ( token , new TodoistRestClient ( proxy ) )
50
+ : this ( new TodoistRestClient ( token , proxy ) )
53
51
{
52
+ if ( string . IsNullOrEmpty ( token ) )
53
+ {
54
+ throw new ArgumentException ( "Value cannot be null or empty." , nameof ( token ) ) ;
55
+ }
54
56
}
55
57
56
58
/// <summary>
57
59
/// Initializes a new instance of the <see cref="TodoistClient" /> class.
58
60
/// </summary>
59
- /// <param name="token">The token.</param>
60
61
/// <param name="restClient">The rest client.</param>
61
62
/// <exception cref="System.ArgumentException">Value cannot be null or empty - token</exception>
62
- public TodoistClient ( string token , ITodoistRestClient restClient )
63
+ public TodoistClient ( ITodoistRestClient restClient )
63
64
{
64
- if ( string . IsNullOrEmpty ( token ) )
65
- {
66
- throw new ArgumentException ( "Value cannot be null or empty." , nameof ( token ) ) ;
67
- }
68
-
69
- _token = token ;
70
- _restClient = restClient ;
65
+ _restClient = restClient ?? throw new ArgumentNullException ( nameof ( restClient ) ) ;
71
66
72
67
Projects = new ProjectsService ( this ) ;
73
68
Templates = new TemplateService ( this ) ;
@@ -86,11 +81,6 @@ public TodoistClient(string token, ITodoistRestClient restClient)
86
81
Sections = new SectionService ( this ) ;
87
82
}
88
83
89
- internal TodoistClient ( ITodoistRestClient restClient )
90
- {
91
- _restClient = restClient ?? throw new ArgumentNullException ( nameof ( restClient ) ) ;
92
- }
93
-
94
84
/// <summary>
95
85
/// Gets the activity service.
96
86
/// </summary>
@@ -378,8 +368,6 @@ private async Task<T> ProcessFormAsync<T>(
378
368
ICollection < KeyValuePair < string , string > > parameters ,
379
369
IEnumerable < ByteArrayContent > files )
380
370
{
381
- TryAddToken ( parameters ) ;
382
-
383
371
var response = await _restClient . PostFormAsync ( resource , parameters , files )
384
372
. ConfigureAwait ( false ) ;
385
373
var responseContent = await ReadResponseAsync ( response )
@@ -399,8 +387,6 @@ private async Task<string> ProcessRawPostAsync(
399
387
string resource ,
400
388
ICollection < KeyValuePair < string , string > > parameters )
401
389
{
402
- TryAddToken ( parameters ) ;
403
-
404
390
var response = await _restClient . PostAsync ( resource , parameters )
405
391
. ConfigureAwait ( false ) ;
406
392
@@ -477,14 +463,6 @@ private void ThrowIfErrors(SyncResponse syncResponse)
477
463
}
478
464
}
479
465
480
- private void TryAddToken ( ICollection < KeyValuePair < string , string > > parameters )
481
- {
482
- if ( ! string . IsNullOrEmpty ( _token ) )
483
- {
484
- parameters . Add ( new KeyValuePair < string , string > ( "token" , _token ) ) ;
485
- }
486
- }
487
-
488
466
private void UpdateTempIds ( Command [ ] commands , IDictionary < Guid , string > tempIdMappings )
489
467
{
490
468
foreach ( var command in commands )
0 commit comments