The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

VERSION

version 0.003

NAME

WWW::IRail::API::Stations - HTTP::Request builder and HTTP::Response parser for the IRail API Station data

SYNOPSIS

use WWW::IRail::API::Stations;
use LWP::UserAgent();

my $ua = new LWP::UserAgent();
   $ua->timeout(20);
         
my $station_req = WWW::IRail::API::Stations::make_request();
my $http_resp = $ua->request($station_req);
my $result = WWW::IRail::API::Stations::parse_response($http_resp,'perl');

DESCRIPTION

This module builds a HTTP::Request and has a parser for the HTTP::Response. It's up to you to transmit it over the wire. If don't want to do that yourself, don't use this module directly and use WWW::IRail::API instead.

METHODS

make_request()

Has no arguments, requests the whole list of stations from the API

parse_response( {$http_response}, "dataType", filter() )

parses the HTTP::Response you got back from the server, which if all went well contains XML. That XML is then transformed into other data formats.

Note that the perl data format returns the data unnested for easier access.

  • xml

  • XML

  • YAML

  • JSON

  • perl (default)

example of output when dataType = 'xml'

<stations>
  <station>\'S GRAVENBRAKEL</station>
  <station>AALST</station>
  <station>AALST KERREBROEK</station>

  <!-- ... snip ... -->

</stations>

example of output when dataType = 'XML'

<stations timestamp="1291047694" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="stations.xsd">
  <station id="BE.NMBS.82" location="50.605075 4.137658" locationX="4.137658" locationY="50.605075">\'S GRAVENBRAKEL</station>
  <station id="BE.NMBS.1" location="50.943053 4.038586" locationX="4.038586" locationY="50.943053">AALST</station>
  <station id="BE.NMBS.2" location="50.948316 4.024773" locationX="4.024773" locationY="50.948316">AALST KERREBROEK</station>

  <!-- ... snip ... -->

</stations>

example of output when dataType = 'JSON'

{ 
  "station" : [
    "\'S GRAVENBRAKEL",
    "AALST",
    "AALST KERREBROEK",
    "AALTER",
    // ...
  ]
}

example of output when dataType = 'YAML'

station:
  - "\'S GRAVENBRAKEL"
  - AALST
  - AALST KERREBROEK
  - AALTER
  ...

example of output when dataType="perl" (default)

$VAR1 = [
           '\'S GRAVENBRAKEL',
           'AALST',
           'AALST KERREBROEK',
           'AALTER',
           'AARLEN',
           'AARSCHOT',
           # ...
        ]

METHODS

SEE ALSO

INSTALLATION

See perlmodinstall for information and options on installing Perl modules.

BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests through the web interface at http://rt.cpan.org.

AUTHOR

Tim Esselens <tim.esselens@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Tim Esselens.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.