Skip to content

Commit

Permalink
Use namepsace statements
Browse files Browse the repository at this point in the history
  • Loading branch information
nullforce committed Aug 14, 2022
1 parent 4e1b811 commit 8eb9b93
Show file tree
Hide file tree
Showing 11 changed files with 396 additions and 417 deletions.
23 changes: 11 additions & 12 deletions src/DerpiBase.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
namespace Nullforce.Api.Derpibooru
namespace Nullforce.Api.Derpibooru;

public class DerpiBase
{
public class DerpiBase
{
protected readonly string _apiBaseUri;
protected readonly string _apiKey;
protected string _uri;
public string Uri => _uri;
protected readonly string _apiBaseUri;
protected readonly string _apiKey;
protected string _uri;
public string Uri => _uri;

public DerpiBase(string apiBaseUri, string apiKey)
{
_apiBaseUri = apiBaseUri;
_apiKey = apiKey;
}
public DerpiBase(string apiBaseUri, string apiKey)
{
_apiBaseUri = apiBaseUri;
_apiKey = apiKey;
}
}
73 changes: 36 additions & 37 deletions src/DerpiClient.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
namespace Nullforce.Api.Derpibooru
namespace Nullforce.Api.Derpibooru;

public class DerpiClient
{
public class DerpiClient
{
private readonly string _apiBaseUri = "https://derpibooru.org/api/v1/json";
private readonly string _apiKey;
private readonly string _apiBaseUri = "https://derpibooru.org/api/v1/json";
private readonly string _apiKey;

public DerpiClient()
{
}
public DerpiClient()
{
}

public DerpiClient(string apiKey)
{
_apiKey = apiKey;
}
public DerpiClient(string apiKey)
{
_apiKey = apiKey;
}

/// <summary>
/// Gets the image response for an image by Id
/// </summary>
/// <param name="imageId">The id of the image</param>
/// <returns>A fluent API wrapper for get image</returns>
public DerpiGetImage GetImage(int imageId)
{
return new DerpiGetImage(_apiBaseUri, _apiKey, imageId);
}
/// <summary>
/// Gets the image response for an image by Id
/// </summary>
/// <param name="imageId">The id of the image</param>
/// <returns>A fluent API wrapper for get image</returns>
public DerpiGetImage GetImage(int imageId)
{
return new DerpiGetImage(_apiBaseUri, _apiKey, imageId);
}

/// <summary>
/// Gets the image response for the featured image
/// </summary>
/// <returns>A fluent API wrapper for featured image</returns>
public DerpiGetFeaturedImage GetFeaturedImage()
{
return new DerpiGetFeaturedImage(_apiBaseUri, _apiKey);
}
/// <summary>
/// Gets the image response for the featured image
/// </summary>
/// <returns>A fluent API wrapper for featured image</returns>
public DerpiGetFeaturedImage GetFeaturedImage()
{
return new DerpiGetFeaturedImage(_apiBaseUri, _apiKey);
}

/// <summary>
/// Exposes the Derpibooru Search as a Fluent API.
/// </summary>
/// <returns>A fluent API wrapper for search</returns>
public DerpiSearch Search()
{
return new DerpiSearch(_apiBaseUri, _apiKey);
}
/// <summary>
/// Exposes the Derpibooru Search as a Fluent API.
/// </summary>
/// <returns>A fluent API wrapper for search</returns>
public DerpiSearch Search()
{
return new DerpiSearch(_apiBaseUri, _apiKey);
}
}
13 changes: 6 additions & 7 deletions src/DerpiGetFeaturedImage.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Flurl;

namespace Nullforce.Api.Derpibooru
namespace Nullforce.Api.Derpibooru;

public class DerpiGetFeaturedImage : DerpiBase
{
public class DerpiGetFeaturedImage : DerpiBase
public DerpiGetFeaturedImage(string apiBaseUri, string apiKey)
: base(apiBaseUri, apiKey)
{
public DerpiGetFeaturedImage(string apiBaseUri, string apiKey)
: base(apiBaseUri, apiKey)
{
_uri = apiBaseUri.AppendPathSegment("images/featured");
}
_uri = apiBaseUri.AppendPathSegment("images/featured");
}
}
31 changes: 15 additions & 16 deletions src/DerpiGetImage.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
using Flurl;

namespace Nullforce.Api.Derpibooru
namespace Nullforce.Api.Derpibooru;

public class DerpiGetImage : DerpiBase
{
public class DerpiGetImage : DerpiBase
public DerpiGetImage(string apiBaseUri, string apiKey, int imageId)
: base(apiBaseUri, apiKey)
{
public DerpiGetImage(string apiBaseUri, string apiKey, int imageId)
: base(apiBaseUri, apiKey)
{
_uri = apiBaseUri.AppendPathSegment($"images/{imageId}");
}
_uri = apiBaseUri.AppendPathSegment($"images/{imageId}");
}

/// <summary>
/// Applies a Derpibooru filter
/// </summary>
/// <param name="filterId">A user or system filter ID (See https://www.derpibooru.org/filters) </param>
public DerpiGetImage WithFilterId(int filterId)
{
_uri = _uri.SetQueryParam("filter_id", filterId);
return this;
}
/// <summary>
/// Applies a Derpibooru filter
/// </summary>
/// <param name="filterId">A user or system filter ID (See https://www.derpibooru.org/filters) </param>
public DerpiGetImage WithFilterId(int filterId)
{
_uri = _uri.SetQueryParam("filter_id", filterId);
return this;
}
}
Loading

0 comments on commit 8eb9b93

Please sign in to comment.