Remove restease and fix tags
This commit is contained in:
@@ -3,8 +3,8 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||||
<AssemblyVersion>2020.4.10.0</AssemblyVersion>
|
<AssemblyVersion>2020.4.28.0</AssemblyVersion>
|
||||||
<FileVersion>2020.4.10.0</FileVersion>
|
<FileVersion>2020.4.28.0</FileVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace Booru.Net.Tests
|
|||||||
{
|
{
|
||||||
Console.WriteLine(client);
|
Console.WriteLine(client);
|
||||||
|
|
||||||
string[] tags = new[] { "corona" };
|
List<string> tags = new List<string>{ "corona", "-cum" };
|
||||||
|
|
||||||
switch (client)
|
switch (client)
|
||||||
{
|
{
|
||||||
@@ -35,8 +35,8 @@ namespace Booru.Net.Tests
|
|||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
var p = await new E621Client().GetImagesAsync(tags).ConfigureAwait(false);
|
var posts = await new E621Client().GetImagesAsync(tags).ConfigureAwait(false);
|
||||||
Console.WriteLine(p.Posts.All(x => x.Tags.Any(z => z.Value.Any(y => tags.Contains(y)))));
|
Console.WriteLine(posts.All(x => x.Tags.Any(z => z.Value.Any(y => tags.Contains(y)))));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
|||||||
@@ -24,11 +24,11 @@ Yande.re</Description>
|
|||||||
<PackageTags>booru imageboard api wrapper</PackageTags>
|
<PackageTags>booru imageboard api wrapper</PackageTags>
|
||||||
<PackageLicenseUrl></PackageLicenseUrl>
|
<PackageLicenseUrl></PackageLicenseUrl>
|
||||||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
||||||
<Version>2.0.4</Version>
|
<Version>2.0.5</Version>
|
||||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||||
<AssemblyVersion>2.0.4.0</AssemblyVersion>
|
<AssemblyVersion>2.0.5.0</AssemblyVersion>
|
||||||
<FileVersion>2.0.4.0</FileVersion>
|
<FileVersion>2.0.5.0</FileVersion>
|
||||||
<PackageReleaseNotes>Fix E621 Tags</PackageReleaseNotes>
|
<PackageReleaseNotes>Tags now work</PackageReleaseNotes>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||||
@@ -46,7 +46,6 @@ Yande.re</Description>
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||||
<PackageReference Include="RestEase" Version="1.4.10" />
|
|
||||||
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
|
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using RestEase;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@@ -7,35 +6,43 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Booru.Net
|
namespace Booru.Net
|
||||||
{
|
{
|
||||||
public class DanbooruClient : IPostsBooruClient<DanbooruImage>, IDisposable
|
public class DanbooruClient : IDisposable
|
||||||
{
|
{
|
||||||
IPostsBooruClient<DanbooruImage> _api;
|
private readonly HttpClient _api;
|
||||||
|
private readonly JsonSerializerSettings settings;
|
||||||
|
|
||||||
public DanbooruClient()
|
public DanbooruClient()
|
||||||
{
|
{
|
||||||
var httpClient = new HttpClient
|
_api = new HttpClient
|
||||||
{
|
{
|
||||||
BaseAddress = new Uri("https://danbooru.donmai.us/")
|
BaseAddress = new Uri("https://danbooru.donmai.us/")
|
||||||
};
|
};
|
||||||
httpClient.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
|
_api.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
|
||||||
|
|
||||||
JsonSerializerSettings settings = new JsonSerializerSettings
|
settings = new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
Formatting = Formatting.Indented,
|
Formatting = Formatting.Indented,
|
||||||
NullValueHandling = NullValueHandling.Ignore
|
NullValueHandling = NullValueHandling.Ignore
|
||||||
};
|
};
|
||||||
|
|
||||||
_api = new RestClient(httpClient)
|
|
||||||
{
|
|
||||||
JsonSerializerSettings = settings
|
|
||||||
}.For<IPostsBooruClient<DanbooruImage>>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<IReadOnlyList<DanbooruImage>> GetImagesAsync(IEnumerable<string> tags)
|
public Task<IReadOnlyList<DanbooruImage>> GetImagesAsync(IEnumerable<string> tags)
|
||||||
=> _api.GetImagesAsync(tags);
|
=> GetImagesAsync(string.Join("%20", tags));
|
||||||
|
|
||||||
public Task<IReadOnlyList<DanbooruImage>> GetImagesAsync(params string[] tags)
|
public Task<IReadOnlyList<DanbooruImage>> GetImagesAsync(params string[] tags)
|
||||||
=> _api.GetImagesAsync(tags);
|
=> GetImagesAsync(string.Join("%20", tags));
|
||||||
|
|
||||||
|
public async Task<IReadOnlyList<DanbooruImage>> GetImagesAsync(string tags)
|
||||||
|
{
|
||||||
|
var get = await _api.GetAsync($"posts.json?tags={tags}").ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (!get.IsSuccessStatusCode)
|
||||||
|
throw new HttpRequestException($"Response failed with reason: \"({get.StatusCode}) {get.ReasonPhrase}\"");
|
||||||
|
|
||||||
|
var content = await get.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
return JsonConvert.DeserializeObject<IReadOnlyList<DanbooruImage>>(content, settings);
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using RestEase;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@@ -7,35 +6,45 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Booru.Net
|
namespace Booru.Net
|
||||||
{
|
{
|
||||||
public class E621Client : IPostsWrappedBooruClient<WrappedPosts<E621Image>>, IDisposable
|
public class E621Client : IDisposable
|
||||||
{
|
{
|
||||||
IPostsWrappedBooruClient<WrappedPosts<E621Image>> _api;
|
private readonly HttpClient _api;
|
||||||
|
private readonly JsonSerializerSettings settings;
|
||||||
|
|
||||||
public E621Client()
|
public E621Client()
|
||||||
{
|
{
|
||||||
var httpClient = new HttpClient
|
_api = new HttpClient
|
||||||
{
|
{
|
||||||
BaseAddress = new Uri("https://e621.net/")
|
BaseAddress = new Uri("https://e621.net/")
|
||||||
};
|
};
|
||||||
httpClient.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
|
_api.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
|
||||||
|
|
||||||
JsonSerializerSettings settings = new JsonSerializerSettings
|
settings = new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
Formatting = Formatting.Indented,
|
Formatting = Formatting.Indented,
|
||||||
NullValueHandling = NullValueHandling.Ignore
|
NullValueHandling = NullValueHandling.Ignore
|
||||||
};
|
};
|
||||||
|
|
||||||
_api = new RestClient(httpClient)
|
|
||||||
{
|
|
||||||
JsonSerializerSettings = settings
|
|
||||||
}.For<IPostsWrappedBooruClient<WrappedPosts<E621Image>>>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<WrappedPosts<E621Image>> GetImagesAsync(IEnumerable<string> tags)
|
public Task<IReadOnlyList<E621Image>> GetImagesAsync(IEnumerable<string> tags)
|
||||||
=> _api.GetImagesAsync(tags);
|
=> GetImagesAsync(string.Join("%20", tags));
|
||||||
|
|
||||||
public Task<WrappedPosts<E621Image>> GetImagesAsync(params string[] tags)
|
public Task<IReadOnlyList<E621Image>> GetImagesAsync(params string[] tags)
|
||||||
=> _api.GetImagesAsync(tags);
|
=> GetImagesAsync(string.Join("%20", tags));
|
||||||
|
|
||||||
|
public async Task<IReadOnlyList<E621Image>> GetImagesAsync(string tags)
|
||||||
|
{
|
||||||
|
var get = await _api.GetAsync($"posts.json?tags={tags}").ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (!get.IsSuccessStatusCode)
|
||||||
|
throw new HttpRequestException($"Response failed with reason: \"({get.StatusCode}) {get.ReasonPhrase}\"");
|
||||||
|
|
||||||
|
var content = await get.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
var posts = JsonConvert.DeserializeObject<WrappedPosts<E621Image>>(content, settings);
|
||||||
|
|
||||||
|
return posts.Posts;
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using RestEase;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@@ -7,35 +6,43 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Booru.Net
|
namespace Booru.Net
|
||||||
{
|
{
|
||||||
public class GelbooruClient : IPHPBooruClient<GelbooruImage>, IDisposable
|
public class GelbooruClient : IDisposable
|
||||||
{
|
{
|
||||||
IPHPBooruClient<GelbooruImage> _api;
|
private readonly HttpClient _api;
|
||||||
|
private readonly JsonSerializerSettings settings;
|
||||||
|
|
||||||
public GelbooruClient()
|
public GelbooruClient()
|
||||||
{
|
{
|
||||||
var httpClient = new HttpClient
|
_api = new HttpClient
|
||||||
{
|
{
|
||||||
BaseAddress = new Uri("https://gelbooru.com/")
|
BaseAddress = new Uri("https://gelbooru.com/")
|
||||||
};
|
};
|
||||||
httpClient.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
|
_api.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
|
||||||
|
|
||||||
JsonSerializerSettings settings = new JsonSerializerSettings
|
settings = new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
Formatting = Formatting.Indented,
|
Formatting = Formatting.Indented,
|
||||||
NullValueHandling = NullValueHandling.Ignore
|
NullValueHandling = NullValueHandling.Ignore
|
||||||
};
|
};
|
||||||
|
|
||||||
_api = new RestClient(httpClient)
|
|
||||||
{
|
|
||||||
JsonSerializerSettings = settings
|
|
||||||
}.For<IPHPBooruClient<GelbooruImage>>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<IReadOnlyList<GelbooruImage>> GetImagesAsync(IEnumerable<string> tags)
|
public Task<IReadOnlyList<GelbooruImage>> GetImagesAsync(IEnumerable<string> tags)
|
||||||
=> _api.GetImagesAsync(tags);
|
=> GetImagesAsync(string.Join("%20", tags));
|
||||||
|
|
||||||
public Task<IReadOnlyList<GelbooruImage>> GetImagesAsync(params string[] tags)
|
public Task<IReadOnlyList<GelbooruImage>> GetImagesAsync(params string[] tags)
|
||||||
=> _api.GetImagesAsync(tags);
|
=> GetImagesAsync(string.Join("%20", tags));
|
||||||
|
|
||||||
|
public async Task<IReadOnlyList<GelbooruImage>> GetImagesAsync(string tags)
|
||||||
|
{
|
||||||
|
var get = await _api.GetAsync($"index.php?page=dapi&s=post&q=index&json=1&tags={tags}").ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (!get.IsSuccessStatusCode)
|
||||||
|
throw new HttpRequestException($"Response failed with reason: \"({get.StatusCode}) {get.ReasonPhrase}\"");
|
||||||
|
|
||||||
|
var content = await get.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
return JsonConvert.DeserializeObject<IReadOnlyList<GelbooruImage>>(content, settings);
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using RestEase;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@@ -7,35 +6,43 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Booru.Net
|
namespace Booru.Net
|
||||||
{
|
{
|
||||||
public class KonaChanClient : IPostBooruClient<KonaChanImage>, IDisposable
|
public class KonaChanClient : IDisposable
|
||||||
{
|
{
|
||||||
IPostBooruClient<KonaChanImage> _api;
|
private readonly HttpClient _api;
|
||||||
|
private readonly JsonSerializerSettings settings;
|
||||||
|
|
||||||
public KonaChanClient()
|
public KonaChanClient()
|
||||||
{
|
{
|
||||||
var httpClient = new HttpClient
|
_api = new HttpClient
|
||||||
{
|
{
|
||||||
BaseAddress = new Uri("https://konachan.com/")
|
BaseAddress = new Uri("https://konachan.com/")
|
||||||
};
|
};
|
||||||
httpClient.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
|
_api.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
|
||||||
|
|
||||||
JsonSerializerSettings settings = new JsonSerializerSettings
|
settings = new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
Formatting = Formatting.Indented,
|
Formatting = Formatting.Indented,
|
||||||
NullValueHandling = NullValueHandling.Ignore
|
NullValueHandling = NullValueHandling.Ignore
|
||||||
};
|
};
|
||||||
|
|
||||||
_api = new RestClient(httpClient)
|
|
||||||
{
|
|
||||||
JsonSerializerSettings = settings
|
|
||||||
}.For<IPostBooruClient<KonaChanImage>>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<IReadOnlyList<KonaChanImage>> GetImagesAsync(IEnumerable<string> tags)
|
public Task<IReadOnlyList<KonaChanImage>> GetImagesAsync(IEnumerable<string> tags)
|
||||||
=> _api.GetImagesAsync(tags);
|
=> GetImagesAsync(string.Join("%20", tags));
|
||||||
|
|
||||||
public Task<IReadOnlyList<KonaChanImage>> GetImagesAsync(params string[] tags)
|
public Task<IReadOnlyList<KonaChanImage>> GetImagesAsync(params string[] tags)
|
||||||
=> _api.GetImagesAsync(tags);
|
=> GetImagesAsync(string.Join("%20", tags));
|
||||||
|
|
||||||
|
public async Task<IReadOnlyList<KonaChanImage>> GetImagesAsync(string tags)
|
||||||
|
{
|
||||||
|
var get = await _api.GetAsync($"post.json?tags={tags}").ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (!get.IsSuccessStatusCode)
|
||||||
|
throw new HttpRequestException($"Response failed with reason: \"({get.StatusCode}) {get.ReasonPhrase}\"");
|
||||||
|
|
||||||
|
var content = await get.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
return JsonConvert.DeserializeObject<IReadOnlyList<KonaChanImage>>(content, settings);
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using RestEase;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@@ -7,35 +6,43 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Booru.Net
|
namespace Booru.Net
|
||||||
{
|
{
|
||||||
public class RealbooruClient : IPHPBooruClient<RealbooruImage>, IDisposable
|
public class RealbooruClient : IDisposable
|
||||||
{
|
{
|
||||||
IPHPBooruClient<RealbooruImage> _api;
|
HttpClient _api;
|
||||||
|
JsonSerializerSettings settings;
|
||||||
|
|
||||||
public RealbooruClient()
|
public RealbooruClient()
|
||||||
{
|
{
|
||||||
var httpClient = new HttpClient
|
_api = new HttpClient
|
||||||
{
|
{
|
||||||
BaseAddress = new Uri("https://realbooru.com/")
|
BaseAddress = new Uri("https://realbooru.com/")
|
||||||
};
|
};
|
||||||
httpClient.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
|
_api.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
|
||||||
|
|
||||||
JsonSerializerSettings settings = new JsonSerializerSettings
|
settings = new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
Formatting = Formatting.Indented,
|
Formatting = Formatting.Indented,
|
||||||
NullValueHandling = NullValueHandling.Ignore
|
NullValueHandling = NullValueHandling.Ignore
|
||||||
};
|
};
|
||||||
|
|
||||||
_api = new RestClient(httpClient)
|
|
||||||
{
|
|
||||||
JsonSerializerSettings = settings
|
|
||||||
}.For<IPHPBooruClient<RealbooruImage>>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IReadOnlyList<RealbooruImage>> GetImagesAsync(IEnumerable<string> tags)
|
public Task<IReadOnlyList<RealbooruImage>> GetImagesAsync(IEnumerable<string> tags)
|
||||||
=> await _api.GetImagesAsync(tags).ConfigureAwait(false);
|
=> GetImagesAsync(string.Join("%20", tags));
|
||||||
|
|
||||||
public async Task<IReadOnlyList<RealbooruImage>> GetImagesAsync(params string[] tags)
|
public Task<IReadOnlyList<RealbooruImage>> GetImagesAsync(params string[] tags)
|
||||||
=> await _api.GetImagesAsync(tags).ConfigureAwait(false);
|
=> GetImagesAsync(string.Join("%20", tags));
|
||||||
|
|
||||||
|
public async Task<IReadOnlyList<RealbooruImage>> GetImagesAsync(string tags)
|
||||||
|
{
|
||||||
|
var get = await _api.GetAsync($"index.php?page=dapi&s=post&q=index&json=1&tags={tags}").ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (!get.IsSuccessStatusCode)
|
||||||
|
throw new HttpRequestException($"Response failed with reason: \"({get.StatusCode}) {get.ReasonPhrase}\"");
|
||||||
|
|
||||||
|
var content = await get.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
return JsonConvert.DeserializeObject<IReadOnlyList<RealbooruImage>>(content, settings);
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using RestEase;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@@ -7,35 +6,43 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Booru.Net
|
namespace Booru.Net
|
||||||
{
|
{
|
||||||
public class Rule34Client : IPHPBooruClient<Rule34Image>, IDisposable
|
public class Rule34Client : IDisposable
|
||||||
{
|
{
|
||||||
IPHPBooruClient<Rule34Image> _api;
|
private readonly HttpClient _api;
|
||||||
|
private readonly JsonSerializerSettings settings;
|
||||||
|
|
||||||
public Rule34Client()
|
public Rule34Client()
|
||||||
{
|
{
|
||||||
var httpClient = new HttpClient
|
_api = new HttpClient
|
||||||
{
|
{
|
||||||
BaseAddress = new Uri("https://rule34.xxx/")
|
BaseAddress = new Uri("https://rule34.xxx/")
|
||||||
};
|
};
|
||||||
httpClient.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
|
_api.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
|
||||||
|
|
||||||
JsonSerializerSettings settings = new JsonSerializerSettings
|
settings = new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
Formatting = Formatting.Indented,
|
Formatting = Formatting.Indented,
|
||||||
NullValueHandling = NullValueHandling.Ignore
|
NullValueHandling = NullValueHandling.Ignore
|
||||||
};
|
};
|
||||||
|
|
||||||
_api = new RestClient(httpClient)
|
|
||||||
{
|
|
||||||
JsonSerializerSettings = settings
|
|
||||||
}.For<IPHPBooruClient<Rule34Image>>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<IReadOnlyList<Rule34Image>> GetImagesAsync(IEnumerable<string> tags)
|
public Task<IReadOnlyList<Rule34Image>> GetImagesAsync(IEnumerable<string> tags)
|
||||||
=> _api.GetImagesAsync(tags);
|
=> GetImagesAsync(string.Join("%20", tags));
|
||||||
|
|
||||||
public Task<IReadOnlyList<Rule34Image>> GetImagesAsync(params string[] tags)
|
public Task<IReadOnlyList<Rule34Image>> GetImagesAsync(params string[] tags)
|
||||||
=> _api.GetImagesAsync(tags);
|
=> GetImagesAsync(string.Join("%20", tags));
|
||||||
|
|
||||||
|
public async Task<IReadOnlyList<Rule34Image>> GetImagesAsync(string tags)
|
||||||
|
{
|
||||||
|
var get = await _api.GetAsync($"index.php?page=dapi&s=post&q=index&json=1&tags={tags}").ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (!get.IsSuccessStatusCode)
|
||||||
|
throw new HttpRequestException($"Response failed with reason: \"({get.StatusCode}) {get.ReasonPhrase}\"");
|
||||||
|
|
||||||
|
var content = await get.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
return JsonConvert.DeserializeObject<IReadOnlyList<Rule34Image>>(content, settings);
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using RestEase;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@@ -7,35 +6,43 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Booru.Net
|
namespace Booru.Net
|
||||||
{
|
{
|
||||||
public class SafebooruClient : IPHPBooruClient<SafebooruImage>, IDisposable
|
public class SafebooruClient : IDisposable
|
||||||
{
|
{
|
||||||
IPHPBooruClient<SafebooruImage> _api;
|
private readonly HttpClient _api;
|
||||||
|
private readonly JsonSerializerSettings settings;
|
||||||
|
|
||||||
public SafebooruClient()
|
public SafebooruClient()
|
||||||
{
|
{
|
||||||
var httpClient = new HttpClient
|
_api = new HttpClient
|
||||||
{
|
{
|
||||||
BaseAddress = new Uri("https://safebooru.org/")
|
BaseAddress = new Uri("https://safebooru.org/")
|
||||||
};
|
};
|
||||||
httpClient.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
|
_api.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
|
||||||
|
|
||||||
JsonSerializerSettings settings = new JsonSerializerSettings
|
settings = new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
Formatting = Formatting.Indented,
|
Formatting = Formatting.Indented,
|
||||||
NullValueHandling = NullValueHandling.Ignore
|
NullValueHandling = NullValueHandling.Ignore
|
||||||
};
|
};
|
||||||
|
|
||||||
_api = new RestClient(httpClient)
|
|
||||||
{
|
|
||||||
JsonSerializerSettings = settings
|
|
||||||
}.For<IPHPBooruClient<SafebooruImage>>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<IReadOnlyList<SafebooruImage>> GetImagesAsync(IEnumerable<string> tags)
|
public Task<IReadOnlyList<SafebooruImage>> GetImagesAsync(IEnumerable<string> tags)
|
||||||
=> _api.GetImagesAsync(tags);
|
=> GetImagesAsync(string.Join("%20", tags));
|
||||||
|
|
||||||
public Task<IReadOnlyList<SafebooruImage>> GetImagesAsync(params string[] tags)
|
public Task<IReadOnlyList<SafebooruImage>> GetImagesAsync(params string[] tags)
|
||||||
=> _api.GetImagesAsync(tags);
|
=> GetImagesAsync(string.Join("%20", tags));
|
||||||
|
|
||||||
|
public async Task<IReadOnlyList<SafebooruImage>> GetImagesAsync(string tags)
|
||||||
|
{
|
||||||
|
var get = await _api.GetAsync($"index.php?page=dapi&s=post&q=index&json=1&tags={tags}").ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (!get.IsSuccessStatusCode)
|
||||||
|
throw new HttpRequestException($"Response failed with reason: \"({get.StatusCode}) {get.ReasonPhrase}\"");
|
||||||
|
|
||||||
|
var content = await get.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
return JsonConvert.DeserializeObject<IReadOnlyList<SafebooruImage>>(content, settings);
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using RestEase;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@@ -7,35 +6,43 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Booru.Net
|
namespace Booru.Net
|
||||||
{
|
{
|
||||||
public class YandereClient : IPostBooruClient<YandereImage>, IDisposable
|
public class YandereClient : IDisposable
|
||||||
{
|
{
|
||||||
IPostBooruClient<YandereImage> _api;
|
private readonly HttpClient _api;
|
||||||
|
private readonly JsonSerializerSettings settings;
|
||||||
|
|
||||||
public YandereClient()
|
public YandereClient()
|
||||||
{
|
{
|
||||||
var httpClient = new HttpClient
|
_api = new HttpClient
|
||||||
{
|
{
|
||||||
BaseAddress = new Uri("https://yande.re/")
|
BaseAddress = new Uri("https://yande.re/")
|
||||||
};
|
};
|
||||||
httpClient.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
|
_api.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
|
||||||
|
|
||||||
JsonSerializerSettings settings = new JsonSerializerSettings
|
settings = new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
Formatting = Formatting.Indented,
|
Formatting = Formatting.Indented,
|
||||||
NullValueHandling = NullValueHandling.Ignore
|
NullValueHandling = NullValueHandling.Ignore
|
||||||
};
|
};
|
||||||
|
|
||||||
_api = new RestClient(httpClient)
|
|
||||||
{
|
|
||||||
JsonSerializerSettings = settings
|
|
||||||
}.For<IPostBooruClient<YandereImage>>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<IReadOnlyList<YandereImage>> GetImagesAsync(IEnumerable<string> tags)
|
public Task<IReadOnlyList<YandereImage>> GetImagesAsync(IEnumerable<string> tags)
|
||||||
=> _api.GetImagesAsync(tags);
|
=> GetImagesAsync(string.Join("%20", tags));
|
||||||
|
|
||||||
public Task<IReadOnlyList<YandereImage>> GetImagesAsync(params string[] tags)
|
public Task<IReadOnlyList<YandereImage>> GetImagesAsync(params string[] tags)
|
||||||
=> _api.GetImagesAsync(tags);
|
=> GetImagesAsync(string.Join("%20", tags));
|
||||||
|
|
||||||
|
public async Task<IReadOnlyList<YandereImage>> GetImagesAsync(string tags)
|
||||||
|
{
|
||||||
|
var get = await _api.GetAsync($"post.json?tags={tags}").ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (!get.IsSuccessStatusCode)
|
||||||
|
throw new HttpRequestException($"Response failed with reason: \"({get.StatusCode}) {get.ReasonPhrase}\"");
|
||||||
|
|
||||||
|
var content = await get.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
return JsonConvert.DeserializeObject<IReadOnlyList<YandereImage>>(content, settings);
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
using RestEase;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Booru.Net
|
|
||||||
{
|
|
||||||
public interface IIndexBooruClient<T> : IDisposable
|
|
||||||
{
|
|
||||||
[Get("index.json")]
|
|
||||||
public Task<IReadOnlyList<T>> GetImagesAsync([Query("tags")] IEnumerable<string> tags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using RestEase;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Booru.Net
|
|
||||||
{
|
|
||||||
public interface IPHPBooruClient<T> : IDisposable
|
|
||||||
{
|
|
||||||
[Get("index.php?page=dapi&s=post&q=index&json=1")]
|
|
||||||
public Task<IReadOnlyList<T>> GetImagesAsync([Query("tags")] IEnumerable<string> tags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using RestEase;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Booru.Net
|
|
||||||
{
|
|
||||||
public interface IPostBooruClient<T> : IDisposable
|
|
||||||
{
|
|
||||||
[Get("post.json")]
|
|
||||||
public Task<IReadOnlyList<T>> GetImagesAsync([Query("tags")] IEnumerable<string> tags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using RestEase;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Booru.Net
|
|
||||||
{
|
|
||||||
public interface IPostsBooruClient<T> : IDisposable
|
|
||||||
{
|
|
||||||
[Get("posts.json")]
|
|
||||||
public Task<IReadOnlyList<T>> GetImagesAsync([Query("tags")] IEnumerable<string> tags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using RestEase;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Booru.Net
|
|
||||||
{
|
|
||||||
public interface IPostsWrappedBooruClient<T> : IDisposable
|
|
||||||
{
|
|
||||||
[Get("posts.json")]
|
|
||||||
public Task<T> GetImagesAsync([Query("tags")] IEnumerable<string> tags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user