Skip to content

Commit

Permalink
Forward GET parameter key to timetable.search.ch
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian committed Nov 13, 2024
1 parent c084649 commit ac0e989
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/Transport/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class API

protected $clientUserAgent;

protected $key;

public function __construct(Browser $browser = null, $lang = 'EN')
{
$this->browser = $browser ?: new Browser();
Expand All @@ -51,6 +53,11 @@ public function setClientUserAgent($clientUserAgent)
$this->clientUserAgent = $clientUserAgent;
}

public function setKey($key)
{
$this->key = $key;
}

/**
* @return object
*/
Expand Down Expand Up @@ -94,6 +101,10 @@ public function sendQuery(Query $query, $url = self::URL)
$formRequest->setField('ip_address', $this->clientIpAddress);
$formRequest->setField('user_agent', $this->clientUserAgent);

if ($this->key) {
$formRequest->setField('key', $this->key);
}

return $this->browser->send($formRequest);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/Transport/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,10 @@ public function __construct()
$app->before(function (Request $request) use ($app) {
$ipAddress = $request->getClientIp();
$userAgent = $request->headers->get('User-Agent');
$key = $request->query->get('key');
$app['api']->setClientIpAddress($ipAddress);
$app['api']->setClientUserAgent($userAgent);
$app['api']->setKey($key);
});

// home
Expand Down

0 comments on commit ac0e989

Please sign in to comment.