Repo for the search and displace core module including the interface to select files and search and displace operations to run on them. https://searchanddisplace.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
858 B

  1. <?php
  2. namespace App\SearchDisplace\Searchers;
  3. use GuzzleHttp\Client;
  4. class Duckling
  5. {
  6. protected $url;
  7. public function __construct()
  8. {
  9. $this->url = env('SD_DUCKLING_URL');
  10. }
  11. public function execute($content, $dimensions)
  12. {
  13. // @TODO Parse result
  14. return $this->sendRequest($content, $dimensions);
  15. }
  16. protected function sendRequest($text, $dimensions)
  17. {
  18. $client = new Client();
  19. $response = $client->request('post', $this->url, [
  20. 'headers' => [
  21. 'Accept' => 'application/json',
  22. ],
  23. 'form_params' => [
  24. 'locale' => 'en_GB',
  25. 'text' => $text,
  26. 'dims' => json_encode($dimensions),
  27. ],
  28. ]);
  29. return json_decode($response->getBody()->getContents(), true);
  30. }
  31. }