Skip to content

Instantly share code, notes, and snippets.

@ordinaryzelig
Created May 15, 2014 16:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?

dbrady_trainline

Build a bot that triggers searches on http://thetrainline.com and returns the results in a specific format.

Input

  • The bot should respond to ComThetrainline.find(from, to, departure_at).
  • Assume that the parameters from and to will be EXACTLY what you need.
  • departure_at will be a Ruby DateTime object.

Output

find() should return an array. Each element of the array should be an option for a trip. E.g. If you search for London to Paris, and they give you 10 "segments" leaving each hour on the hour, the array size should be 10. Each "segment" should be in this format and should include all data:

# Segment
{
      :departure_station => "Ashchurch For Tewkesbury",
           :departure_at => #<DateTime: 2014-04-26T06:09:00+00:00 ((2456774j,22140s,0n),+0s,2299161j)>,
        :arrival_station => "Ash",
             :arrival_at => #<DateTime: 2014-04-26T09:37:00+00:00 ((2456774j,34620s,0n),+0s,2299161j)>,
       :service_agencies => ["thetrainline"],
    :duration_in_minutes => 208,
            :changeovers => 2,
               :products => ["train"],
                  :fares => ["See below"],
}
# Fare
{
                       :name => "Advance Single",
             :price_in_cents => 1939,
                   :currency => "GBP",
              :comfort_class => 1,
 },

Misc

  • We use Ruby 2.0.0-p353, but if you just use 2.0, I think it will be fine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment