PHP code example of vikingmaster / tampere-journeys-api-sdk

1. Go to this page and download the library: Download vikingmaster/tampere-journeys-api-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vikingmaster / tampere-journeys-api-sdk example snippets


$api = new \Vikingmaster\TampereJourneysApiSdk\TampereJourneysApiClient([
    'baseUri' => 'http://data.itsfactory.fi/journeys/api'
]);

//Fetch lines
$request = $api->makeGetLinesRequest()
    ->setIndent(true)
    ->setDescription('Description')
;
$response = $request->send();
$lines = $response->getLines();

$request = $api->makeGetJourneyPatternsRequest()
    ->setFirstStopPointId(1)
    ->setLastStopPointId(2)
    ->setLineId(17)
    ->setName("Nokian asema C - Keho")
;
$response = $request->send();
$patterns = $response->getJourneyPatterns();

use \Vikingmaster\TampereJourneysApiSdk\Exceptions\TampereJourneyApiException;

try {
    $response = $request->send();
} catch (TampereJourneyApiException $e) {
    //These methods are available for problem tracing
    $apiError  = $e->getApiError();
    $request   = $e->getRequest();
    $response  = $e->getResponse();
    $apiClient = $e->getApiClient();
} catch (\Exception $e) {
    //Any other errors such as network or configuration error
}

/** @var array|\Vikingmaster\TampereJourneysApiSdk\Dto\Line[] $entries */
$entries = [];

$fetch      = true;
$startIndex = 0;
while ($fetch) {
    try {
        $response = $request->setStartIndex($startIndex)->send();
        $entries  = array_merge($entries, $response->getLines());
    } catch (\Exception $e) {
         //Handle exception / resend the request
        break;
    }

    $fetch      = $response->getPaging()->hasMoreData();
    $startIndex = $response->getPaging()->getPageSize();
}