@@ -31,31 +31,21 @@ namespace csharp_github_api.Core
3131 /// </remarks>
3232 public class UserApi : Api
3333 {
34- public readonly string BaseUrl ;
35-
36- private RestClient _client ;
37- private readonly IAuthenticator _authenticator ;
38-
3934 /// <summary>
4035 /// Instantiattes a new instance of the <see cref="UserApi"/> class.
4136 /// </summary>
4237 /// <param name="baseUrl">The base url for GitHub's API.</param>
43- public UserApi ( string baseUrl )
38+ public UserApi ( string baseUrl ) : base ( baseUrl )
4439 {
45- BaseUrl = baseUrl ;
46- _client = new RestClient ( BaseUrl ) ;
4740 }
4841
4942 /// <summary>
5043 /// Instantiattes a new instance of the <see cref="UserApi"/> class.
5144 /// </summary>
5245 /// <param name="baseUrl">The base url for GitHub's API.</param>
5346 /// <param name="authenticator">The <see cref="IAuthenticator"/> class to use to authenticate requests to the user api.</param>
54- public UserApi ( string baseUrl , IAuthenticator authenticator )
47+ public UserApi ( string baseUrl , IAuthenticator authenticator ) : base ( baseUrl , authenticator )
5548 {
56- BaseUrl = baseUrl ;
57- _authenticator = authenticator ;
58- _client = new RestClient ( BaseUrl ) ;
5949 }
6050
6151 /// <summary>
@@ -65,10 +55,10 @@ public UserApi(string baseUrl, IAuthenticator authenticator)
6555 /// <returns>An authenticated instance of the <see cref="UserApi"/> class.</returns>
6656 public UserApi Authenticated ( )
6757 {
68- if ( _authenticator != null )
58+ if ( Authenticator != null )
6959 {
70- _client = GetRestClient ( ) ;
71- _client . Authenticator = _authenticator ;
60+ Client = GetRestClient ( ) ;
61+ Client . Authenticator = Authenticator ;
7262 }
7363
7464 return this ;
@@ -81,15 +71,15 @@ public UserApi Authenticated()
8171 /// <returns>A <see cref="User"/> instance which encapsulates the response from GitHub for the requested user.</returns>
8272 public User GetUser ( string username )
8373 {
84- if ( _client == null ) _client = GetRestClient ( ) ;
74+ if ( Client == null ) Client = GetRestClient ( ) ;
8575
8676 var request = new RestRequest
8777 {
8878 Resource = string . Format ( "/user/show/{0}" , username ) ,
8979 RootElement = "user"
9080 } ;
9181
92- var response = _client . Execute < User > ( request ) ;
82+ var response = Client . Execute < User > ( request ) ;
9383
9484 var user = response . Data ;
9585
@@ -103,15 +93,15 @@ public User GetUser(string username)
10393 /// <returns>Returns a lise of <see cref="User"/> instances of GitHub users who may match the search.</returns>
10494 public IList < User > SearchUser ( string username )
10595 {
106- if ( _client == null ) _client = GetRestClient ( ) ;
96+ if ( Client == null ) Client = GetRestClient ( ) ;
10797
10898 var request = new RestRequest
10999 {
110100 Resource = string . Format ( "/user/search/{0}" , username ) ,
111101 RootElement = "users"
112102 } ;
113103
114- var response = _client . Execute < List < User > > ( request ) ;
104+ var response = Client . Execute < List < User > > ( request ) ;
115105
116106 return response . Data ;
117107 }
@@ -124,15 +114,15 @@ public IList<User> SearchUser(string username)
124114 /// <returns>A <see cref="User"/> instance which encapsulates the response from GitHub for the requested user.</returns>
125115 public User FindUserByEmail ( string email )
126116 {
127- if ( _client == null ) _client = GetRestClient ( ) ;
117+ if ( Client == null ) Client = GetRestClient ( ) ;
128118
129119 var request = new RestRequest
130120 {
131121 Resource = string . Format ( "/user/email/{0}" , email ) ,
132122 RootElement = "users"
133123 } ;
134124
135- var response = _client . Execute < User > ( request ) ;
125+ var response = Client . Execute < User > ( request ) ;
136126
137127 return response . Data ;
138128 }
@@ -154,15 +144,15 @@ public IList<string> GetFollowing(User user)
154144 /// <returns>A list of the users (username only) that the specified user is following.</returns>
155145 public IList < string > GetFollowing ( string username )
156146 {
157- if ( _client == null ) _client = GetRestClient ( ) ;
147+ if ( Client == null ) Client = GetRestClient ( ) ;
158148
159149 var request = new RestRequest
160150 {
161151 Resource = string . Format ( "/user/show/{0}/following" , username ) ,
162152 RootElement = "users"
163153 } ;
164154
165- var response = _client . Execute < List < string > > ( request ) ;
155+ var response = Client . Execute < List < string > > ( request ) ;
166156
167157 return response . Data ;
168158 }
@@ -184,23 +174,18 @@ public IList<string> GetFollowers(User user)
184174 /// <returns>A string list containing the (username only) list of users who are followers of the specified user.</returns>
185175 public IList < string > GetFollowers ( string username )
186176 {
187- if ( _client == null ) _client = GetRestClient ( ) ;
177+ if ( Client == null ) Client = GetRestClient ( ) ;
188178
189179 var request = new RestRequest
190180 {
191181 Resource = string . Format ( "/user/show/{0}/followers" , username ) ,
192182 RootElement = "users"
193183 } ;
194184
195- var response = _client . Execute < List < string > > ( request ) ;
185+ var response = Client . Execute < List < string > > ( request ) ;
196186 ThrowExceptionForBadResponseIfNeccessary ( response ) ;
197187
198188 return response . Data ;
199189 }
200-
201- private RestClient GetRestClient ( )
202- {
203- return new RestClient ( BaseUrl ) ;
204- }
205190 }
206191}
0 commit comments