<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">

<title>RDoc Documentation</title>

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
</script>

<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<link href="./css/fonts.css" rel="stylesheet">
<link href="./css/rdoc.css" rel="stylesheet">


<body id="top" role="document" class="file">
<nav role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="./index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>


    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  <div id="project-metadata">
    
<div id="fileindex-section" class="nav-section">
  <h3>Pages</h3>

  <ul class="link-list">
    <li><a href="./LICENSE.html">LICENSE</a>
    <li><a href="./README_md.html">README</a>
  </ul>
</div>

    <div id="classindex-section" class="nav-section">
  <h3>Class and Module Index</h3>

  <ul class="link-list">
  <li><details open><summary><code><a href="./Ldbws.html">Ldbws</a></code></summary>
  <ul class="link-list">
  <li><details><summary><code><a href="./Ldbws/Request.html">Request</a></code></summary>
  <ul class="link-list">
  <li><code><a href="./Ldbws/Request/GetDeparturesBoard.html">GetDeparturesBoard</a></code>
  <li><code><a href="./Ldbws/Request/GetDeparturesBoardWithDetails.html">GetDeparturesBoardWithDetails</a></code>
  <li><code><a href="./Ldbws/Request/GetServiceDetails.html">GetServiceDetails</a></code>
  <li><code><a href="./Ldbws/Request/GetStationBoard.html">GetStationBoard</a></code>
  <li><code><a href="./Ldbws/Request/GetStationBoardWithDetails.html">GetStationBoardWithDetails</a></code>
  <li><code><a href="./Ldbws/Request/ParamValidationError.html">ParamValidationError</a></code>
  </ul></details>
  <li><code><a href="./Ldbws/RequestError.html">RequestError</a></code>
  <li><code><a href="./Ldbws/ResponseParsingError.html">ResponseParsingError</a></code>
  <li><details><summary><code><a href="./Ldbws/ResponseTypes.html">ResponseTypes</a></code></summary>
  <ul class="link-list">
  <li><code><a href="./Ldbws/ResponseTypes/BaseStationBoard.html">BaseStationBoard</a></code>
  <li><code><a href="./Ldbws/ResponseTypes/CallingPoint.html">CallingPoint</a></code>
  <li><code><a href="./Ldbws/ResponseTypes/Coach.html">Coach</a></code>
  <li><code><a href="./Ldbws/ResponseTypes/DepartureItem.html">DepartureItem</a></code>
  <li><code><a href="./Ldbws/ResponseTypes/DepartureItemWithDetails.html">DepartureItemWithDetails</a></code>
  <li><code><a href="./Ldbws/ResponseTypes/DeparturesBoard.html">DeparturesBoard</a></code>
  <li><code><a href="./Ldbws/ResponseTypes/DeparturesBoardWithDetails.html">DeparturesBoardWithDetails</a></code>
  <li><code><a href="./Ldbws/ResponseTypes/Formation.html">Formation</a></code>
  <li><code><a href="./Ldbws/ResponseTypes/LoadingCategory.html">LoadingCategory</a></code>
  <li><code><a href="./Ldbws/ResponseTypes/Location.html">Location</a></code>
  <li><code><a href="./Ldbws/ResponseTypes/ServiceDetails.html">ServiceDetails</a></code>
  <li><code><a href="./Ldbws/ResponseTypes/ServiceItem.html">ServiceItem</a></code>
  <li><code><a href="./Ldbws/ResponseTypes/ServiceItemWithCallingPoints.html">ServiceItemWithCallingPoints</a></code>
  <li><code><a href="./Ldbws/ResponseTypes/StationBoard.html">StationBoard</a></code>
  <li><code><a href="./Ldbws/ResponseTypes/StationBoardWithDetails.html">StationBoardWithDetails</a></code>
  <li><code><a href="./Ldbws/ResponseTypes/ToiletAvailability.html">ToiletAvailability</a></code>
  </ul></details>
  <li><code><a href="./Ldbws/Service.html">Service</a></code>
  </ul></details>
</div>

  </div>
</nav>

<main role="main">


<h1 id="label-ldbws-ruby">ldbws-ruby<span><a href="#label-ldbws-ruby">&para;</a> <a href="#top">&uarr;</a></span></h1>

<p>I’ll write a proper readme/howto at some point, but short version is that this is a Ruby wrapper around <a href="https://lite.realtime.nationalrail.co.uk/OpenLDBWS/">Network Rail‘s Live Departure Board web service</a> (LDBWS/OpenLDBWS)—I’ve trawled through their XSD files so you don’t have to =)</p>

<p>I built it for a project I’m hacking at + thought I’d release it into the world. It’s rough and ready right now, but it should be somewhat functional.</p>

