1 | <?php |
||
17 | class JsonProvider implements LoggerAwareInterface |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * Logger instance |
||
22 | * |
||
23 | * @var LoggerInterface |
||
24 | */ |
||
25 | private $logger; |
||
26 | |||
27 | /** |
||
28 | * Timeout in seconds |
||
29 | * |
||
30 | * @var int |
||
31 | */ |
||
32 | private $timeout = 5; |
||
33 | |||
34 | /** |
||
35 | * |
||
36 | * @var HttpClient |
||
37 | */ |
||
38 | private $httpClient; |
||
39 | |||
40 | 4 | public function __construct() |
|
44 | |||
45 | /** |
||
46 | * Set timeout in seconds |
||
47 | * |
||
48 | * @param int $timeout |
||
49 | */ |
||
50 | public function setTimeout(int $timeout) |
||
54 | |||
55 | /** |
||
56 | * Query the duck duck go api |
||
57 | * |
||
58 | * @param string $query |
||
59 | * Keywords to start a query for |
||
60 | * @throws ApiException |
||
61 | * @return string The payload |
||
62 | */ |
||
63 | 3 | public function query(string $query): string |
|
87 | |||
88 | 3 | private function createHttpClient(string $query) |
|
96 | |||
97 | /** |
||
98 | * Provide an URL object out of given duckduckgo query |
||
99 | * |
||
100 | * @param string $query |
||
101 | * @return Url |
||
102 | */ |
||
103 | 3 | private function provideUrl(string $query): Url |
|
109 | |||
110 | /** |
||
111 | * Set the logger |
||
112 | * |
||
113 | * @param LoggerInterface $logger |
||
114 | */ |
||
115 | 4 | public function setLogger(LoggerInterface $logger) |
|
119 | } |
||
120 |