<?php
class TransportForLondonAPI
{
    private $appKey;

    private $trace;

    function __construct($appKey, $trace = FALSE)
    {
        $this->appKey = $appKey;

        $this->trace = $trace;
    }

    private function call($tapiUrl)
    {
        try {
            $response = file_get_contents($tapiUrl);
            if ($response !== false) {
                $response = json_decode($response, true);
            }
        } catch (Exception $ex) {
            if ($this->trace) {
                $traceOutput["Message"] = $ex->getMessage();

                $traceOutput["url"] = str_replace($this->appId, "", str_replace($this->appKey, "", $tapiUrl));

                echo "<xmp>";
                print_r($traceOutput);
                echo "</xmp>";
            }
        }

        return (isset($response) ? $response : false);
    }

    public function Arrivals(string $loc)
    {
        return $this->call("https://api.tfl.gov.uk/StopPoint/{$loc}/Arrivals?app_key={$this->appKey}");
    }
}
