Skip to content

Commit

Permalink
Hotfix for DHL
Browse files Browse the repository at this point in the history
  • Loading branch information
sauladam committed Dec 1, 2020
1 parent 038d2f6 commit f1edc2e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/DataProviders/GuzzleClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
27 changes: 25 additions & 2 deletions src/Trackers/DHL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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',
],
];

Expand Down

0 comments on commit f1edc2e

Please sign in to comment.