Skip to content

Commit

Permalink
1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Myuuiii committed Dec 3, 2021
1 parent 336b245 commit 48e31e3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
10 changes: 5 additions & 5 deletions JishoNET.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ public class Tests
public void GetNormalDefinition()
{
JishoClient client = new JishoClient();
JishoResult<List<JishoDefinition>> result = client.GetDefinition("川口");
JishoResult result = client.GetDefinition("川口");

Assert.IsTrue(result.Success, "The request was not successful");
Assert.IsNull(result.Exception, "An exception occurred whilst executing the request");
Assert.IsTrue(result.Data.Count > 0, "The result did not contain any data");
Assert.IsTrue(result.Data.Length > 0, "The result did not contain any data");
}

[TestMethod("Get Quick Definition")]
public void GetQuickDefinition()
{
JishoClient client = new JishoClient();
JishoResult<JishoQuickDefinition> qDef = client.GetQuickDefinition("川口");
JishoQuickDefinition qDef = client.GetQuickDefinition("川口");

Assert.IsTrue(qDef.Success, "The request was not successful");
Assert.IsNull(qDef.Exception, "An exception occurred whilst executing the request");
Assert.IsNotNull(qDef.Data.JapaneseReading, "The Japanese Reading was null");
Assert.IsNotNull(qDef.Data.EnglishSense, "The English Definition was null");
Assert.IsNotNull(qDef.JapaneseReading, "The Japanese Reading was null");
Assert.IsNotNull(qDef.EnglishSense, "The English Definition was null");
}
}
}
14 changes: 7 additions & 7 deletions JishoNET/JishoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class JishoClient
/// </summary>
/// <param name="keyword">Keyword used as a search term to find definitions</param>
/// <returns><see cref="JishoResult" /> containing all definitions</returns>
public JishoResult<List<JishoDefinition>> GetDefinition(String keyword)
public JishoResult GetDefinition(String keyword)
{
try
{
Expand All @@ -27,13 +27,13 @@ public JishoResult<List<JishoDefinition>> GetDefinition(String keyword)
webClient.Encoding = System.Text.Encoding.UTF8;

String jsonResponse = webClient.DownloadString(new Uri(BaseUrl + keyword));
JishoResult<List<JishoDefinition>> result = JsonSerializer.Deserialize<JishoResult<List<JishoDefinition>>>(jsonResponse);
JishoResult result = JsonSerializer.Deserialize<JishoResult>(jsonResponse);
result.Success = true;
return result;
}
catch (Exception e)
{
return new JishoResult<List<JishoDefinition>>()
return new JishoResult()
{
Success = false,
Exception = e.ToString()
Expand All @@ -46,18 +46,18 @@ public JishoResult<List<JishoDefinition>> GetDefinition(String keyword)
/// </summary>
/// <param name="keyword">Keyword used as a search term to quickly retrieve an English <see cref="JishoEnglishSense" /> and a <see cref="JishoJapaneseDefinition" /> Reading</param>
/// <returns><see cref="JishoQuickDefinition" /> containing the top English <see cref="JishoEnglishSense" /> and <see cref="JishoJapaneseDefinition" /> Reading of the search term OR null if no definition was found</returns>
public JishoResult<JishoQuickDefinition> GetQuickDefinition(String keyword)
public JishoQuickDefinition GetQuickDefinition(String keyword)
{
try
{
JishoResult<JishoQuickDefinition> result = new JishoResult<JishoQuickDefinition>();
result.Data = new JishoQuickDefinition(GetDefinition(keyword));
JishoQuickDefinition result = new JishoQuickDefinition();
result = new JishoQuickDefinition(GetDefinition(keyword));
result.Success = true;
return result;
}
catch (Exception e)
{
return new JishoResult<JishoQuickDefinition>()
return new JishoQuickDefinition()
{
Success = false,
Exception = e.ToString()
Expand Down
4 changes: 2 additions & 2 deletions JishoNET/JishoNET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>JishoNET</Title>
<PackageId>JishoNET</PackageId>
<Version>1.1.0</Version>
<Version>1.2.1</Version>
<Authors>Myuuiii</Authors>
<Company>SubSilence</Company>
<Company>Myuuiii Software Development</Company>
<Description>Simple wrapper for the Japanese Jisho.org Dictionary API</Description>
<PackageIconUrl>icon.png</PackageIconUrl>
<PackageIcon>icon.png</PackageIcon>
Expand Down
4 changes: 2 additions & 2 deletions JishoNET/Models/JishoQuickDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ public JishoQuickDefinition() { }
/// <summary>
/// Create a new <see cref="JishoQuickDefinition" /> from a <see cref="JishoResult" />
/// </summary>
public JishoQuickDefinition(JishoResult<List<JishoDefinition>> result)
public JishoQuickDefinition(JishoResult result)
{

this.Meta = result.Meta;
this.Success = result.Success;
this.Exception = result.Exception;
if (result.Data.Count != 0 && result.Success && result.Meta.Status == 200)
if (result.Data.Length != 0 && result.Success && result.Meta.Status == 200)
{
this.EnglishSense = result.Data[0].Senses[0];
this.JapaneseReading = result.Data[0].Japanese[0];
Expand Down
46 changes: 23 additions & 23 deletions JishoNET/Models/JishoResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@

namespace JishoNET.Models
{
public class JishoResult<T>
{
/// <summary>
/// Meta data that is returned by the API
/// </summary>
[JsonPropertyName("meta")]
public JishoMeta Meta { get; set; }
public class JishoResult
{
/// <summary>
/// Meta data that is returned by the API
/// </summary>
[JsonPropertyName("meta")]
public JishoMeta Meta { get; set; }

/// <summary>
/// List of definitions that were returned by the API using the given search term keyword
/// </summary>
[JsonPropertyName("data")]
public T Data { get; set; }
/// <summary>
/// Array of definitions that were returned by the API using the given search term keyword
/// </summary>
[JsonPropertyName("data")]
public JishoDefinition[] Data { get; set; }

/// <summary>
/// Indicates if the request was executed successfully
/// </summary>
[JsonIgnore]
public Boolean Success { get; set; }
/// <summary>
/// Indicates if the request was executed successfully
/// </summary>
[JsonIgnore]
public Boolean Success { get; set; }

/// <summary>
/// Any exception information, this will only be provided if something goes wrong during the creation or processing of your request
/// </summary>
[JsonIgnore]
public String Exception { get; set; }
}
/// <summary>
/// Any exception information, this will only be provided if something goes wrong during the creation or processing of your request
/// </summary>
[JsonIgnore]
public String Exception { get; set; }
}
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ Using this client you can start retrieving definitions.
## Retrieving a definition
On the instance of `JishoClient` you just created you can execute the `GetDefinition` method. As the argument for this method you provide the "keyword" to use in the search. This can be any English or Japanese word. The `GetDefinition` returns a `JishoResult` which will contain all the data sent back by the API.
```cs
JishoResult<List<JishoDefinition>> result = client.GetDefinition("house");
JishoResult result = client.GetDefinition("house");
```

## Retrieving a quick definition
A quick definition contains the top result from a query, the result will contain an English `Sense` object and a `Japanese` reading object.
```cs
JishoResult<JishoQuickDefinition> qDefinition = client.GetQuickDefinition("house");
JishoQuickDefinition qDefinition = client.GetQuickDefinition("house");
```


Expand Down

0 comments on commit 48e31e3

Please sign in to comment.