@@ -43,12 +43,8 @@ private ListUsersRequest(
43
43
this . baseUrl = baseUrl ;
44
44
this . httpClient = httpClient ;
45
45
this . RequestParameters = new Dictionary < string , IParameter > ( ) ;
46
- this . SetPageSize ( options . PageSize ?? MaxListUsersResults ) ;
47
- var pageToken = options . PageToken ;
48
- if ( pageToken != null )
49
- {
50
- this . SetPageToken ( pageToken ) ;
51
- }
46
+ this . SetPageSize ( options . PageSize ) ;
47
+ this . SetPageToken ( options . PageToken ) ;
52
48
}
53
49
54
50
public string MethodName => "ListUsers" ;
@@ -61,16 +57,6 @@ private ListUsersRequest(
61
57
62
58
public IClientService Service { get ; }
63
59
64
- public void SetPageSize ( int pageSize )
65
- {
66
- this . AddOrUpdate ( "maxResults" , pageSize . ToString ( ) ) ;
67
- }
68
-
69
- public void SetPageToken ( string pageToken )
70
- {
71
- this . AddOrUpdate ( "nextPageToken" , pageToken ) ;
72
- }
73
-
74
60
public HttpRequestMessage CreateRequest ( bool ? overrideGZipEnabled = null )
75
61
{
76
62
var queryParameters = string . Join ( "&" , this . RequestParameters . Select (
@@ -121,6 +107,47 @@ public ExportedUserRecords Execute()
121
107
return this . ExecuteAsync ( ) . Result ;
122
108
}
123
109
110
+ internal void SetPageSize ( int ? pageSize )
111
+ {
112
+ this . AddOrUpdate ( "maxResults" , CheckPageSize ( pageSize ) . ToString ( ) ) ;
113
+ }
114
+
115
+ internal void SetPageToken ( string pageToken )
116
+ {
117
+ if ( pageToken != null )
118
+ {
119
+ this . AddOrUpdate ( "nextPageToken" , CheckPageToken ( pageToken ) ) ;
120
+ }
121
+ else
122
+ {
123
+ this . RequestParameters . Remove ( "nextPageToken" ) ;
124
+ }
125
+ }
126
+
127
+ private static int CheckPageSize ( int ? pageSize )
128
+ {
129
+ if ( pageSize > MaxListUsersResults )
130
+ {
131
+ throw new ArgumentException ( "Page size must not exceed 1000." ) ;
132
+ }
133
+ else if ( pageSize <= 0 )
134
+ {
135
+ throw new ArgumentException ( "Page size must be positive." ) ;
136
+ }
137
+
138
+ return pageSize ?? MaxListUsersResults ;
139
+ }
140
+
141
+ private static string CheckPageToken ( string token )
142
+ {
143
+ if ( token == string . Empty )
144
+ {
145
+ throw new ArgumentException ( "Page token must not be empty." ) ;
146
+ }
147
+
148
+ return token ;
149
+ }
150
+
124
151
private void AddOrUpdate ( string paramName , string value )
125
152
{
126
153
var parameter = new Parameter ( )
@@ -190,7 +217,7 @@ private async Task<HttpResponseMessage> SendAsync(
190
217
/// Factory class that validates arguments, and then creates new instances of the
191
218
/// <see cref="ListUsersRequest"/> class.
192
219
/// </summary>
193
- internal class Factory
220
+ internal sealed class Factory
194
221
{
195
222
private readonly string baseUrl ;
196
223
private readonly HttpClient httpClient ;
@@ -203,22 +230,9 @@ internal Factory(
203
230
this . httpClient = httpClient ;
204
231
this . options = new ListUsersOptions ( )
205
232
{
206
- PageSize = options ? . PageSize ?? MaxListUsersResults ,
207
- PageToken = options ? . PageToken ,
233
+ PageSize = CheckPageSize ( options ? . PageSize ) ,
234
+ PageToken = CheckPageToken ( options ? . PageToken ) ,
208
235
} ;
209
-
210
- if ( this . options . PageSize > MaxListUsersResults )
211
- {
212
- throw new ArgumentException ( "Page size must not exceed 1000." ) ;
213
- }
214
- else if ( this . options . PageSize <= 0 )
215
- {
216
- throw new ArgumentException ( "Page size must be positive." ) ;
217
- }
218
- else if ( this . options . PageToken == string . Empty )
219
- {
220
- throw new ArgumentException ( "Initial page token must not be empty." ) ;
221
- }
222
236
}
223
237
224
238
internal ListUsersRequest Create ( )
0 commit comments