https://github.com/edofre/laravel-ns-api
Laravel wrapper for NS api
https://github.com/edofre/laravel-ns-api
Last synced: 6 months ago
JSON representation
Laravel wrapper for NS api
- Host: GitHub
- URL: https://github.com/edofre/laravel-ns-api
- Owner: Edofre
- License: mit
- Created: 2017-01-09T21:07:02.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-04T15:15:09.000Z (over 9 years ago)
- Last Synced: 2024-12-30T15:38:31.859Z (over 1 year ago)
- Language: PHP
- Size: 42 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel NS API wrapper
[](https://packagist.org/packages/edofre/laravel-ns-api)
[](https://packagist.org/packages/edofre/laravel-ns-api)
[](https://packagist.org/packages/edofre/laravel-ns-api)
[](https://packagist.org/packages/edofre/laravel-ns-api)
[](https://packagist.org/packages/edofre/laravel-ns-api)
## Installation
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
To install, either run
```
$ php composer.phar require edofre/laravel-ns-api
```
or add
```
"edofre/laravel-ns-api": "v1.0.0"
```
to the ```require``` section of your `composer.json` file.
## Configuration
Publish assets and configuration files
```
php artisan vendor:publish --tag=config
```
In the above configuration file you will need to enter your NS API username and password
### Example
#### Get all the stations
```php
$api = new NsApi();
$stations = $api->getStations();
```
#### Get all the departing trains from a station
```php
$api = new NsApi();
$station = new Station('UT', '','','','','','','','','');
$departing_trains = $api->getDepartures($station);
```
#### Get all the disturbances from a station
```php
$api = new NsApi();
$station = new Station('ut', '', '', '', '', '', '', '', '', '');
// We want the actual disturbances and not the unplanned disturbances
$disturbances = $api->getDisturbances($station, true , false);
```
#### Get the prices for a route
```php
$api = new NsApi();
$from_station = new Station('ZL', '', '', '', '', '', '', '', '', '');
$via_station = new Station('DH', '', '', '', '', '', '', '', '', '');
$to_station = new Station('HT', '', '', '', '', '', '', '', '', '');
$prices = $api->getPrices($from_station, $to_station, $via_station);
```