定制 vikingmaster/tampere-journeys-api-sdk 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vikingmaster/tampere-journeys-api-sdk

Composer 安装命令:

composer require vikingmaster/tampere-journeys-api-sdk

包简介

PHP SDK for Tampere Journeys API

README 文档

README

This is an unofficial SDK release for Tampere Journeys API.

Installation

Install using composer: composer require vikingmaster/tampere-journeys-api-sdk

Usage

Creating an API Client instance. Available config parameters:

  • baseUri Base URI to make requests to
  • timeout (optional) Http request timeout in seconds
  • userAgent (optional) User-Agent header
$api = new \Vikingmaster\TampereJourneysApiSdk\TampereJourneysApiClient([
    'baseUri' => 'http://data.itsfactory.fi/journeys/api'
]);

Fetching lines:

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

Fetching journey patterns

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

Exception handling

When there is a request error, TampereJourneyApiException will be thrown:

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
}

Pagination

Some of the responses can be long, so multiple requests might be needed to fetch everything

/** @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();
}

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: HTML

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-11-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固