diff --git a/JishoNET.Tests/Tests.cs b/JishoNET.Tests/Tests.cs index 76f5c95..e437226 100644 --- a/JishoNET.Tests/Tests.cs +++ b/JishoNET.Tests/Tests.cs @@ -12,23 +12,23 @@ public class Tests public void GetNormalDefinition() { JishoClient client = new JishoClient(); - JishoResult> 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 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"); } } } diff --git a/JishoNET/JishoClient.cs b/JishoNET/JishoClient.cs index 6ab8a9e..5e4e801 100644 --- a/JishoNET/JishoClient.cs +++ b/JishoNET/JishoClient.cs @@ -17,7 +17,7 @@ public class JishoClient /// /// Keyword used as a search term to find definitions /// containing all definitions - public JishoResult> GetDefinition(String keyword) + public JishoResult GetDefinition(String keyword) { try { @@ -27,13 +27,13 @@ public JishoResult> GetDefinition(String keyword) webClient.Encoding = System.Text.Encoding.UTF8; String jsonResponse = webClient.DownloadString(new Uri(BaseUrl + keyword)); - JishoResult> result = JsonSerializer.Deserialize>>(jsonResponse); + JishoResult result = JsonSerializer.Deserialize(jsonResponse); result.Success = true; return result; } catch (Exception e) { - return new JishoResult>() + return new JishoResult() { Success = false, Exception = e.ToString() @@ -46,18 +46,18 @@ public JishoResult> GetDefinition(String keyword) /// /// Keyword used as a search term to quickly retrieve an English and a Reading /// containing the top English and Reading of the search term OR null if no definition was found - public JishoResult GetQuickDefinition(String keyword) + public JishoQuickDefinition GetQuickDefinition(String keyword) { try { - JishoResult result = new JishoResult(); - 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() + return new JishoQuickDefinition() { Success = false, Exception = e.ToString() diff --git a/JishoNET/JishoNET.csproj b/JishoNET/JishoNET.csproj index cb99295..fd81c3a 100644 --- a/JishoNET/JishoNET.csproj +++ b/JishoNET/JishoNET.csproj @@ -5,9 +5,9 @@ true JishoNET JishoNET - 1.1.0 + 1.2.1 Myuuiii - SubSilence + Myuuiii Software Development Simple wrapper for the Japanese Jisho.org Dictionary API icon.png icon.png diff --git a/JishoNET/Models/JishoQuickDefinition.cs b/JishoNET/Models/JishoQuickDefinition.cs index 9100c32..1c2ed64 100644 --- a/JishoNET/Models/JishoQuickDefinition.cs +++ b/JishoNET/Models/JishoQuickDefinition.cs @@ -11,13 +11,13 @@ public JishoQuickDefinition() { } /// /// Create a new from a /// - public JishoQuickDefinition(JishoResult> 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]; diff --git a/JishoNET/Models/JishoResult.cs b/JishoNET/Models/JishoResult.cs index a7dfb46..4b03519 100644 --- a/JishoNET/Models/JishoResult.cs +++ b/JishoNET/Models/JishoResult.cs @@ -4,30 +4,30 @@ namespace JishoNET.Models { - public class JishoResult - { - /// - /// Meta data that is returned by the API - /// - [JsonPropertyName("meta")] - public JishoMeta Meta { get; set; } + public class JishoResult + { + /// + /// Meta data that is returned by the API + /// + [JsonPropertyName("meta")] + public JishoMeta Meta { get; set; } - /// - /// List of definitions that were returned by the API using the given search term keyword - /// - [JsonPropertyName("data")] - public T Data { get; set; } + /// + /// Array of definitions that were returned by the API using the given search term keyword + /// + [JsonPropertyName("data")] + public JishoDefinition[] Data { get; set; } - /// - /// Indicates if the request was executed successfully - /// - [JsonIgnore] - public Boolean Success { get; set; } + /// + /// Indicates if the request was executed successfully + /// + [JsonIgnore] + public Boolean Success { get; set; } - /// - /// Any exception information, this will only be provided if something goes wrong during the creation or processing of your request - /// - [JsonIgnore] - public String Exception { get; set; } - } + /// + /// Any exception information, this will only be provided if something goes wrong during the creation or processing of your request + /// + [JsonIgnore] + public String Exception { get; set; } + } } \ No newline at end of file diff --git a/readme.md b/readme.md index d37618b..9e14b0f 100644 --- a/readme.md +++ b/readme.md @@ -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> 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 qDefinition = client.GetQuickDefinition("house"); +JishoQuickDefinition qDefinition = client.GetQuickDefinition("house"); ```