Skip to content

Commit

Permalink
Removed the need for a session ID.
Browse files Browse the repository at this point in the history
  • Loading branch information
B3none committed Feb 16, 2018
1 parent 2b6dd34 commit e6f3ff1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 35 deletions.
35 changes: 1 addition & 34 deletions src/EMTClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class EMTClient
const EMT_BASE_URL = "https://www.eastmidlandstrains.co.uk";
const EMT_API_ENDPOINT = "/services/LiveTrainInfoService.svc/GetLiveBoardJson";

const DEFAULT_SESSION_ID = "hoetyz55hfy5t1554cepm32i";

/**
* @var bool
*/
Expand Down Expand Up @@ -54,19 +52,7 @@ public function getJourneys(string $startLocation, string $endLocation) : array
]);

$request = new Request('POST', self::EMT_BASE_URL . self::EMT_API_ENDPOINT, [
'Host' => 'www.eastmidlandstrains.co.uk',
'Connection' => 'keep-alive',
'Content-Length' => strlen($jsonData),
'Pragma' => 'no-cache',
'Accept' => 'application/json, text/javascript, */*; q=0.01',
'Origin' => 'https://www.eastmidlandstrains.co.uk',
'X-Requested-With' => 'XMLHttpRequest',
'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36',
'Content-Type' => 'application/json',
'Referer' => 'https://www.eastmidlandstrains.co.uk/train-times/live-train-updates',
'Accept-Encoding' => 'gzip, deflate, br',
'Accept-Language' => 'en-GB,en-US;q=0.8,en;q=0.6',
'Cookie' => 'EMT_cookies=True; ASP.NET_SessionId=' . $this->fetchNewSessionId() . '; _gat=1; _gat_UA-32673593-2=1; _ga=GA1.3.1718692550.1518710881; _gid=GA1.3.1779475860.1518710881'
'Content-Type' => 'application/json'
], $jsonData);

$response = $this->client->send($request);
Expand All @@ -75,25 +61,6 @@ public function getJourneys(string $startLocation, string $endLocation) : array
return $this->processResponse($requestResult);
}

/**
* Grab a new session ID via GET request.
*
* @return string
*/
protected function fetchNewSessionId() : string
{
$this->client->get(self::EMT_BASE_URL);
$cookies = $this->client->getConfig('cookies')->toArray();

foreach ($cookies as $cookie) {
if ($cookie['Name'] === "ASP.NET_SessionId") {
return $cookie['Value'];
}
}

return self::DEFAULT_SESSION_ID;
}

/**
* Process the response from the API call.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/EMTClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class EMTClientTest extends TestCase
public function test()
{
$client = new EMTClient();
$testData = $client->getJourneys('Derby', 'Burton-Upon-Trent');
$testData = $client->getJourneys('Derby', 'Burton-On-Trent');
$this->assertTrue(is_array($testData));
}
}

0 comments on commit e6f3ff1

Please sign in to comment.