mirror of
https://github.com/h7x4/unofficial_jisho_api_dart.git
synced 2025-09-21 04:55:56 +02:00
Reformat
This commit is contained in:
21
lib/api.dart
21
lib/api.dart
@@ -1,8 +1,9 @@
|
||||
/// This library provides search functions for searching/scraping Jisho.org.
|
||||
///
|
||||
///
|
||||
/// It provides a built-in http client and performs async requests to the server
|
||||
/// for different types of requests.
|
||||
library unofficial_jisho_api;
|
||||
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
@@ -13,28 +14,34 @@ import './src/phraseScrape.dart';
|
||||
import './src/phraseSearch.dart';
|
||||
|
||||
/// Query the official Jisho API for a word or phrase
|
||||
///
|
||||
///
|
||||
/// See https://jisho.org/forum/54fefc1f6e73340b1f160000-is-there-any-kind-of-search-api
|
||||
/// for discussion about the official API.
|
||||
Future<JishoAPIResult> searchForPhrase(String phrase) async {
|
||||
final uri = uriForPhraseSearch(phrase);
|
||||
return await http.get(uri).then((response) => JishoAPIResult.fromJson(jsonDecode(response.body)));
|
||||
return await http
|
||||
.get(uri)
|
||||
.then((response) => JishoAPIResult.fromJson(jsonDecode(response.body)));
|
||||
}
|
||||
|
||||
/// Scrape Jisho.org for information about a kanji character.
|
||||
Future<KanjiResult> searchForKanji(String kanji) async {
|
||||
final uri = uriForKanjiSearch(kanji);
|
||||
return http.get(uri).then((response) => parseKanjiPageData(response.body, kanji));
|
||||
return http
|
||||
.get(uri)
|
||||
.then((response) => parseKanjiPageData(response.body, kanji));
|
||||
}
|
||||
|
||||
/// Scrape Jisho.org for examples.
|
||||
Future<ExampleResults> searchForExamples(String phrase) async {
|
||||
final uri = uriForExampleSearch(phrase);
|
||||
return http.get(uri).then((response) => parseExamplePageData(response.body, phrase));
|
||||
return http
|
||||
.get(uri)
|
||||
.then((response) => parseExamplePageData(response.body, phrase));
|
||||
}
|
||||
|
||||
/// Scrape the word page for a word/phrase.
|
||||
///
|
||||
///
|
||||
/// This allows you to get some information that isn't provided by the official API, such as
|
||||
/// part-of-speech and JLPT level. However, the official API should be preferred
|
||||
/// if it has the information you need. This function scrapes https://jisho.org/word/XXX.
|
||||
@@ -50,4 +57,4 @@ Future<PhrasePageScrapeResult> scrapeForPhrase(String phrase) async {
|
||||
);
|
||||
}
|
||||
return parsePhrasePageData(response.body, phrase);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user