From efc806b57af902613a8f71a12ce92c6ef7f998af Mon Sep 17 00:00:00 2001 From: Haroon Date: Mon, 13 Jan 2014 09:31:26 +0000 Subject: [PATCH 1/5] base class for searching --- Octokit/Models/Request/SearchBase.cs | 90 ++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Octokit/Models/Request/SearchBase.cs diff --git a/Octokit/Models/Request/SearchBase.cs b/Octokit/Models/Request/SearchBase.cs new file mode 100644 index 0000000000..68a7fb49b0 --- /dev/null +++ b/Octokit/Models/Request/SearchBase.cs @@ -0,0 +1,90 @@ +using System.Globalization; + +namespace Octokit +{ + /// + /// Base class for searching issues/code/users/repos + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1012:AbstractTypesShouldNotHaveConstructors")] + public abstract class BaseSearchRequest + { + public BaseSearchRequest(string term) + { + Ensure.ArgumentNotNullOrEmptyString(term, "term"); + Term = term; + Page = 1; + PerPage = 100; + Order = SortDirection.Descending; + } + + /// + /// The search term + /// + public string Term { get; private set; } + + /// + /// The sort field + /// + public abstract string Sort + { + get; + } + + private string SortOrder + { + get + { + return Order == SortDirection.Ascending ? "asc" : "desc"; + } + } + + /// + /// Optional Sort order if sort parameter is provided. One of asc or desc; the default is desc. + /// + public SortDirection Order { get; set; } + + /// + /// Page of paginated results + /// + public int Page { get; set; } + + /// + /// Number of items per page + /// + public int PerPage { get; set; } + + /// + /// All qualifiers are merged into one string + /// + public abstract string MergedQualifiers(); + + /// + /// Add qualifiers onto the search term + /// + private string TermAndQualifiers + { + get + { + var mergedParameters = MergedQualifiers(); + return Term + (mergedParameters.IsNotBlank() ? "+" + mergedParameters : ""); + } + } + + /// + /// Get the query parameters that will be appending onto the search + /// + public System.Collections.Generic.IDictionary Parameters + { + get + { + var d = new System.Collections.Generic.Dictionary(); + d.Add("page", Page.ToString(CultureInfo.CurrentCulture)); + d.Add("per_page", PerPage.ToString(CultureInfo.CurrentCulture)); + d.Add("sort", Sort); + d.Add("order", SortOrder); + d.Add("q", TermAndQualifiers); + return d; + } + } + } +} \ No newline at end of file From b206f5e3685e398b96c86e9b51e04c7885e7fdc4 Mon Sep 17 00:00:00 2001 From: Haroon Date: Mon, 13 Jan 2014 09:46:46 +0000 Subject: [PATCH 2/5] expose a collection it's simpler if we join the qualifiers... --- Octokit/Models/Request/SearchBase.cs | 9 +++++---- Octokit/Octokit.csproj | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Octokit/Models/Request/SearchBase.cs b/Octokit/Models/Request/SearchBase.cs index 68a7fb49b0..82c7bae97b 100644 --- a/Octokit/Models/Request/SearchBase.cs +++ b/Octokit/Models/Request/SearchBase.cs @@ -1,4 +1,5 @@ -using System.Globalization; +using System; +using System.Globalization; namespace Octokit { @@ -54,9 +55,9 @@ private string SortOrder public int PerPage { get; set; } /// - /// All qualifiers are merged into one string + /// All qualifiers that are used for this search /// - public abstract string MergedQualifiers(); + public abstract System.Collections.Generic.IReadOnlyCollection MergedQualifiers(); /// /// Add qualifiers onto the search term @@ -65,7 +66,7 @@ private string TermAndQualifiers { get { - var mergedParameters = MergedQualifiers(); + var mergedParameters = String.Join("+", MergedQualifiers()); return Term + (mergedParameters.IsNotBlank() ? "+" + mergedParameters : ""); } } diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index c77f10c062..c2dc936b21 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -56,6 +56,7 @@ + From ae5dabff2441d9bf2d0df21b865e11bc70bdae8e Mon Sep 17 00:00:00 2001 From: Haroon Date: Mon, 13 Jan 2014 10:12:00 +0000 Subject: [PATCH 3/5] fixed using statements --- Octokit/Models/Request/SearchBase.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Octokit/Models/Request/SearchBase.cs b/Octokit/Models/Request/SearchBase.cs index 82c7bae97b..c127ed8b05 100644 --- a/Octokit/Models/Request/SearchBase.cs +++ b/Octokit/Models/Request/SearchBase.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Globalization; namespace Octokit @@ -6,7 +8,7 @@ namespace Octokit /// /// Base class for searching issues/code/users/repos /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1012:AbstractTypesShouldNotHaveConstructors")] + [SuppressMessage("Microsoft.Design", "CA1012:AbstractTypesShouldNotHaveConstructors")] public abstract class BaseSearchRequest { public BaseSearchRequest(string term) @@ -57,7 +59,7 @@ private string SortOrder /// /// All qualifiers that are used for this search /// - public abstract System.Collections.Generic.IReadOnlyCollection MergedQualifiers(); + public abstract IReadOnlyCollection MergedQualifiers(); /// /// Add qualifiers onto the search term @@ -74,11 +76,11 @@ private string TermAndQualifiers /// /// Get the query parameters that will be appending onto the search /// - public System.Collections.Generic.IDictionary Parameters + public IDictionary Parameters { get { - var d = new System.Collections.Generic.Dictionary(); + var d = new Dictionary(); d.Add("page", Page.ToString(CultureInfo.CurrentCulture)); d.Add("per_page", PerPage.ToString(CultureInfo.CurrentCulture)); d.Add("sort", Sort); From af1e2e085cd79e7f65a6de831d713f158dfdc747 Mon Sep 17 00:00:00 2001 From: Haroon Date: Mon, 13 Jan 2014 10:22:41 +0000 Subject: [PATCH 4/5] fixed name of file --- Octokit/Models/Request/{SearchBase.cs => BaseSearchRequest.cs} | 0 Octokit/Octokit.csproj | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename Octokit/Models/Request/{SearchBase.cs => BaseSearchRequest.cs} (100%) diff --git a/Octokit/Models/Request/SearchBase.cs b/Octokit/Models/Request/BaseSearchRequest.cs similarity index 100% rename from Octokit/Models/Request/SearchBase.cs rename to Octokit/Models/Request/BaseSearchRequest.cs diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index c2dc936b21..f14a7134f6 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -56,7 +56,7 @@ - + From 02fe9839f2fa66f7f307ca519ca8fa67e92bc326 Mon Sep 17 00:00:00 2001 From: Haroon Date: Mon, 13 Jan 2014 10:24:30 +0000 Subject: [PATCH 5/5] Add basesearchrequest to all projs --- Octokit/Octokit-Mono.csproj | 1 + Octokit/Octokit-MonoAndroid.csproj | 1 + Octokit/Octokit-Monotouch.csproj | 1 + Octokit/Octokit-netcore45.csproj | 1 + 4 files changed, 4 insertions(+) diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 24df4fe180..db35c2db73 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -246,6 +246,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 43029a83fa..e93e83a6b6 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -256,6 +256,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 6a9f703234..3e7d4916dd 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -251,6 +251,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 4b48709124..6f0a70d09c 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -244,6 +244,7 @@ +