wubs/ns-api

此包的最新版本(1.0.0)没有提供许可信息。

与NS API通信

1.0.0 2017-11-22 19:18 UTC

This package is not auto-updated.

Last update: 2024-09-28 17:49:02 UTC


README

Laravel ns-api 封装器

安装

在项目根目录下,输入

$ composer require wubs/ns-api

安装完成后,将 'Wubs\NS\NSServiceProvider', 添加到 app/config.php 中的 providers 数组,并将 'NS' => 'Wubs\NS\Facades\NS', 添加到 aliases 数组,同样在 app/config.php 中。

Laravel 使用

火车站

获取所有火车站的集合

<?php
$stations = NS::stations();

这将返回一个包含 Station 对象的 Collection,一个 Station 对象具有以下属性

<?php
$station = $stations->first();
$station->name;
$station->code;
$station->country;
$station->lat;
$station->long;
$station->alias;

失败

获取计划内和计划外的失败列表

<?php
$failures = NS::failures(ut'); //full name or code from a station
$planned = $failures->planned; //Collection of planned failures
$unplanned = $failures->unplanned; //Collection of unplanned failures

一个 Failure 对象具有以下属性

<?php
$failure->id;
$failure->route;
$failure->reason;
$failure->message;
$failure->date; //Carbon date object

旅行建议

旅行建议由多个对象组成。一个 Advise 对象包含一个或多个 Notification 对象的 Collection,同时它还包含多个 Step 对象。每个 Step 对象在一个 Collection 中包含多个 WayPoint 对象。WayPoints 是你旅行建议中的一部分火车站,但你不会在那里停留。此 Collection 中的第一个和最后一个项目是该部分旅行建议的起点和终点站。

<?php
$advises = NS::advise('Aalten', "Zurich"); //Returns a Collection with Advise objects
$advise = $advises->first();
$advise->notifications; //Collection|Notification[]
$advise->numberOfSwitches;
$advise->plannedTravelDuration;
$advise->actualTravelDuration;
$advise->departureDelay;
$advise->arrivalDelay;
$advise->optimal;
$advise->plannedDepartureTime; //Carbon
$advise->actualDepartureTime; //Carbon
$advise->plannedArrivalTime; //Carbon
$advise->actualArrivalTime; //Carbon
$advise->state;
$advise->steps; //Collection|Steps[]

$notification = $advise->notifications->first();
$notification->id;
$notification->serious;
$notification->text;

$step = $advise->steps->first();
$step->carrier;
$step->carrierType;
$step->tripNumber;
$step->status;
$step->tripDetails;
$step->plannedFailureId;
$step->unplannedFailureId;
$step->transitType;
$step->wayPoints; //Collection|WayPoint[]

$wayPoint = $step->wayPoints->first();
$wayPoint->name;
$wayPoint->time; //Carbon
$wayPoint->departureDelay;
$wayPoint->track;