@@ -43,12 +43,8 @@ private ListUsersRequest(
4343 this . baseUrl = baseUrl ;
4444 this . httpClient = httpClient ;
4545 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 ) ;
5248 }
5349
5450 public string MethodName => "ListUsers" ;
@@ -61,16 +57,6 @@ private ListUsersRequest(
6157
6258 public IClientService Service { get ; }
6359
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-
7460 public HttpRequestMessage CreateRequest ( bool ? overrideGZipEnabled = null )
7561 {
7662 var queryParameters = string . Join ( "&" , this . RequestParameters . Select (
@@ -121,6 +107,47 @@ public ExportedUserRecords Execute()
121107 return this . ExecuteAsync ( ) . Result ;
122108 }
123109
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+
124151 private void AddOrUpdate ( string paramName , string value )
125152 {
126153 var parameter = new Parameter ( )
@@ -190,7 +217,7 @@ private async Task<HttpResponseMessage> SendAsync(
190217 /// Factory class that validates arguments, and then creates new instances of the
191218 /// <see cref="ListUsersRequest"/> class.
192219 /// </summary>
193- internal class Factory
220+ internal sealed class Factory
194221 {
195222 private readonly string baseUrl ;
196223 private readonly HttpClient httpClient ;
@@ -203,22 +230,9 @@ internal Factory(
203230 this . httpClient = httpClient ;
204231 this . options = new ListUsersOptions ( )
205232 {
206- PageSize = options ? . PageSize ?? MaxListUsersResults ,
207- PageToken = options ? . PageToken ,
233+ PageSize = CheckPageSize ( options ? . PageSize ) ,
234+ PageToken = CheckPageToken ( options ? . PageToken ) ,
208235 } ;
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- }
222236 }
223237
224238 internal ListUsersRequest Create ( )
0 commit comments