-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathSearchUsersRequest.cs
203 lines (174 loc) · 6.37 KB
/
SearchUsersRequest.cs
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
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using Octokit.Internal;
namespace Octokit
{
/// <summary>
/// Searching Users
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class SearchUsersRequest : BaseSearchRequest
{
/// <summary>
/// Initializes a new instance of the <see cref="SearchUsersRequest"/> class.
/// </summary>
/// <param name="term">The search term.</param>
public SearchUsersRequest(string term) : base(term)
{
}
/// <summary>
/// Optional Sort field. One of followers, repositories, or joined. If not provided (null), results are sorted by best match.
/// <remarks>https://help.github.com/articles/searching-users#sorting</remarks>
/// </summary>
public UsersSearchSort? SortField { get; set; }
/// <summary>
/// The sort field as a string.
/// </summary>
public override string Sort
{
get { return SortField.ToParameter(); }
}
/// <summary>
/// Filter users based on the number of followers they have.
/// <remarks>https://help.github.com/articles/searching-users#followers</remarks>
/// </summary>
public Range Followers { get; set; }
/// <summary>
/// Filter users based on when they joined.
/// <remarks>https://help.github.com/articles/searching-users#created</remarks>
/// </summary>
public DateRange Created { get; set; }
/// <summary>
/// Filter users by the location indicated in their profile.
/// <remarks>https://help.github.com/articles/searching-users#location</remarks>
/// </summary>
public string Location { get; set; }
/// <summary>
/// Filters users based on the number of repositories they have.
/// <remarks>https://help.github.com/articles/searching-users#repository-count</remarks>
/// </summary>
public Range Repositories { get; set; }
/// <summary>
/// Search for users that have repositories that match a certain language.
/// <remarks>https://help.github.com/articles/searching-users#language</remarks>
/// </summary>
public Language? Language { get; set; }
/// <summary>
/// With this qualifier you can restrict the search to just personal accounts or just organization accounts.
/// <remarks>https://help.github.com/articles/searching-users#type</remarks>
/// </summary>
public AccountSearchType? AccountType { get; set; }
private IEnumerable<UserInQualifier> _inQualifier;
/// <summary>
/// Qualifies which fields are searched. With this qualifier you can restrict the search to just the username, public email, full name, or any combination of these.
/// <remarks>https://help.github.com/articles/searching-users#search-in</remarks>
/// </summary>
public IEnumerable<UserInQualifier> In
{
get
{
return _inQualifier;
}
set
{
if (value != null && value.Any())
_inQualifier = value.Distinct().ToList();
}
}
public override IReadOnlyList<string> MergedQualifiers()
{
var parameters = new List<string>();
if (AccountType != null)
{
parameters.Add(string.Format(CultureInfo.InvariantCulture, "type:{0}", AccountType));
}
if (In != null)
{
parameters.Add(string.Format(CultureInfo.InvariantCulture, "in:{0}", string.Join(",", In)));
}
if (Repositories != null)
{
parameters.Add(string.Format(CultureInfo.InvariantCulture, "repos:{0}", Repositories));
}
if (Location.IsNotBlank())
{
parameters.Add(string.Format(CultureInfo.InvariantCulture, "location:{0}", Location));
}
if (Language != null)
{
parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:\"{0}\"", Language.ToParameter()));
}
if (Created != null)
{
parameters.Add(string.Format(CultureInfo.InvariantCulture, "created:{0}", Created));
}
if (Followers != null)
{
parameters.Add(string.Format(CultureInfo.InvariantCulture, "followers:{0}", Followers));
}
return new ReadOnlyCollection<string>(parameters);
}
internal string DebuggerDisplay
{
get
{
return string.Format(CultureInfo.InvariantCulture, "Term: {0} Sort: {1}", Term, Sort);
}
}
}
/// <summary>
/// Account Type used to filter search result
/// </summary>
public enum AccountSearchType
{
/// <summary>
/// User account
/// </summary>
[Parameter(Value = "user")]
User,
/// <summary>
/// Organization account
/// </summary>
[Parameter(Value = "org")]
Org
}
/// <summary>
/// User type to filter search results
/// </summary>
public enum UserInQualifier
{
/// <summary>
/// Search by the username
/// </summary>
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "Username")]
[Parameter(Value = "login")]
Username,
/// <summary>
/// Search by the user's email address
/// </summary>
[Parameter(Value = "email")]
Email,
/// <summary>
/// Search by the user's full name
/// </summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Fullname")]
[Parameter(Value = "fullname")]
Fullname
}
/// <summary>
///
/// </summary>
public enum UsersSearchSort
{
[Parameter(Value = "followers")]
Followers,
[Parameter(Value = "repositories")]
Repositories,
[Parameter(Value = "joined")]
Joined
}
}