<h2 id="label-HOWTO">HOWTO<span><a href="#label-HOWTO">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>All operations are supported, in <code>snake_case</code>, thus:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&quot;ldbws&quot;</span>

<span class="ruby-identifier">service</span> = <span class="ruby-constant">Ldbws</span>.<span class="ruby-identifier">service</span>(<span class="ruby-constant">YOUR_API_TOKEN</span>)
<span class="ruby-identifier">result</span> = <span class="ruby-identifier">service</span>.<span class="ruby-identifier">get_departure_board</span>(<span class="ruby-value">crs:</span> <span class="ruby-string">&quot;CDF&quot;</span>)

<span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;TIME   PLAT  TO&quot;</span>
<span class="ruby-identifier">result</span>.<span class="ruby-identifier">train_services</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">service</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">printf</span>(
    <span class="ruby-string">&quot;%s   %-2s   %s  (%s)\n&quot;</span>,
    <span class="ruby-identifier">service</span>.<span class="ruby-identifier">std</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-string">&quot;%H:%M&quot;</span>),
    <span class="ruby-identifier">service</span>.<span class="ruby-identifier">platform</span> <span class="ruby-operator">||</span> <span class="ruby-string">&quot;-&quot;</span>,
    <span class="ruby-identifier">service</span>.<span class="ruby-identifier">destination</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">name</span>,
    <span class="ruby-identifier">service</span>.<span class="ruby-identifier">operator</span>
  )
<span class="ruby-keyword">end</span>

<span class="ruby-comment"># TIME   PLAT  TO</span>
<span class="ruby-comment"># 17:32   -    Penarth  (Transport for Wales)</span>
<span class="ruby-comment"># 17:39   3    Swansea  (Great Western Railway)</span>
<span class="ruby-comment"># 17:55   8    Barry  (Transport for Wales)</span>
<span class="ruby-comment"># 17:56   2A   Manchester Piccadilly  (Transport for Wales)</span>
<span class="ruby-comment"># 18:01   6    Bargoed  (Transport for Wales)</span>
<span class="ruby-comment"># [etc]</span>
</pre>

<h3 id="label-A+note+about+rate+limiting">A note about rate limiting<span><a href="#label-A+note+about+rate+limiting">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>LDBWS uses rate-limiting for free access: while this <em>probably</em> isn’t going to be an issue for the casual user, you may want to consider using a cache in front of this gem, just in case.</p>

<h2 id="label-Error-handling">Error-handling<span><a href="#label-Error-handling">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>This module is pretty decent at validating request parameters, but beyond that all it can really do is just echo what LDBWS says. To wit, there are three errors that can be raised:</p>

<h3 id="label-Ldbws-3A-3ARequest-3A-3AParamValidationError"><code>Ldbws::Request::ParamValidationError</code><span><a href="#label-Ldbws-3A-3ARequest-3A-3AParamValidationError">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>This is raised when parameter validation fails. Details about exactly which parameters and why can be found using the <code>#messages</code>, and is provided in hash format, thus:</p>

<pre class="ruby"><span class="ruby-keyword">begin</span>
        <span class="ruby-identifier">service</span>.<span class="ruby-identifier">get_departure_board</span>
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">Ldbws</span><span class="ruby-operator">::</span><span class="ruby-constant">Request</span><span class="ruby-operator">::</span><span class="ruby-constant">ParamValidationError</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">e</span>
        <span class="ruby-comment"># e = { crs: &quot;is missing&quot; }</span>
<span class="ruby-keyword">end</span>
</pre>

<h3 id="label-Ldbws-3A-3ARequestError"><code>Ldbws::RequestError</code><span><a href="#label-Ldbws-3A-3ARequestError">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Raised when LDBWS returns an error message, usually because the request is bad (eg: invalid CRS). Unfortunately LDBWS’ error messages are pretty terrible, so it’s generally not too edifying to look at them.</p>

<h3 id="label-Ldbws-3A-3AResponseParsingError"><code>Ldbws::ResponseParsingError</code><span><a href="#label-Ldbws-3A-3AResponseParsingError">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Raised when the response from LDBWS cannot be parsed.</p>

<h2 id="label-Caveats">Caveats<span><a href="#label-Caveats">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>This is released into the world as-is. If you use it for something and end up missing your train, or do something that falls foul of the LDBWS terms of use, it’s not my fault :)</p>
<hr>

<p>Share and enjoy!</p>

</main>


<footer id="validator-badges" role="contentinfo">
  <p><a href="https://validator.w3.org/check/referer">Validate</a>
  <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.5.0.
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>