diff --git a/src/Dictionary/DictionaryContext.php b/src/Dictionary/DictionaryContext.php index 1ac45e6..f7ddc6a 100644 --- a/src/Dictionary/DictionaryContext.php +++ b/src/Dictionary/DictionaryContext.php @@ -2,6 +2,7 @@ namespace Satori\Dictionary; use Syokuhou\IConfig; +use Satori\SHttp; class DictionaryContext { private IConfig $config; @@ -15,13 +16,13 @@ class DictionaryContext { } public function defineWord(string $word): array { - $data = json_decode(file_get_contents(sprintf( + $data = SHttp::getJson(sprintf( 'https://api.wordnik.com/v4/word.json/%s/definitions?limit=5&includeRelated=false&sourceDictionaries=ahd-5%%2Cwordnet&useCanonical=true&includeTags=false&api_key=%s', rawurlencode($word), $this->config->getString('token') - )), true); + )); - if(empty($data)) + if(empty($data) || !empty($data['statusCode'])) return []; $results = []; diff --git a/src/ExRate/ExRateContext.php b/src/ExRate/ExRateContext.php index 3b64ee5..de9db83 100644 --- a/src/ExRate/ExRateContext.php +++ b/src/ExRate/ExRateContext.php @@ -3,6 +3,7 @@ namespace Satori\ExRate; use Index\Data\IDbConnection; use Syokuhou\IConfig; +use Satori\SHttp; class ExRateContext { private const BASE_CURRENCY = 'EUR'; @@ -41,11 +42,11 @@ class ExRateContext { public function refreshRates(): void { // HTTPS is a paid feature????????? - $data = json_decode(file_get_contents(sprintf( + $data = SHttp::getJsonCached(sprintf( 'http://api.exchangerate.host/live?source=%s&access_key=%s', self::BASE_CURRENCY, $this->config->getString('token') - )), true); + )); if(empty($data) || !$data['success']) return;