1 | <?php |
||
17 | class JsonProvider implements LoggerAwareInterface |
||
18 | { |
||
19 | /** |
||
20 | * Logger instance |
||
21 | * |
||
22 | * @var LoggerInterface |
||
23 | */ |
||
24 | private $logger; |
||
25 | |||
26 | /** |
||
27 | * Timeout in seconds |
||
28 | * |
||
29 | * @var int |
||
30 | */ |
||
31 | private $timeout = 5; |
||
32 | |||
33 | /** |
||
34 | * |
||
35 | * @var HttpClient |
||
36 | */ |
||
37 | private $httpClient; |
||
38 | |||
39 | 4 | public function __construct() |
|
43 | |||
44 | /** |
||
45 | * Set timeout in seconds |
||
46 | * |
||
47 | * @param int $timeout |
||
48 | */ |
||
49 | public function setTimeout(int $timeout) |
||
53 | |||
54 | /** |
||
55 | * Query the duck duck go api |
||
56 | * |
||
57 | * @param string $query |
||
58 | * Keywords to start a query for |
||
59 | * @throws ApiException |
||
60 | * @return string The payload |
||
61 | */ |
||
62 | 3 | public function query(string $query): string |
|
90 | |||
91 | /** |
||
92 | * Provide an URL object out of given duckduckgo query |
||
93 | * |
||
94 | * @param string $query |
||
95 | * @return Url |
||
96 | */ |
||
97 | 3 | private function provideUrl(string $query): Url |
|
103 | |||
104 | /** |
||
105 | * Set the logger |
||
106 | * @param LoggerInterface $logger |
||
107 | */ |
||
108 | 4 | public function setLogger(LoggerInterface $logger) |
|
112 | |||
113 | } |
||
114 |