Giter Club home page Giter Club logo

php-api's Introduction

phpNS, by Jurrie Overgoor <[email protected]>

phpNS is an implementation of the public API of the NS.
You can find the documentation of that API at http://www.ns.nl/reizigers/blind/_api-nieuw

phpNS is licensed under the GNU General Public License version 3. Please see the COPYING file for more information.

Developer key
-------------
To use phpNS, you must have a developer key. You can request one at https://www.ns.nl/ews-aanvraagformulier/

How to use phpNS
----------------
Step 1: get your developer key at https://www.ns.nl/ews-aanvraagformulier/

Step 2: include the main file
Simply include phpNS.php with the following line:
  require_once('NS.php');

Step 3: decide on the retriever implementation you want to use
A 'retriever' is a class that can request content from ns.nl. At the moment, there's only one retriever:
* cURLRetriever: It uses cURL to request the information.
(Implement your own retriever when you have special needs, like proxy-support or something. To implement your own retriever, extend Retriever and implement the abstract methods.)

Instantiate the cURLRetriever like so:
  $retriever = new cURLRetriever('<YOUR_EMAIL>', '<YOUR_DEVELOPER_KEY>');

Replace <YOUR_EMAIL> with the email you used in step 1, and <YOUR_DEVELOPER_KEY> with the key you got from step 1.

Step 4: decide on the caching implementation
Caching the responses is a good idea, as it lowers the amount of requests you need to do on the NS servers. At the moment, you have the choice between three caching implementations:
* NoCache: does not actually cache
* FileCache: caches responses on disk, in a directory structure
* MySQLCache: caches responses in a MySQL database table

Let's go for the FileCache. We want to cache the responses in a 'tmp' directory below the current directory. We instantiate the FileCache like so:
  require_once('cache/FileCache.php');
  $cache = new FileCache($retriever, "tmp");

Step 5: create an NS object
The NS class is the main class that you'll use for accessing the NS information. Instantiate it like so:
  $ns = new NS($cache);

Step 6: query the NS object for the information you want!
The NS class has several methods. For this example, we want to retrieve a list of all stations:
  $stations = $ns->getStations();

The complete code is like this:
  require_once('NS.php');
  require_once('cache/FileCache.php');
  $retriever = new cURLRetriever('<YOUR_EMAIL>', '<YOUR_DEVELOPER_KEY>');
  $cache = new FileCache($retriever, "tmp");
  $ns = new NS($cache);
  $stations = $ns->getStations();

php-api's People

Contributors

jurrie avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.