Skip to content

Commit

Permalink
Merge pull request #2 from nullforce-public/twibooru
Browse files Browse the repository at this point in the history
Add support for Twibooru.
Breaking: Namespace for Derpibooru/Philomena support
  • Loading branch information
nullforce authored Aug 14, 2022
2 parents b6b5776 + e83c6e8 commit 458cb52
Show file tree
Hide file tree
Showing 28 changed files with 443 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/JsonBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Nullforce.Api.Derpibooru.JsonModels;
namespace Nullforce.Api.JsonModels;

public abstract class JsonBase
{
Expand Down
2 changes: 1 addition & 1 deletion src/AwardsJson.cs → src/Philomena/AwardsJson.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Nullforce.Api.Derpibooru.JsonModels;
namespace Nullforce.Api.JsonModels.Philomena;

public class AwardsJson : JsonBase
{
Expand Down
2 changes: 1 addition & 1 deletion src/CommentJson.cs → src/Philomena/CommentJson.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Nullforce.Api.Derpibooru.JsonModels;
namespace Nullforce.Api.JsonModels.Philomena;

public class CommentJson : JsonBase
{
Expand Down
2 changes: 1 addition & 1 deletion src/FilterJson.cs → src/Philomena/FilterJson.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Nullforce.Api.Derpibooru.JsonModels;
namespace Nullforce.Api.JsonModels.Philomena;

public class FilterJson : JsonBase
{
Expand Down
2 changes: 1 addition & 1 deletion src/ForumJson.cs → src/Philomena/ForumJson.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Nullforce.Api.Derpibooru.JsonModels;
namespace Nullforce.Api.JsonModels.Philomena;

public class ForumJson : JsonBase
{
Expand Down
2 changes: 1 addition & 1 deletion src/GalleryJson.cs → src/Philomena/GalleryJson.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Nullforce.Api.Derpibooru.JsonModels;
namespace Nullforce.Api.JsonModels.Philomena;

public class GalleryJson : JsonBase
{
Expand Down
2 changes: 1 addition & 1 deletion src/ImageJson.cs → src/Philomena/ImageJson.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Nullforce.Api.Derpibooru.JsonModels;
namespace Nullforce.Api.JsonModels.Philomena;

public class ImageJson : JsonBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Nullforce.Api.Derpibooru.JsonModels;
namespace Nullforce.Api.JsonModels.Philomena;

public class IntensitiesJson : JsonBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Nullforce.Api.Derpibooru.JsonModels;
namespace Nullforce.Api.JsonModels.Philomena;

/// <summary>
/// The interactions of the user specified by the API key given.
Expand Down
2 changes: 1 addition & 1 deletion src/LinksJson.cs → src/Philomena/LinksJson.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Nullforce.Api.Derpibooru.JsonModels;
namespace Nullforce.Api.JsonModels.Philomena;

public class LinksJson : JsonBase
{
Expand Down
2 changes: 1 addition & 1 deletion src/OembedJson.cs → src/Philomena/OembedJson.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Nullforce.Api.Derpibooru.JsonModels;
namespace Nullforce.Api.JsonModels.Philomena;

public class OembedJson : JsonBase
{
Expand Down
2 changes: 1 addition & 1 deletion src/PostJson.cs → src/Philomena/PostJson.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Nullforce.Api.Derpibooru.JsonModels;
namespace Nullforce.Api.JsonModels.Philomena;

public class PostJson : JsonBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Nullforce.Api.Derpibooru.JsonModels;
namespace Nullforce.Api.JsonModels.Philomena;

public class RepresentationsJson : JsonBase
{
Expand Down
2 changes: 1 addition & 1 deletion src/RootJson.cs → src/Philomena/RootJson.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Nullforce.Api.Derpibooru.JsonModels;
namespace Nullforce.Api.JsonModels.Philomena;

public class CommentRootJson : JsonBase
{
Expand Down
2 changes: 1 addition & 1 deletion src/TagJson.cs → src/Philomena/TagJson.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Nullforce.Api.Derpibooru.JsonModels;
namespace Nullforce.Api.JsonModels.Philomena;

public class TagJson : JsonBase
{
Expand Down
2 changes: 1 addition & 1 deletion src/TopicJson.cs → src/Philomena/TopicJson.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Nullforce.Api.Derpibooru.JsonModels;
namespace Nullforce.Api.JsonModels.Philomena;

public class TopicJson : JsonBase
{
Expand Down
2 changes: 1 addition & 1 deletion src/UserJson.cs → src/Philomena/UserJson.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Nullforce.Api.Derpibooru.JsonModels;
namespace Nullforce.Api.JsonModels.Philomena;

public class UserJson : JsonBase
{
Expand Down
19 changes: 19 additions & 0 deletions src/Twibooru/CommentJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Nullforce.Api.JsonModels.Twibooru;

public class CommentJson : JsonBase
{
[JsonPropertyName("id")]
public int Id { get; set; }

[JsonPropertyName("created_at")]
public DateTime CreatedAt { get; set; }

[JsonPropertyName("updated_at")]
public DateTime UpdatedAt { get; set; }

[JsonPropertyName("hidden_from_users")]
public bool HiddenFromUsers { get; set; }

[JsonPropertyName("body")]
public string Body { get; set; }
}
13 changes: 13 additions & 0 deletions src/Twibooru/IntensitiesJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Nullforce.Api.JsonModels.Twibooru;

public class IntensitiesJson : JsonBase
{
[JsonPropertyName("ne")]
public double NE { get; set; }
[JsonPropertyName("nw")]
public double NW { get; set; }
[JsonPropertyName("se")]
public double SE { get; set; }
[JsonPropertyName("sw")]
public double SW { get; set; }
}
13 changes: 13 additions & 0 deletions src/Twibooru/LocationJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Nullforce.Api.JsonModels.Twibooru;

public class LocationJson : JsonBase
{
[JsonPropertyName("id_at_location")]
public int Id { get; set; }

[JsonPropertyName("location")]
public string Location { get; set; }

[JsonPropertyName("url_at_location")]
public string Url { get; set; }
}
120 changes: 120 additions & 0 deletions src/Twibooru/PostJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
namespace Nullforce.Api.JsonModels.Twibooru;

public class PostJson : JsonBase
{
[JsonPropertyName("id")]
public int Id { get; set; }

[JsonPropertyName("created_at")]
public DateTime CreatedAt { get; set; }

[JsonPropertyName("deletion_reason")]
public string DeletionReason { get; set; }

[JsonPropertyName("duplicate_of")]
public int DuplicateOf { get; set; }

[JsonPropertyName("first_seen_at")]
public DateTime FirstSeenAt { get; set; }

[JsonPropertyName("hidden_from_users")]
public bool HiddenFromUsers { get; set; }

[JsonPropertyName("locations")]
public LocationJson[] Locations { get; set; }

/// <summary>
/// The type of media associated with this post. One of "paste", "image".
/// </summary>
[JsonPropertyName("media_type")]
public string MediaType { get; set; }

[JsonPropertyName("orig_sha512_hash")]
public string OriginalSHA512Hash { get; set; }

[JsonPropertyName("processed")]
public bool Processed { get; set; }

[JsonPropertyName("sha512_hash")]
public string SHA512Hash { get; set; }

[JsonPropertyName("source_url")]
public string SourceUrl { get; set; }

[JsonPropertyName("tag_ids")]
public int[] TagIds { get; set; }

[JsonPropertyName("tags")]
public string[] Tags { get; set; }

[JsonPropertyName("updated_at")]
public DateTime UpdatedAt { get; set; }

// Non-hidden Post
[JsonPropertyName("comment_count")]
public int CommentCount { get; set; }

[JsonPropertyName("description")]
public string Description { get; set; }

[JsonPropertyName("downvotes")]
public int Downvotes { get; set; }

[JsonPropertyName("faves")]
public int Favorites { get; set; }

[JsonPropertyName("score")]
public int Score { get; set; }

[JsonPropertyName("size")]
public long Size { get; set; }

[JsonPropertyName("upvotes")]
public int Upvotes { get; set; }

[JsonPropertyName("wilson_score")]
public double WilsonScore { get; set; }

// Image Post
[JsonPropertyName("animated")]
public bool Animated { get; set; }

[JsonPropertyName("aspect_ratio")]
public double AspectRatio { get; set; }

[JsonPropertyName("duration")]
public double Duration { get; set; }

/// <summary>
/// The file extension of the image. One of "gif", "jpg", "jpeg", "png", "svg", "webm", "mp4".
/// </summary>
[JsonPropertyName("format")]
public string Format { get; set; }

[JsonPropertyName("height")]
public int Height { get; set; }

[JsonPropertyName("intensities")]
public IntensitiesJson Intensities { get; set; }

/// <summary>
/// The MIME type of this image. One of "image/gif", "image/jpeg", "image/png", "image/svg+xml", "video/webm", "video/mp4".
/// </summary>
[JsonPropertyName("mime_type")]
public string MimeType { get; set; }

[JsonPropertyName("name")]
public string Name { get; set; }

[JsonPropertyName("representations")]
public RepresentationsJson Representations { get; set; }

[JsonPropertyName("thumbnails_generated")]
public bool ThumbnailsGenerated { get; set; }

[JsonPropertyName("view_url")]
public string ViewUrl { get; set; }

[JsonPropertyName("width")]
public int Width { get; set; }
}
19 changes: 19 additions & 0 deletions src/Twibooru/RepresentationsJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Nullforce.Api.JsonModels.Twibooru;

public class RepresentationsJson : JsonBase
{
[JsonPropertyName("full")]
public string Full { get; set; }
[JsonPropertyName("large")]
public string Large { get; set; }
[JsonPropertyName("medium")]
public string Medium { get; set; }
[JsonPropertyName("small")]
public string Small { get; set; }
[JsonPropertyName("thumb")]
public string Thumb { get; set; }
[JsonPropertyName("thumb_small")]
public string ThumbSmall { get; set; }
[JsonPropertyName("thumb_tiny")]
public string ThumbTiny { get; set; }
}
29 changes: 29 additions & 0 deletions src/Twibooru/RootJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Nullforce.Api.JsonModels.Twibooru;


public class CommentResponseJson : JsonBase
{
[JsonPropertyName("comments")]
public CommentJson[] Comments { get; set; }
}

public class PostResponseJson : JsonBase
{
[JsonPropertyName("post")]
public PostJson Post { get; set; }
}

public class SearchPostsResponseJson : JsonBase
{
[JsonPropertyName("posts")]
public PostJson[] Posts { get; set; }

[JsonPropertyName("total")]
public int Total { get; set; }
}

public class SearchTagsResponseJson : JsonBase
{
[JsonPropertyName("tags")]
public TagJson[] Tags { get; set; }
}
46 changes: 46 additions & 0 deletions src/Twibooru/TagJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace Nullforce.Api.JsonModels.Twibooru;

public class TagJson : JsonBase
{
[JsonPropertyName("id")]
public int Id { get; set; }

[JsonPropertyName("aliased_tag")]
public string AliasedTag { get; set; }

[JsonPropertyName("aliases")]
public string[] Aliases { get; set; }

/// <summary>
/// The category class of this tag. One of "character", "content-fanmade", "content-official", "error", "oc", "origin", "rating", "species", "spoiler".
/// </summary>
[JsonPropertyName("category")]
public string Category { get; set; }

[JsonPropertyName("description")]
public string Description { get; set; }

[JsonPropertyName("implied_by_tags")]
public string[] ImpliedByTags { get; set; }

[JsonPropertyName("implied_tags")]
public string[] ImpliedTags { get; set; }

[JsonPropertyName("name")]
public string Name { get; set; }

[JsonPropertyName("name_in_namespace")]
public string NameInNamespace { get; set; }

[JsonPropertyName("namespace")]
public string Namespace { get; set; }

[JsonPropertyName("posts")]
public int PostCount { get; set; }

[JsonPropertyName("short_description")]
public string ShortDescription { get; set; }

[JsonPropertyName("slug")]
public string Slug { get; set; }
}
1 change: 1 addition & 0 deletions src/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
global using Nullforce.Api.JsonModels;
global using System;
global using System.Collections.Generic;
global using System.Text.Json;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
using System;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using FluentAssertions;
using FluentAssertions.Execution;
using Flurl;
using Flurl.Http;
using Xunit;

namespace Nullforce.Api.Derpibooru.JsonModels.Tests.Integration;
namespace Nullforce.Api.JsonModels.Philomena.Tests.Integration;

public class DeserializationTests
public class PhilomenaTests
{
private readonly string _baseUri = "https://derpibooru.org/api/v1/json";

public DeserializationTests()
public PhilomenaTests()
{
// Do this in Startup. All calls to the _baseUri will use the same HttpClient instance.
FlurlHttp.ConfigureClient(_baseUri, cli => cli
Expand Down
Loading

0 comments on commit 458cb52

Please sign in to comment.