From 59d2e347b5a0075faa1d929bc2d0fe515f58557f Mon Sep 17 00:00:00 2001 From: Haroon Date: Wed, 6 Nov 2013 22:26:59 +0000 Subject: [PATCH] prepping search repos --- Octokit/Clients/ISearchClient.cs | 11 +++++ Octokit/Clients/SearchClient.cs | 38 ++++++++++++++++++ Octokit/Models/Request/SearchTerm.cs | 58 +++++++++++++++++++++++++++ Octokit/Models/Response/SearchRepo.cs | 37 +++++++++++++++++ Octokit/Octokit.csproj | 4 ++ 5 files changed, 148 insertions(+) create mode 100644 Octokit/Clients/ISearchClient.cs create mode 100644 Octokit/Clients/SearchClient.cs create mode 100644 Octokit/Models/Request/SearchTerm.cs create mode 100644 Octokit/Models/Response/SearchRepo.cs diff --git a/Octokit/Clients/ISearchClient.cs b/Octokit/Clients/ISearchClient.cs new file mode 100644 index 00000000..97997b8f --- /dev/null +++ b/Octokit/Clients/ISearchClient.cs @@ -0,0 +1,11 @@ +#if NET_45 +using System.Collections.Generic; +#endif +using System.Threading.Tasks; +namespace Octokit +{ + public interface ISearchClient + { + Task> SearchRepo(SearchTerm search); + } +} \ No newline at end of file diff --git a/Octokit/Clients/SearchClient.cs b/Octokit/Clients/SearchClient.cs new file mode 100644 index 00000000..f4b8f1c4 --- /dev/null +++ b/Octokit/Clients/SearchClient.cs @@ -0,0 +1,38 @@ +#if NET_45 +using System.Collections.Generic; +#endif +using System.Threading.Tasks; +namespace Octokit +{ + public class SearchClient : ApiClient, ISearchClient + { + /// + /// Initializes a new GitHub Search API client. + /// + /// An API connection. + public SearchClient(IApiConnection apiConnection) + : base(apiConnection) + { + + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "System.Int32.ToString", + Justification="Trust me")] + public Task> SearchRepo(SearchTerm search) + { + Ensure.ArgumentNotNull(search, "search"); + var param = new Dictionary(); + param.Add("q", search.Term); + param.Add("page", search.Page.ToString()); + param.Add("per_page ", search.PerPage.ToString()); + + if (search.Sort.HasValue) + param.Add("sort", search.Sort.Value.ToString()); + + if (search.Order.HasValue) + param.Add("order", search.Order.Value.ToString()); + + return ApiConnection.GetAll("search/repositories".FormatUri(), param); + } + } +} \ No newline at end of file diff --git a/Octokit/Models/Request/SearchTerm.cs b/Octokit/Models/Request/SearchTerm.cs new file mode 100644 index 00000000..70216644 --- /dev/null +++ b/Octokit/Models/Request/SearchTerm.cs @@ -0,0 +1,58 @@ +namespace Octokit +{ + /// + /// Searching GitHub + /// + public class SearchTerm + { + public SearchTerm(string term) + { + Term = term; + Page = 1; + PerPage = 100; + } + + /// + /// The search terms. This can be any combination of the supported repository search parameters: + /// http://developer.github.com/v3/search/#search-code + /// + public string Term { get; set; } + + /// + /// Optional Sort field. One of stars, forks, or updated. If not provided, results are sorted by best match. + /// + public SearchSort? Sort { get; set; } + + /// + /// Optional Sort order if sort parameter is provided. One of asc or desc; the default is desc. + /// + public SearchOrder? Order { get; set; } + + /// + /// Page of paginated results + /// + public int Page { get; set; } + + /// + /// Number of items per page + /// + public int PerPage { get; set; } + } + + public enum SearchSort + { + Stars, + Forks, + Updated + } + + public enum SearchOrder + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Asc")] + Asc, + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Desc")] + Desc + } + + +} \ No newline at end of file diff --git a/Octokit/Models/Response/SearchRepo.cs b/Octokit/Models/Response/SearchRepo.cs new file mode 100644 index 00000000..2dddf9d1 --- /dev/null +++ b/Octokit/Models/Response/SearchRepo.cs @@ -0,0 +1,37 @@ +using System; + +namespace Octokit +{ + public class SearchRepo + { + /// + /// repo name + /// + public string Name { get; set; } + + /// + /// full name of repo e.g. dtrupenn/Tetris + /// + public string FullName { get; set; } + + /// + /// owner of repo + /// + public User Owner { get; set; } + + /// + /// is a private repo? + /// + public bool Private { get; set; } + + /// + /// description of repo + /// + public string Description { get; set; } + + /// + /// is repo a fork + /// + public bool Fork { get; set; } + } +} \ No newline at end of file diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 613dda2f..72d1f34d 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -53,8 +53,11 @@ Properties\SolutionInfo.cs + + + @@ -83,6 +86,7 @@ +