diff --git a/src/DataProviders/GuzzleClient.php b/src/DataProviders/GuzzleClient.php index c636022..c92a827 100644 --- a/src/DataProviders/GuzzleClient.php +++ b/src/DataProviders/GuzzleClient.php @@ -25,11 +25,12 @@ public function __construct() * Request the given url. * * @param $url + * @param array $options * * @return string */ - public function get($url) + public function get($url, $options = []) { - return $this->client->get($url)->getBody()->getContents(); + return $this->client->get($url, $options)->getBody()->getContents(); } } diff --git a/src/Trackers/DHL.php b/src/Trackers/DHL.php index 85574fe..f3ec539 100644 --- a/src/Trackers/DHL.php +++ b/src/Trackers/DHL.php @@ -51,6 +51,29 @@ public function track($number, $language = null, $params = []) } + /** + * Get the contents of the given url. + * + * @param string $url + * + * @return string + */ + protected function fetch($url) + { + if ($this->defaultDataProvider !== 'guzzle') { + return $this->getDataProvider()->get($url); + } + + return $this->getDataProvider()->get($url, [ + 'timeout' => 5, + 'headers' => [ + 'User-Agent' => 'tracking/1.0', + 'Accept' => 'text/html', + ]] + ); + } + + /** * @param string $contents * @@ -153,7 +176,7 @@ protected function parseJson(DOMXPath $xpath) } $matched = preg_match( - "/initialState: JSON\.parse\((.*)\)\,/m", $scriptTags->item(0)->nodeValue, $matches + "/initialState: JSON\.parse\((.*)\)\,/m", $scriptTags->item(2)->nodeValue, $matches ); if ($matched !== 1) { @@ -253,7 +276,7 @@ protected function resolveStatus($statusDescription) 'The shipment is being returned', 'Es erfolgt eine Rücksendung', 'Zustellung der Sendung nicht möglich', - 'recipient is unknown' + 'recipient is unknown', ], ];