From 03e9182cb171d14a2d099c4bd525d28b59bc648e Mon Sep 17 00:00:00 2001 From: h7x4 Date: Thu, 11 Jun 2020 11:50:16 +0200 Subject: [PATCH] Fix some bugs --- lib/src/objects.dart | 42 +++++++++++++++++++++----- lib/src/unofficial_jisho_api_base.dart | 6 ++-- test/local_function_test_cases.dart | 14 ++++----- test/unofficial_jisho_api_test.dart | 2 +- 4 files changed, 46 insertions(+), 18 deletions(-) diff --git a/lib/src/objects.dart b/lib/src/objects.dart index 0835307..ccce5ac 100644 --- a/lib/src/objects.dart +++ b/lib/src/objects.dart @@ -96,12 +96,12 @@ class Radical { this.meaning = meaning; } - Map toJson() => - { - 'symbol': symbol, - 'forms': forms, - 'meaning': meaning - }; + Map toJson() => + { + if (symbol != null) 'symbol': symbol, + if (forms != null) 'forms': forms, + if (meaning != null) 'meaning': meaning + }; } @@ -116,14 +116,42 @@ class KanjiResult { String meaning; List kunyomi; List onyomi; - List onyomiExamples; List kunyomiExamples; + List onyomiExamples; Radical radical; List parts; String strokeOrderDiagramUri; String strokeOrderSvgUri; String strokeOrderGifUri; String uri; + + Map toJson() { + + if (found == false) return { + 'query': query, + 'found': found + }; + + return { + 'query': query, + 'found': found, + 'taughtIn': taughtIn, + 'jlptLevel': jlptLevel, + 'newspaperFrequencyRank': newspaperFrequencyRank.toString(), + 'strokeCount': strokeCount, + 'meaning': meaning, + 'kunyomi': kunyomi, + 'onyomi': onyomi, + 'onyomiExamples': onyomiExamples.map((onyomiExample) => onyomiExample.toJson()).toList(), + 'kunyomiExamples': kunyomiExamples.map((kunyomiExample) => kunyomiExample.toJson()).toList(), + 'radical': radical.toJson(), + 'parts': parts, + 'strokeOrderDiagramUri': strokeOrderDiagramUri, + 'strokeOrderSvgUri': strokeOrderSvgUri, + 'strokeOrderGifUri': strokeOrderGifUri, + 'uri': uri + }; + } } class ExampleSentencePiece { diff --git a/lib/src/unofficial_jisho_api_base.dart b/lib/src/unofficial_jisho_api_base.dart index cd9a1a0..0485df2 100644 --- a/lib/src/unofficial_jisho_api_base.dart +++ b/lib/src/unofficial_jisho_api_base.dart @@ -8,9 +8,9 @@ final htmlUnescape = html_entities.HtmlUnescape(); // TODO: Put public facing types in this file. -const String JISHO_API = 'https://jisho.org/api/v1/search/words'; -const String SCRAPE_BASE_URI = 'https://jisho.org/search/'; -const String STROKE_ORDER_DIAGRAM_BASE_URI = 'https://classic.jisho.org/static/images/stroke_diagrams/'; +const String JISHO_API = 'http://jisho.org/api/v1/search/words'; +const String SCRAPE_BASE_URI = 'http://jisho.org/search/'; +const String STROKE_ORDER_DIAGRAM_BASE_URI = 'http://classic.jisho.org/static/images/stroke_diagrams/'; /* KANJI SEARCH FUNCTIONS START */ diff --git a/test/local_function_test_cases.dart b/test/local_function_test_cases.dart index bc331ff..d02c1e3 100644 --- a/test/local_function_test_cases.dart +++ b/test/local_function_test_cases.dart @@ -17,20 +17,20 @@ void test_local_functions() async { test('uriForKanjiSearch', () { final result = uriForKanjiSearch('時'); - expect(result, 'https://jisho.org/search/%E6%99%82%23kanji'); + expect(result, 'http://jisho.org/search/%E6%99%82%23kanji'); }); test('getUriForStrokeOrderDiagram', () { final result = getUriForStrokeOrderDiagram('時'); - expect(result, 'https://classic.jisho.org/static/images/stroke_diagrams/26178_frames.png'); + expect(result, 'http://classic.jisho.org/static/images/stroke_diagrams/26178_frames.png'); }); test('uriForPhraseSearch', () { final result = uriForPhraseSearch('時間'); - expect(result, 'https://jisho.org/api/v1/search/words?keyword=%E6%99%82%E9%96%93'); + expect(result, 'http://jisho.org/api/v1/search/words?keyword=%E6%99%82%E9%96%93'); }); - final kanjiPage = (await http.get('https://jisho.org/search/%E6%99%82%23kanji')).body; + final kanjiPage = (await http.get('http://jisho.org/search/%E6%99%82%23kanji')).body; test('containsKanjiGlyph', () { final result = containsKanjiGlyph(kanjiPage, '時'); @@ -277,10 +277,10 @@ void test_local_functions() async { meaning: 'sun, day' ); expectedResult.parts = ['土', '寸', '日']; - expectedResult.strokeOrderDiagramUri = 'https://classic.jisho.org/static/images/stroke_diagrams/26178_frames.png'; + expectedResult.strokeOrderDiagramUri = 'http://classic.jisho.org/static/images/stroke_diagrams/26178_frames.png'; expectedResult.strokeOrderSvgUri = 'http://d1w6u4xc3l95km.cloudfront.net/kanji-2015-03/06642.svg'; - expectedResult.strokeOrderGifUri = 'https://raw.githubusercontent.com/mistval/kanji_images/master/gifs/3c.gif'; - expectedResult.uri = 'https://jisho.org/search/%E6%99%82%23kanji'; + expectedResult.strokeOrderGifUri = 'https://raw.githubusercontent.com/mistval/kanji_images/master/gifs/6642.gif'; + expectedResult.uri = 'http://jisho.org/search/%E6%99%82%23kanji'; expect( json.encode(result), diff --git a/test/unofficial_jisho_api_test.dart b/test/unofficial_jisho_api_test.dart index dca8ac6..fd570b0 100644 --- a/test/unofficial_jisho_api_test.dart +++ b/test/unofficial_jisho_api_test.dart @@ -22,7 +22,7 @@ void runTestCases(List testCaseFiles, String apiFunction) async { switch(apiFunction) { case 'searchForKanji': { final result = await jisho.searchForKanji(testCase['query']); - expect(result, jsonDecode(testCase['expectedResult'])); + expect(result.toJson(), testCase['expectedResult']); break; } case 'searchForExamples': {