mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 19:46:07 +00:00
using RequestParams base class
This commit is contained in:
@@ -61,7 +61,7 @@ namespace Octokit
|
||||
public Task<IReadOnlyList<SearchCode>> SearchCode(SearchCodeRequest search)
|
||||
{
|
||||
Ensure.ArgumentNotNull(search, "search");
|
||||
return ApiConnection.GetAll<SearchCode>("search/code".FormatUri(), search.Parameters);
|
||||
return ApiConnection.GetAll<SearchCode>("search/code".FormatUri(), search.ToParametersDictionary());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Octokit.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -10,19 +11,22 @@ namespace Octokit
|
||||
/// Searching Code/Files
|
||||
/// http://developer.github.com/v3/search/#search-code
|
||||
/// </summary>
|
||||
public class SearchCodeRequest
|
||||
public class SearchCodeRequest : RequestParameters
|
||||
{
|
||||
public SearchCodeRequest(string term)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(term, "term");
|
||||
Term = term;
|
||||
Page = 1;
|
||||
PerPage = 100;
|
||||
Order = SortDirection.Descending;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The search term
|
||||
/// </summary>
|
||||
public string Term { get; set; }
|
||||
[Parameter(Key = "q")]
|
||||
public string Term { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional Sort field. Can only be indexed, which indicates how recently a file has been indexed by the GitHub search infrastructure. If not provided, results are sorted by best match.
|
||||
@@ -32,7 +36,7 @@ namespace Octokit
|
||||
/// <summary>
|
||||
/// Optional Sort order if sort parameter is provided. One of asc or desc; the default is desc.
|
||||
/// </summary>
|
||||
public SortDirection? Order { get; set; }
|
||||
public SortDirection Order { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Page of paginated results
|
||||
@@ -42,30 +46,7 @@ namespace Octokit
|
||||
/// <summary>
|
||||
/// Number of items per page
|
||||
/// </summary>
|
||||
[Parameter(Key = "per_page")]
|
||||
public int PerPage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// get the params in the correct format...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "System.Int32.ToString")]
|
||||
public System.Collections.Generic.IDictionary<string, string> Parameters
|
||||
{
|
||||
get
|
||||
{
|
||||
var d = new System.Collections.Generic.Dictionary<string, string>();
|
||||
d.Add("q", Term);
|
||||
d.Add("page", Page.ToString());
|
||||
d.Add("per_page ", PerPage.ToString());
|
||||
|
||||
if (Sort.IsNotBlank()) //only add if not blank
|
||||
d.Add("sort", Sort);
|
||||
|
||||
if (Order.HasValue)
|
||||
d.Add("order", Order.Value.ToString());
|
||||
|
||||
return d;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user