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 { /// /// Searching Users /// [DebuggerDisplay("{DebuggerDisplay,nq}")] public class SearchUsersRequest : BaseSearchRequest { /// /// Initializes a new instance of the class. /// /// The search term. public SearchUsersRequest(string term) : base(term) { } /// /// Optional Sort field. One of followers, repositories, or joined. If not provided (null), results are sorted by best match. /// https://help.github.com/articles/searching-users#sorting /// public UsersSearchSort? SortField { get; set; } /// /// The sort field as a string. /// public override string Sort { get { return SortField.ToParameter(); } } /// /// Filter users based on the number of followers they have. /// https://help.github.com/articles/searching-users#followers /// public Range Followers { get; set; } /// /// Filter users based on when they joined. /// https://help.github.com/articles/searching-users#created /// public DateRange Created { get; set; } /// /// Filter users by the location indicated in their profile. /// https://help.github.com/articles/searching-users#location /// public string Location { get; set; } /// /// Filters users based on the number of repositories they have. /// https://help.github.com/articles/searching-users#repository-count /// public Range Repositories { get; set; } /// /// Search for users that have repositories that match a certain language. /// https://help.github.com/articles/searching-users#language /// public Language? Language { get; set; } /// /// With this qualifier you can restrict the search to just personal accounts or just organization accounts. /// https://help.github.com/articles/searching-users#type /// public AccountSearchType? AccountType { get; set; } private IEnumerable _inQualifier; /// /// 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. /// https://help.github.com/articles/searching-users#search-in /// public IEnumerable In { get { return _inQualifier; } set { if (value != null && value.Any()) _inQualifier = value.Distinct().ToList(); } } public override IReadOnlyList MergedQualifiers() { var parameters = new List(); 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)); } 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(parameters); } internal string DebuggerDisplay { get { return string.Format(CultureInfo.InvariantCulture, "Term: {0} Sort: {1}", Term, Sort); } } } /// /// Account Type used to filter search result /// public enum AccountSearchType { /// /// User account /// [Parameter(Value = "user")] User, /// /// Organization account /// [Parameter(Value = "org")] Org } /// /// User type to filter search results /// public enum UserInQualifier { /// /// Search by the username /// [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "Username")] [Parameter(Value = "login")] Username, /// /// Search by the user's email address /// [Parameter(Value = "email")] Email, /// /// Search by the user's full name /// [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Fullname")] [Parameter(Value = "fullname")] Fullname } /// /// /// public enum UsersSearchSort { [Parameter(Value = "followers")] Followers, [Parameter(Value = "repositories")] Repositories, [Parameter(Value = "joined")] Joined } }