-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from LucioMacarine/master
Haiii :3
- Loading branch information
Showing
12 changed files
with
250 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace BooruSharp.Booru | ||
{ | ||
public abstract partial class ABooru | ||
{ | ||
/// <summary> | ||
/// Gets a result of autocomplete options from a tag slice | ||
/// </summary> | ||
/// <param name="query">The tag slice to autocomplete</param> | ||
/// <returns>The task object representing the asynchronous operation.</returns> | ||
/// <exception cref="Search.FeatureUnavailable"/> | ||
/// <exception cref="System.Net.Http.HttpRequestException"/> | ||
public virtual async Task<Search.Autocomplete.SearchResult[]> AutocompleteAsync(string query) | ||
{ | ||
if (!HasAutocompleteAPI) | ||
throw new Search.FeatureUnavailable(); | ||
|
||
if (query.Length < 3) | ||
throw new ArgumentException("Autocomplete query must be longer than 3 characters"); | ||
|
||
Uri url = _format == UrlFormat.Danbooru | ||
? CreateUrl(_autocompleteUrl, SearchArg("name_matches") + query) | ||
: CreateUrl(_autocompleteUrl, SearchArg("q") + query); | ||
|
||
var array = JsonConvert.DeserializeObject<JArray>(await GetJsonAsync(url)); | ||
|
||
return GetAutocompleteResultAsync(array); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using BooruSharp.Search.Tag; | ||
|
||
namespace BooruSharp.Search.Autocomplete | ||
{ | ||
///<summary> | ||
/// Represents an autocomplete API search result. | ||
///</summary> | ||
public readonly struct SearchResult | ||
{ | ||
/// <summary> | ||
/// Initializes a <see cref="SearchResult"/> struct. | ||
/// </summary> | ||
/// <param name="id">The ID of the tag.</param> | ||
/// <param name="name">The name of the tag.</param> | ||
/// <param name="label">The label (display name) of the tag.</param> | ||
/// <param name="type">The type of the tag.</param> | ||
/// <param name="count">The number of occurences of the tag.</param> | ||
/// <param name="antecedent_name">The previous name of the tag.</param> | ||
public SearchResult(int? id, string name, string label, TagType? type, int count, string antecedent_name) | ||
{ | ||
TagID = id; | ||
Label = label; | ||
Name = name; | ||
Type = type; | ||
Count = count; | ||
AntecedentName = antecedent_name; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the ID of the tag. | ||
/// <see langword="null"/> if not on E621 or E926. | ||
/// </summary> | ||
public int? TagID { get; } | ||
|
||
/// <summary> | ||
/// Gets the label (display name) of the tag. | ||
/// </summary> | ||
public string Label { get; } | ||
|
||
/// <summary> | ||
/// Gets the name of the tag. | ||
/// </summary> | ||
public string Name { get; } | ||
|
||
/// <summary> | ||
/// Gets the type of the tag. | ||
/// <see langword="null"/> if on GelBooru02 | ||
/// </summary> | ||
/// Also known as "category". | ||
public TagType? Type { get; } | ||
|
||
/// <summary> | ||
/// Gets the number of occurences of the tag. | ||
/// </summary> | ||
public int Count { get; } | ||
|
||
/// <summary> | ||
/// Gets the previous name of the tag. | ||
/// <see langword="null"/> if not on E621 or E926. | ||
/// </summary> | ||
public string AntecedentName { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters