-
Notifications
You must be signed in to change notification settings - Fork 0
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 #2 from nullforce-public/addTwibooruSupport
Add twibooru support
- Loading branch information
Showing
29 changed files
with
482 additions
and
197 deletions.
There are no files selected for viewing
File renamed without changes.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace Nullforce.Api.Derpibooru; | ||
namespace Nullforce.Api.UrlBuilder.Derpibooru; | ||
|
||
public class DerpiClient | ||
{ | ||
|
4 changes: 2 additions & 2 deletions
4
src/DerpiGetFeaturedImage.cs → ...ilder/Derpibooru/DerpiGetFeaturedImage.cs
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
2 changes: 1 addition & 1 deletion
2
src/DerpiSortOptions.cs → ...UrlBuilder/Derpibooru/DerpiSortOptions.cs
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
2 changes: 1 addition & 1 deletion
2
src/DerpiSystemFilter.cs → ...rlBuilder/Derpibooru/DerpiSystemFilter.cs
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,6 @@ | ||
namespace Nullforce.Api.UrlBuilder; | ||
|
||
public interface IGetFeaturedImage | ||
{ | ||
public string Uri { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Nullforce.Api.UrlBuilder; | ||
|
||
public interface IGetImage | ||
{ | ||
public string Uri { get; } | ||
|
||
/// <summary> | ||
/// Applies a Derpibooru filter | ||
/// </summary> | ||
/// <param name="filterId">A user or system filter ID (See https://www.derpibooru.org/filters) </param> | ||
public IGetImage WithFilterId(int filterId); | ||
} |
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,53 @@ | ||
namespace Nullforce.Api.UrlBuilder; | ||
|
||
public interface ISearch | ||
{ | ||
public string Uri { get; } | ||
|
||
/// <summary> | ||
/// Specifies a search query filter | ||
/// </summary> | ||
/// <remarks> | ||
/// Search my favorites: my:faves, !my:faves | ||
/// Search my upvotes: my:upvotes, !my:upvotes | ||
/// Search my downvotes: my:downvotes, !my:downvotes | ||
/// Search my uploads: my:uploads, !my:uploads | ||
/// Search my watched: my:watched, !my:watched | ||
/// </remarks> | ||
/// <param name="query">A query string following the syntax at https://derpibooru.org/pages/search_syntax </param> | ||
public ISearch WithQuery(string query); | ||
|
||
/// <summary> | ||
/// Applies a Derpibooru filter | ||
/// </summary> | ||
/// <param name="filterId">A user or system filter ID (See https://www.derpibooru.org/filters) </param> | ||
public ISearch WithFilterId(int filterId); | ||
|
||
/// <summary> | ||
/// Applies a Derpibooru sort option | ||
/// </summary> | ||
/// <param name="sortOption">A sort option</param> | ||
public ISearch SortBy(string sort); | ||
|
||
/// <summary> | ||
/// Sorts the results in ascending order | ||
/// </summary> | ||
public ISearch SortAscending(); | ||
|
||
/// <summary> | ||
/// Sorts the results in descending order | ||
/// </summary> | ||
public ISearch SortDescending(); | ||
|
||
/// <summary> | ||
/// The page number for the search results | ||
/// </summary> | ||
/// <param name="page">A 1-indexed page number</param> | ||
public ISearch Page(int page); | ||
|
||
/// <summary> | ||
/// The number of search results to return per page | ||
/// </summary> | ||
/// <param name="limit">A limit between 1 and 50</param> | ||
public ISearch PerPage(int limit); | ||
} |
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,15 @@ | ||
namespace Nullforce.Api.UrlBuilder.Twibooru; | ||
|
||
public abstract class TwibooruBase | ||
{ | ||
protected readonly string _apiBaseUri; | ||
protected readonly string _apiKey; | ||
protected string _uri; | ||
public string Uri => _uri; | ||
|
||
public TwibooruBase(string apiBaseUri, string apiKey) | ||
{ | ||
_apiBaseUri = apiBaseUri; | ||
_apiKey = apiKey; | ||
} | ||
} |
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,39 @@ | ||
namespace Nullforce.Api.UrlBuilder.Twibooru; | ||
|
||
public class TwibooruClient | ||
{ | ||
private readonly string _apiBaseUri = "https://twibooru.org/api/v3"; | ||
private readonly string _apiKey; | ||
|
||
public TwibooruClient() | ||
{ | ||
} | ||
|
||
public TwibooruClient(string apiKey) | ||
{ | ||
_apiKey = apiKey; | ||
} | ||
|
||
public TwibooruGetImage GetImage(int imageId) | ||
{ | ||
return new TwibooruGetImage(_apiBaseUri, _apiKey, imageId); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the image response for the featured image | ||
/// </summary> | ||
/// <returns>A fluent API wrapper for featured image</returns> | ||
public TwibooruGetFeaturedImage GetFeaturedImage() | ||
{ | ||
return new TwibooruGetFeaturedImage(_apiBaseUri, _apiKey); | ||
} | ||
|
||
/// <summary> | ||
/// Exposes the Twibooru Search as a Fluent API. | ||
/// </summary> | ||
/// <returns>A fluent API wrapper for search</returns> | ||
public TwibooruSearch Search() | ||
{ | ||
return new TwibooruSearch(_apiBaseUri, _apiKey); | ||
} | ||
} |
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,12 @@ | ||
using Flurl; | ||
|
||
namespace Nullforce.Api.UrlBuilder.Twibooru; | ||
|
||
public class TwibooruGetFeaturedImage : TwibooruBase, IGetFeaturedImage | ||
{ | ||
public TwibooruGetFeaturedImage(string apiBaseUri, string apiKey) | ||
: base(apiBaseUri, apiKey) | ||
{ | ||
_uri = apiBaseUri.AppendPathSegment("posts/featured"); | ||
} | ||
} |
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,22 @@ | ||
using Flurl; | ||
|
||
namespace Nullforce.Api.UrlBuilder.Twibooru; | ||
|
||
public class TwibooruGetImage : TwibooruBase, IGetImage | ||
{ | ||
public TwibooruGetImage(string apiBaseUri, string apiKey, int imageId) | ||
: base(apiBaseUri, apiKey) | ||
{ | ||
_uri = apiBaseUri.AppendPathSegment($"images/{imageId}"); | ||
} | ||
|
||
/// <summary> | ||
/// Applies a Twibooru filter | ||
/// </summary> | ||
/// <param name="filterId">A user or system filter ID</param> | ||
public IGetImage WithFilterId(int filterId) | ||
{ | ||
_uri = _uri.SetQueryParam("filter_id", filterId); | ||
return this; | ||
} | ||
} |
Oops, something went wrong.