forked from sgrassie/csharp-github-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsers.cs
More file actions
206 lines (165 loc) · 7.66 KB
/
Users.cs
File metadata and controls
206 lines (165 loc) · 7.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//-----------------------------------------------------------------------
// <copyright file="UserApi.cs" company="TemporalCohesion.co.uk">
// Copyright [2010] [Stuart Grassie]
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
//----------------------------------------------------------------------
namespace csharp_github_api
{
using RestSharp;
using LoggingExtensions.Logging;
/// <summary>
/// Encapsulates access to the Github.com User API.
/// </summary>
/// <remarks>
/// See http://developer.github.com/v3/users/ for more details.
/// </remarks>
public class Users : Api
{
//private static readonly ILog Log = LoggingExtensions.Logging.Log.
public Users(){}
/// <summary>
/// Instantiates a new instance of the <see cref="Users"/> class.
/// </summary>
/// <param name="baseUrl">The base url for GitHub's API.</param>
public Users(string baseUrl) : base(baseUrl)
{
}
/// <summary>
/// Gets the specified user from GitHub.
/// </summary>
/// <param name="username">The user to get from GitHub.</param>
public IRestResponse Get(string username)
{
this.Log().Info("Making request for {0}", username);
if (Client == null) Client = GetRestClient();
var request = new RestRequest
{
Resource = string.Format("/users/{0}", username)
};
var response = Client.Execute(request);
CheckRateLimit(response.Headers);
return response;
}
/// <summary>
/// Gets the specified user from GitHub.
/// </summary>
/// <param name="username">The user to get from GitHub.</param>
public IRestResponse<TUser> Get<TUser>(string username) where TUser : new()
{
if (Client == null) Client = GetRestClient();
var request = new RestRequest
{
Resource = string.Format("/users/{0}", username)
};
var response = Client.Execute<TUser>(request);
CheckRateLimit(response.Headers);
return response;
}
///// <summary>
///// Searches for the user on GitHub.
///// </summary>
///// <param name="username">The user to search for.</param>
///// <returns>Returns a lise of <see cref="csharp_github_api.Models.User"/> instances of GitHub users who may match the search.</returns>
//public IList<TUser> SearchUser(string username)
//{
// if (Client == null) Client = GetRestClient();
// var request = new RestRequest
// {
// Resource = string.Format("/user/search/{0}", username),
// RootElement = "users"
// };
// var response = Client.Execute<List<TUser>>(request);
// return response.Data;
//}
///// <summary>
///// Finds a user specified by their email address.
///// This will only match the email address listed in a users public profile, and is opt-in for everyone.
///// </summary>
///// <param name="email">The email address of the user to search for.</param>
///// <returns>A <see cref="csharp_github_api.Models.User"/> instance which encapsulates the response from GitHub for the requested user.</returns>
//public TUser FindUserByEmail(string email)
//{
// if (Client == null) Client = GetRestClient();
// var request = new RestRequest
// {
// Resource = string.Format("/user/email/{0}", email),
// RootElement = "users"
// };
// var response = Client.Execute<TUser>(request);
// return response.Data;
//}
///// <summary>
///// Gets a list of the users that the specified user is following.
///// </summary>
///// <param name="username">The username to get the following list for.</param>
///// <returns>A list of the users (username only) that the specified user is following.</returns>
//public IList<TFollowing> GetFollowing<TFollowing>(string username)
//{
// if (Client == null) Client = GetRestClient();
// var request = new RestRequest(Method.GET)
// {
// Resource = "/users/{user}/following"
// };
// request.AddParameter("user", username, ParameterType.UrlSegment);
// var response = Client.Execute<List<TFollowing>>(request);
// CheckRateLimit(response.Headers);
// response.StatusCode.ShouldBe(HttpStatusCode.OK).IfNotRaiseAnError(response);
// return response.Data;
//}
///// <summary>
///// Gets a list of the users that the specified user is following.
///// </summary>
///// <param name="username">The user to get the list of followers for.</param>
///// <returns>A string list containing the (username only) list of users who are followers of the specified user.</returns>
//public IList<TFollowing> GetFollowers<TFollowing>(string username)
//{
// if (Client == null) Client = GetRestClient();
// var request = new RestRequest(Method.GET)
// {
// Resource = "/users/{user}/followers"
// };
// request.AddParameter("user", username, ParameterType.UrlSegment);
// var response = Client.Execute<List<TFollowing>>(request);
// CheckRateLimit(response.Headers);
// response.StatusCode.ShouldBe(HttpStatusCode.OK).IfNotRaiseAnError(response);
// return response.Data;
//}
//public bool Follow(string username)
//{
// if (Client == null) Client = GetRestClient();
// RequiresAuthentication();
// var request = new RestRequest(Method.PUT)
// {
// Resource = "/user/following/{user}"
// };
// request.AddParameter("user", username, ParameterType.UrlSegment);
// var response = Client.Execute(request);
// CheckRateLimit(response.Headers);
// return response.StatusCode.ShouldBe(HttpStatusCode.NoContent);
//}
//public bool UnFollow(string username)
//{
// if (Client == null) Client = GetRestClient();
// var request = new RestRequest(Method.DELETE)
// {
// Resource = "/user/following/{user}"
// };
// request.AddParameter("user", username, ParameterType.UrlSegment);
// var response = Client.Execute(request);
// CheckRateLimit(response.Headers);
// return response.StatusCode.ShouldBe(HttpStatusCode.NoContent);
//}
}
}