class Amtrak::TrainFetcher
Service for getting train time HTML page from the Amtrak
website
Attributes
date[R]
from[R]
to[R]
Public Class Methods
get(*args)
click to toggle source
# File lib/amtrak/train_fetcher.rb, line 8 def self.get(*args) new(*args).get end
new(from, to, date: nil)
click to toggle source
# File lib/amtrak/train_fetcher.rb, line 14 def initialize(from, to, date: nil) @from = from @to = to @date = date || Date.today end
Public Instance Methods
check_release()
click to toggle source
# File lib/amtrak/train_fetcher.rb, line 20 def check_release first_page.release == '6.25.02a' end
get()
click to toggle source
# File lib/amtrak/train_fetcher.rb, line 24 def get JSON.parse(response.body) end
Private Instance Methods
body()
click to toggle source
# File lib/amtrak/train_fetcher.rb, line 38 def body { 'dateTime' => date.strftime('%Y-%0m-%d'), 'origin' => from.upcase, 'destination' => to.upcase, 'type' => 'A', 'versionNumber' => '2.2.12' } end
headers()
click to toggle source
# File lib/amtrak/train_fetcher.rb, line 48 def headers { 'Accept' => '*/*', 'Content-Type' => 'application/json' } end
response()
click to toggle source
# File lib/amtrak/train_fetcher.rb, line 30 def response Excon.post( 'https://rider.amtrak.com/MobileApps/TrainStatus', body: body.to_json, headers: headers ) end