ierail 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.coveralls.yml +1 -1
- data/.github/workflows/ruby.yml +34 -0
- data/Gemfile +2 -2
- data/LICENSE.txt +3 -9
- data/README.md +4 -11
- data/fixtures/vcr_cassettes/find_station.yml +3 -3
- data/fixtures/vcr_cassettes/northbound.yml +163 -182
- data/fixtures/vcr_cassettes/southbound.yml +221 -239
- data/fixtures/vcr_cassettes/southbound_from.yml +221 -239
- data/fixtures/vcr_cassettes/station.yml +163 -182
- data/fixtures/vcr_cassettes/station_times.yml +70 -60
- data/fixtures/vcr_cassettes/stations.yml +3 -3
- data/fixtures/vcr_cassettes/train_movements.yml +47 -31
- data/fixtures/vcr_cassettes/trains.yml +202 -247
- data/fixtures/vcr_cassettes/westbound.yml +62 -50
- data/ierail.gemspec +12 -9
- data/lib/core_ext.rb +4 -2
- data/lib/ierail.rb +37 -30
- data/lib/station.rb +2 -0
- data/lib/station_data.rb +10 -0
- data/lib/train.rb +2 -0
- data/lib/train_movement.rb +7 -5
- data/test/unit/helper.rb +13 -8
- data/test/unit/ierail.rb +18 -26
- data/test/unit/station.rb +1 -1
- data/test/unit/station_data.rb +1 -5
- data/test/unit/train.rb +1 -1
- data/test/unit/train_movement.rb +1 -1
- metadata +56 -41
- data/.travis.yml +0 -6
- data/Gemfile.lock +0 -60
|
@@ -25,64 +25,76 @@ http_interactions:
|
|
|
25
25
|
Server:
|
|
26
26
|
- ''
|
|
27
27
|
Date:
|
|
28
|
-
-
|
|
28
|
+
- Mon, 05 Oct 2015 20:06:37 GMT
|
|
29
29
|
Content-Length:
|
|
30
|
-
- '
|
|
30
|
+
- '5152'
|
|
31
31
|
body:
|
|
32
32
|
encoding: UTF-8
|
|
33
33
|
string: "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<ArrayOfObjStationData
|
|
34
34
|
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
|
|
35
|
-
xmlns=\"http://api.irishrail.ie/realtime/\">\r\n <objStationData>\r\n <Servertime>
|
|
36
|
-
\ <Traincode>
|
|
37
|
-
\ <Stationcode>GRGRD</Stationcode>\r\n <Querytime>
|
|
38
|
-
\ <Traindate>
|
|
39
|
-
\ <
|
|
40
|
-
\ <
|
|
41
|
-
\ <
|
|
42
|
-
\ <
|
|
43
|
-
\ <
|
|
35
|
+
xmlns=\"http://api.irishrail.ie/realtime/\">\r\n <objStationData>\r\n <Servertime>2015-10-05T21:06:38.783</Servertime>\r\n
|
|
36
|
+
\ <Traincode>E829 </Traincode>\r\n <Stationfullname>Clongriffin</Stationfullname>\r\n
|
|
37
|
+
\ <Stationcode>GRGRD</Stationcode>\r\n <Querytime>21:06:38</Querytime>\r\n
|
|
38
|
+
\ <Traindate>05 Oct 2015</Traindate>\r\n <Origin>Greystones</Origin>\r\n
|
|
39
|
+
\ <Destination>Malahide</Destination>\r\n <Origintime>20:00</Origintime>\r\n
|
|
40
|
+
\ <Destinationtime>21:20</Destinationtime>\r\n <Status>En Route</Status>\r\n
|
|
41
|
+
\ <Lastlocation>Departed Clontarf Road</Lastlocation>\r\n <Duein>12</Duein>\r\n
|
|
42
|
+
\ <Late>6</Late>\r\n <Exparrival>21:17</Exparrival>\r\n <Expdepart>21:18</Expdepart>\r\n
|
|
43
|
+
\ <Scharrival>21:12</Scharrival>\r\n <Schdepart>21:12</Schdepart>\r\n
|
|
44
|
+
\ <Direction>Northbound</Direction>\r\n <Traintype>DART</Traintype>\r\n
|
|
45
|
+
\ <Locationtype>S</Locationtype>\r\n </objStationData>\r\n <objStationData>\r\n
|
|
46
|
+
\ <Servertime>2015-10-05T21:06:38.783</Servertime>\r\n <Traincode>E830
|
|
47
|
+
</Traincode>\r\n <Stationfullname>Clongriffin</Stationfullname>\r\n <Stationcode>GRGRD</Stationcode>\r\n
|
|
48
|
+
\ <Querytime>21:06:38</Querytime>\r\n <Traindate>05 Oct 2015</Traindate>\r\n
|
|
49
|
+
\ <Origin>Greystones</Origin>\r\n <Destination>Malahide</Destination>\r\n
|
|
50
|
+
\ <Origintime>20:30</Origintime>\r\n <Destinationtime>21:50</Destinationtime>\r\n
|
|
51
|
+
\ <Status>En Route</Status>\r\n <Lastlocation>Arrived Blackrock</Lastlocation>\r\n
|
|
52
|
+
\ <Duein>36</Duein>\r\n <Late>1</Late>\r\n <Exparrival>21:41</Exparrival>\r\n
|
|
53
|
+
\ <Expdepart>21:42</Expdepart>\r\n <Scharrival>21:41</Scharrival>\r\n
|
|
54
|
+
\ <Schdepart>21:41</Schdepart>\r\n <Direction>Northbound</Direction>\r\n
|
|
44
55
|
\ <Traintype>DART</Traintype>\r\n <Locationtype>S</Locationtype>\r\n
|
|
45
|
-
\ </objStationData>\r\n <objStationData>\r\n <Servertime>
|
|
46
|
-
\ <Traincode>
|
|
47
|
-
\ <Stationcode>GRGRD</Stationcode>\r\n <Querytime>
|
|
48
|
-
\ <Traindate>
|
|
49
|
-
\ <
|
|
50
|
-
\ <
|
|
51
|
-
\ <
|
|
52
|
-
\ <
|
|
53
|
-
\ <
|
|
56
|
+
\ </objStationData>\r\n <objStationData>\r\n <Servertime>2015-10-05T21:06:38.783</Servertime>\r\n
|
|
57
|
+
\ <Traincode>E831 </Traincode>\r\n <Stationfullname>Clongriffin</Stationfullname>\r\n
|
|
58
|
+
\ <Stationcode>GRGRD</Stationcode>\r\n <Querytime>21:06:38</Querytime>\r\n
|
|
59
|
+
\ <Traindate>05 Oct 2015</Traindate>\r\n <Origin>Greystones</Origin>\r\n
|
|
60
|
+
\ <Destination>Malahide</Destination>\r\n <Origintime>21:00</Origintime>\r\n
|
|
61
|
+
\ <Destinationtime>22:20</Destinationtime>\r\n <Status>En Route</Status>\r\n
|
|
62
|
+
\ <Lastlocation>Departed Greystones</Lastlocation>\r\n <Duein>66</Duein>\r\n
|
|
63
|
+
\ <Late>1</Late>\r\n <Exparrival>22:11</Exparrival>\r\n <Expdepart>22:12</Expdepart>\r\n
|
|
64
|
+
\ <Scharrival>22:11</Scharrival>\r\n <Schdepart>22:11</Schdepart>\r\n
|
|
65
|
+
\ <Direction>Northbound</Direction>\r\n <Traintype>DART</Traintype>\r\n
|
|
66
|
+
\ <Locationtype>S</Locationtype>\r\n </objStationData>\r\n <objStationData>\r\n
|
|
67
|
+
\ <Servertime>2015-10-05T21:06:38.783</Servertime>\r\n <Traincode>E130
|
|
68
|
+
</Traincode>\r\n <Stationfullname>Clongriffin</Stationfullname>\r\n <Stationcode>GRGRD</Stationcode>\r\n
|
|
69
|
+
\ <Querytime>21:06:38</Querytime>\r\n <Traindate>05 Oct 2015</Traindate>\r\n
|
|
70
|
+
\ <Origin>Malahide</Origin>\r\n <Destination>Greystones</Destination>\r\n
|
|
71
|
+
\ <Origintime>21:00</Origintime>\r\n <Destinationtime>22:20</Destinationtime>\r\n
|
|
72
|
+
\ <Status>En Route</Status>\r\n <Lastlocation>Departed Portmarnock</Lastlocation>\r\n
|
|
73
|
+
\ <Duein>2</Duein>\r\n <Late>1</Late>\r\n <Exparrival>21:08</Exparrival>\r\n
|
|
74
|
+
\ <Expdepart>21:08</Expdepart>\r\n <Scharrival>21:06</Scharrival>\r\n
|
|
75
|
+
\ <Schdepart>21:07</Schdepart>\r\n <Direction>Southbound</Direction>\r\n
|
|
54
76
|
\ <Traintype>DART</Traintype>\r\n <Locationtype>S</Locationtype>\r\n
|
|
55
|
-
\ </objStationData>\r\n <objStationData>\r\n <Servertime>
|
|
56
|
-
\ <Traincode>
|
|
57
|
-
\ <Stationcode>GRGRD</Stationcode>\r\n <Querytime>
|
|
58
|
-
\ <Traindate>
|
|
59
|
-
\ <Destination>
|
|
60
|
-
\ <Destinationtime>
|
|
61
|
-
\ <Lastlocation />\r\n <Duein>
|
|
62
|
-
\ <Expdepart>
|
|
63
|
-
\ <Schdepart>
|
|
77
|
+
\ </objStationData>\r\n <objStationData>\r\n <Servertime>2015-10-05T21:06:38.783</Servertime>\r\n
|
|
78
|
+
\ <Traincode>E131 </Traincode>\r\n <Stationfullname>Clongriffin</Stationfullname>\r\n
|
|
79
|
+
\ <Stationcode>GRGRD</Stationcode>\r\n <Querytime>21:06:38</Querytime>\r\n
|
|
80
|
+
\ <Traindate>05 Oct 2015</Traindate>\r\n <Origin>Malahide</Origin>\r\n
|
|
81
|
+
\ <Destination>Greystones</Destination>\r\n <Origintime>21:30</Origintime>\r\n
|
|
82
|
+
\ <Destinationtime>22:50</Destinationtime>\r\n <Status>No Information</Status>\r\n
|
|
83
|
+
\ <Lastlocation />\r\n <Duein>31</Duein>\r\n <Late>0</Late>\r\n <Exparrival>21:36</Exparrival>\r\n
|
|
84
|
+
\ <Expdepart>21:37</Expdepart>\r\n <Scharrival>21:36</Scharrival>\r\n
|
|
85
|
+
\ <Schdepart>21:37</Schdepart>\r\n <Direction>Southbound</Direction>\r\n
|
|
64
86
|
\ <Traintype>DART</Traintype>\r\n <Locationtype>S</Locationtype>\r\n
|
|
65
|
-
\ </objStationData>\r\n <objStationData>\r\n <Servertime>
|
|
66
|
-
\ <Traincode>
|
|
67
|
-
\ <Stationcode>GRGRD</Stationcode>\r\n <Querytime>
|
|
68
|
-
\ <Traindate>
|
|
69
|
-
\ <Destination>
|
|
70
|
-
\ <Destinationtime>
|
|
71
|
-
\ <Lastlocation />\r\n <Duein>
|
|
72
|
-
\ <Expdepart>
|
|
73
|
-
\ <Schdepart>
|
|
74
|
-
\ <Traintype>DART</Traintype>\r\n <Locationtype>S</Locationtype>\r\n
|
|
75
|
-
\ </objStationData>\r\n <objStationData>\r\n <Servertime>2014-04-19T19:10:55.677</Servertime>\r\n
|
|
76
|
-
\ <Traincode>E229 </Traincode>\r\n <Stationfullname>Clongriffin</Stationfullname>\r\n
|
|
77
|
-
\ <Stationcode>GRGRD</Stationcode>\r\n <Querytime>19:10:55</Querytime>\r\n
|
|
78
|
-
\ <Traindate>19 Apr 2014</Traindate>\r\n <Origin>Malahide</Origin>\r\n
|
|
79
|
-
\ <Destination>Bray</Destination>\r\n <Origintime>20:15</Origintime>\r\n
|
|
80
|
-
\ <Destinationtime>21:24</Destinationtime>\r\n <Status>No Information</Status>\r\n
|
|
81
|
-
\ <Lastlocation />\r\n <Duein>72</Duein>\r\n <Late>0</Late>\r\n <Exparrival>20:21</Exparrival>\r\n
|
|
82
|
-
\ <Expdepart>20:22</Expdepart>\r\n <Scharrival>20:21</Scharrival>\r\n
|
|
83
|
-
\ <Schdepart>20:22</Schdepart>\r\n <Direction>Southbound</Direction>\r\n
|
|
87
|
+
\ </objStationData>\r\n <objStationData>\r\n <Servertime>2015-10-05T21:06:38.783</Servertime>\r\n
|
|
88
|
+
\ <Traincode>E710 </Traincode>\r\n <Stationfullname>Clongriffin</Stationfullname>\r\n
|
|
89
|
+
\ <Stationcode>GRGRD</Stationcode>\r\n <Querytime>21:06:38</Querytime>\r\n
|
|
90
|
+
\ <Traindate>05 Oct 2015</Traindate>\r\n <Origin>Malahide</Origin>\r\n
|
|
91
|
+
\ <Destination>Dublin Connolly</Destination>\r\n <Origintime>22:10</Origintime>\r\n
|
|
92
|
+
\ <Destinationtime>22:35</Destinationtime>\r\n <Status>No Information</Status>\r\n
|
|
93
|
+
\ <Lastlocation />\r\n <Duein>71</Duein>\r\n <Late>0</Late>\r\n <Exparrival>22:16</Exparrival>\r\n
|
|
94
|
+
\ <Expdepart>22:17</Expdepart>\r\n <Scharrival>22:16</Scharrival>\r\n
|
|
95
|
+
\ <Schdepart>22:17</Schdepart>\r\n <Direction>Southbound</Direction>\r\n
|
|
84
96
|
\ <Traintype>DART</Traintype>\r\n <Locationtype>S</Locationtype>\r\n
|
|
85
97
|
\ </objStationData>\r\n</ArrayOfObjStationData>"
|
|
86
98
|
http_version:
|
|
87
|
-
recorded_at:
|
|
88
|
-
recorded_with: VCR 2.9.
|
|
99
|
+
recorded_at: Mon, 05 Oct 2015 20:06:37 GMT
|
|
100
|
+
recorded_with: VCR 2.9.3
|
data/ierail.gemspec
CHANGED
|
@@ -2,19 +2,22 @@ require 'date'
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = 'ierail'
|
|
5
|
-
s.version = '0.
|
|
5
|
+
s.version = '0.5.0'
|
|
6
6
|
s.date = Date.today.to_s
|
|
7
7
|
s.summary = "Irish Rail Train Schedule and Status API"
|
|
8
8
|
s.description = "Irish Rail Train Schedule and Status API"
|
|
9
9
|
s.authors = ["Oisin Hurley", "Gary Rafferty", "Michael Dever"]
|
|
10
|
-
s.email = '
|
|
10
|
+
s.email = 'oisin.hurley@gmail.com'
|
|
11
11
|
s.files = `git ls-files`.split("\n")
|
|
12
12
|
s.homepage = 'http://rubygems.org/gems/ierail'
|
|
13
|
-
s.
|
|
14
|
-
s.
|
|
15
|
-
s.add_runtime_dependency '
|
|
16
|
-
s.add_runtime_dependency '
|
|
17
|
-
s.
|
|
18
|
-
s.
|
|
19
|
-
s.add_development_dependency '
|
|
13
|
+
s.licenses = ['BSD-2-Clause']
|
|
14
|
+
s.required_ruby_version = ">=3.3.0"
|
|
15
|
+
s.add_runtime_dependency 'json', "~> 2", ">= 2.12.2"
|
|
16
|
+
s.add_runtime_dependency 'rest-client', "~> 2", ">= 2.1.0"
|
|
17
|
+
s.add_runtime_dependency 'nokogiri', "~> 1", ">= 1.18.8"
|
|
18
|
+
s.add_runtime_dependency 'tzinfo', "~> 2", ">= 2.0.6"
|
|
19
|
+
s.add_development_dependency 'vcr', "~> 6", ">= 6.3.1"
|
|
20
|
+
s.add_development_dependency 'webmock', "~> 3", ">= 3.25.1"
|
|
21
|
+
s.add_development_dependency 'timecop', "~> 0", ">= 0.9.10"
|
|
22
|
+
s.add_development_dependency 'minitest', "~> 5", ">= 5.25.5"
|
|
20
23
|
end
|
data/lib/core_ext.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class Array
|
|
2
4
|
#Filters elements, collecting those
|
|
3
5
|
#whose times are before _time_
|
|
@@ -13,8 +15,8 @@ class Array
|
|
|
13
15
|
select {|t| t.arrival[:expected] >= query_time }
|
|
14
16
|
end
|
|
15
17
|
|
|
16
|
-
# The 'in' is just sugar really, saving the
|
|
17
|
-
# programmer from doing a trivial computation
|
|
18
|
+
# The 'in' is just sugar really, saving the
|
|
19
|
+
# programmer from doing a trivial computation
|
|
18
20
|
# over and over again in their code.
|
|
19
21
|
def in time
|
|
20
22
|
select { |t| t.due_in <= time }
|
data/lib/ierail.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rest-client'
|
|
2
4
|
require 'nokogiri'
|
|
3
5
|
require 'uri'
|
|
@@ -10,19 +12,21 @@ require 'train_movement'
|
|
|
10
12
|
require 'core_ext'
|
|
11
13
|
|
|
12
14
|
class IERail
|
|
13
|
-
|
|
15
|
+
|
|
14
16
|
URL = "http://api.irishrail.ie/realtime/realtime.asmx"
|
|
15
|
-
|
|
17
|
+
|
|
16
18
|
class IERailGet < Nokogiri::XML::SAX::Document
|
|
17
|
-
|
|
19
|
+
|
|
18
20
|
attr_reader :result
|
|
19
|
-
|
|
21
|
+
|
|
20
22
|
def initialize(url, array_name, object_name)
|
|
21
|
-
@ws_url =
|
|
23
|
+
@ws_url = url.gsub(' ', '%20')
|
|
22
24
|
@ws_array_name = array_name.downcase
|
|
23
25
|
@ws_object_name = object_name.downcase
|
|
26
|
+
@result = nil
|
|
27
|
+
@current = nil
|
|
24
28
|
end
|
|
25
|
-
|
|
29
|
+
|
|
26
30
|
def response
|
|
27
31
|
unless @result
|
|
28
32
|
parser = Nokogiri::XML::SAX::Parser.new(self)
|
|
@@ -31,27 +35,27 @@ class IERail
|
|
|
31
35
|
@result
|
|
32
36
|
end
|
|
33
37
|
|
|
34
|
-
def start_document
|
|
38
|
+
def start_document
|
|
35
39
|
@result = []
|
|
36
40
|
end
|
|
37
|
-
|
|
41
|
+
|
|
38
42
|
def characters string
|
|
39
|
-
string.strip
|
|
40
|
-
@result.last[@current] <<
|
|
43
|
+
str = string.strip
|
|
44
|
+
@result.last[@current] << str unless str.empty?
|
|
41
45
|
end
|
|
42
|
-
|
|
46
|
+
|
|
43
47
|
def start_element name, attrs = []
|
|
44
48
|
case name.downcase
|
|
45
|
-
when @ws_object_name
|
|
49
|
+
when @ws_object_name
|
|
46
50
|
@result << Hash.new
|
|
47
51
|
when @ws_array_name
|
|
48
52
|
;
|
|
49
53
|
else
|
|
50
|
-
@current = name
|
|
51
|
-
@result.last[@current] = ""
|
|
54
|
+
@current = name
|
|
55
|
+
@result.last[@current] = String.new("")
|
|
52
56
|
end
|
|
53
57
|
end
|
|
54
|
-
|
|
58
|
+
|
|
55
59
|
def end_element name
|
|
56
60
|
if @current && @result.last[@current].empty?
|
|
57
61
|
@result.last.delete(@current)
|
|
@@ -59,7 +63,7 @@ class IERail
|
|
|
59
63
|
@current = nil
|
|
60
64
|
end
|
|
61
65
|
end
|
|
62
|
-
|
|
66
|
+
|
|
63
67
|
# Get ALL the stations!
|
|
64
68
|
# Returns array of Station objects, and each object responds to
|
|
65
69
|
# {
|
|
@@ -72,10 +76,10 @@ class IERail
|
|
|
72
76
|
#
|
|
73
77
|
def stations
|
|
74
78
|
ier = IERailGet.new("getAllStationsXML?", "arrayofobjstation", "objstation")
|
|
75
|
-
|
|
79
|
+
|
|
76
80
|
ier.response.map { |s| Station.new(s) }
|
|
77
81
|
end
|
|
78
|
-
|
|
82
|
+
|
|
79
83
|
# Get ALL the trains! That are on the go at the moment.
|
|
80
84
|
# Returns array of Train objects, and each object responds to
|
|
81
85
|
# {
|
|
@@ -90,10 +94,10 @@ class IERail
|
|
|
90
94
|
#
|
|
91
95
|
def trains
|
|
92
96
|
ier = IERailGet.new("getCurrentTrainsXML?", "arrayofobjtrainpositions", "objtrainpositions")
|
|
93
|
-
|
|
97
|
+
|
|
94
98
|
ier.response.map { |t| Train.new(t) }
|
|
95
99
|
end
|
|
96
|
-
|
|
100
|
+
|
|
97
101
|
# Get train information for a particular station, by station name. This gives data on trains thru that station
|
|
98
102
|
# Returns array of StationData objects, and each object responds to
|
|
99
103
|
# {
|
|
@@ -122,21 +126,21 @@ class IERail
|
|
|
122
126
|
#
|
|
123
127
|
def station(name)
|
|
124
128
|
ier = IERailGet.new("getStationDataByNameXML?StationDesc=#{name}", "arrayofobjstationdata", "objstationdata")
|
|
125
|
-
|
|
129
|
+
|
|
126
130
|
ier.response.map { |sd| StationData.new(sd) }
|
|
127
131
|
end
|
|
128
|
-
|
|
129
|
-
# Get train information for a particular station, by station name, within the time period in minutes from now.
|
|
132
|
+
|
|
133
|
+
# Get train information for a particular station, by station name, within the time period in minutes from now.
|
|
130
134
|
# This gives data on trains thru that station.
|
|
131
135
|
# Returns array of StationData objects, and each obj looks like the one for IERail#station
|
|
132
136
|
# Will return an empty array if no information.
|
|
133
137
|
#
|
|
134
138
|
def station_times(name, mins)
|
|
135
139
|
ier = IERailGet.new("getStationDataByNameXML_withNumMins?StationDesc=#{name}&NumMins=#{mins}", "arrayofobjstationdata", "objstationdata")
|
|
136
|
-
|
|
140
|
+
|
|
137
141
|
ier.response.map { |sd| StationData.new(sd) }
|
|
138
142
|
end
|
|
139
|
-
|
|
143
|
+
|
|
140
144
|
# Get the movements of a particular train, by train code, on a date.
|
|
141
145
|
# If no date is supplied assume train has run/is running today.
|
|
142
146
|
#
|
|
@@ -153,10 +157,10 @@ class IERail
|
|
|
153
157
|
#
|
|
154
158
|
def train_movements(code, date=Time.now)
|
|
155
159
|
ier = IERailGet.new("getTrainMovementsXML?TrainId=#{code}&TrainDate=#{date.strftime("%d/%m/%Y")}", "ArrayOfObjTrainMovements", "ObjTrainMovements")
|
|
156
|
-
|
|
160
|
+
|
|
157
161
|
ier.response.map{ |tm| TrainMovement.new(tm) }
|
|
158
162
|
end
|
|
159
|
-
|
|
163
|
+
|
|
160
164
|
# Find station codes and descriptions using a partial string to match the station name
|
|
161
165
|
# Returns an array of Structs that each respond to
|
|
162
166
|
# {
|
|
@@ -168,8 +172,11 @@ class IERail
|
|
|
168
172
|
#
|
|
169
173
|
def find_station(partial)
|
|
170
174
|
ier = IERailGet.new("getStationsFilterXML?StationText=#{partial}", "ArrayOfObjStationFilter", "objStationFilter")
|
|
171
|
-
|
|
172
|
-
|
|
175
|
+
|
|
176
|
+
unless defined?(Struct::Station)
|
|
177
|
+
Struct.new("Station", :name, :description, :code)
|
|
178
|
+
end
|
|
179
|
+
|
|
173
180
|
ier.response.map do |st|
|
|
174
181
|
Struct::Station.new(st['StationDesc_sp'],
|
|
175
182
|
st['StationDesc'],
|
|
@@ -189,7 +196,7 @@ class IERail
|
|
|
189
196
|
direction = name.to_s.split('_').first.capitalize
|
|
190
197
|
|
|
191
198
|
ier = IERailGet.new("getStationDataByNameXML?StationDesc=#{args.first}", "arrayofobjstationdata", "objstationdata")
|
|
192
|
-
|
|
199
|
+
|
|
193
200
|
ier.response.select { |sd| sd['Direction'] == direction }.map { |sd| StationData.new(sd) }
|
|
194
201
|
end
|
|
195
202
|
end
|
data/lib/station.rb
CHANGED
data/lib/station_data.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class StationData
|
|
2
4
|
attr_reader :server_time, :train_code, :station_name, :station_code,
|
|
3
5
|
:status, :last_location, :due_in, :minutes_late, :minutes_early,
|
|
@@ -33,8 +35,16 @@ class StationData
|
|
|
33
35
|
is_departure_station = @station_name.eql?(@origin)
|
|
34
36
|
is_terminating_station = @station_name.eql?(@destination)
|
|
35
37
|
|
|
38
|
+
one_day = 86400
|
|
39
|
+
|
|
36
40
|
@expected_arrival = is_departure_station ? @origin_time : Time.parse(hash['Exparrival'])
|
|
37
41
|
@expected_departure = is_terminating_station ? @destination_time : Time.parse(hash['Expdepart'])
|
|
42
|
+
|
|
43
|
+
# The API returns expected arr/dep times as HH:MM, if this time has crossed midnight, we parse it as being
|
|
44
|
+
# earlier 'today'; this then throws off the before/after filters. Use the server time as a sanity check.
|
|
45
|
+
@expected_arrival = @expected_arrival + one_day if @expected_arrival < @server_time
|
|
46
|
+
@expected_departure = @expected_departure + one_day if @expected_departure < @server_time
|
|
47
|
+
|
|
38
48
|
@scheduled_arrival = is_departure_station ? @origin_time + off_schedule_minutes : Time.parse(hash['Scharrival'])
|
|
39
49
|
@scheduled_departure = is_terminating_station ? @destination_time + off_schedule_minutes : Time.parse(hash['Schdepart'])
|
|
40
50
|
@direction = hash['Direction']
|
data/lib/train.rb
CHANGED
data/lib/train_movement.rb
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class TrainMovement
|
|
2
|
-
|
|
4
|
+
|
|
3
5
|
attr_reader :location_full_name
|
|
4
6
|
|
|
5
7
|
def initialize hash
|
|
6
8
|
@train_code = hash['TrainCode']
|
|
7
9
|
@train_date = Time.parse hash['TrainDate']
|
|
8
|
-
@location_code = hash['LocationCode']
|
|
10
|
+
@location_code = hash['LocationCode']
|
|
9
11
|
@location_full_name = hash['LocationFullName']
|
|
10
12
|
@location_order = hash['LocationOrder'].to_i
|
|
11
13
|
@location_type = hash['LocationType']
|
|
@@ -19,7 +21,7 @@ class TrainMovement
|
|
|
19
21
|
@arrival = arrival_time.nil? ? @expected_arrival : Time.parse(arrival_time)
|
|
20
22
|
@departure = departure_time.nil? ? @expected_departure : Time.parse(departure_time)
|
|
21
23
|
end
|
|
22
|
-
|
|
24
|
+
|
|
23
25
|
def location
|
|
24
26
|
{code: @location_code, name: @location_full_name, stop_number: @location_order, type: @location_type}
|
|
25
27
|
end
|
|
@@ -27,11 +29,11 @@ class TrainMovement
|
|
|
27
29
|
def arrival
|
|
28
30
|
{scheduled: @scheduled_arrival, expected: @expected_arrival, actual: @arrival}
|
|
29
31
|
end
|
|
30
|
-
|
|
32
|
+
|
|
31
33
|
def departure
|
|
32
34
|
{scheduled: @scheduled_departure, expected: @expected_departure, actual: @departure}
|
|
33
35
|
end
|
|
34
|
-
|
|
36
|
+
|
|
35
37
|
def train
|
|
36
38
|
{code: @train_code, date: @train_date, origin: @train_origin}
|
|
37
39
|
end
|
data/test/unit/helper.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
require 'simplecov'
|
|
2
|
-
require 'coveralls'
|
|
3
2
|
require 'tzinfo'
|
|
4
3
|
require 'vcr'
|
|
5
4
|
require 'timecop'
|
|
6
|
-
require '
|
|
5
|
+
require 'date'
|
|
7
6
|
require 'minitest/autorun'
|
|
8
7
|
require 'ierail'
|
|
9
8
|
|
|
10
|
-
def
|
|
9
|
+
def helper_get_original_time(t)
|
|
10
|
+
t = Time.now if t.nil?
|
|
11
11
|
@when = Time.parse(t.to_s)
|
|
12
12
|
if TZInfo::Timezone.get('Europe/Dublin').current_period.dst?
|
|
13
13
|
unless @when.zone == 'IST'
|
|
@@ -16,12 +16,17 @@ def get_original_time(t)
|
|
|
16
16
|
else
|
|
17
17
|
@when -= @when.utc_offset
|
|
18
18
|
end
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
@when
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
def helper_get_thirty_mins
|
|
24
|
+
thirty_mins = Time.now + (60 * 30)
|
|
25
|
+
" #{thirty_mins.hour}:#{thirty_mins.min}" # "HH:MM"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
|
29
|
+
SimpleCov::Formatter::HTMLFormatter
|
|
30
|
+
])
|
|
31
|
+
|
|
27
32
|
SimpleCov.start
|
data/test/unit/ierail.rb
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
$:.unshift(File.join(File.dirname(__FILE__), '..','..', 'lib'))
|
|
2
3
|
|
|
3
4
|
require_relative 'helper'
|
|
4
5
|
|
|
5
|
-
class IERailTest <
|
|
6
|
+
class IERailTest < Minitest::Test
|
|
6
7
|
def setup
|
|
7
8
|
@ir = IERail.new
|
|
8
9
|
|
|
@@ -14,7 +15,7 @@ class IERailTest < MiniTest::Unit::TestCase
|
|
|
14
15
|
|
|
15
16
|
def test_that_the_train_directions_are_correct
|
|
16
17
|
VCR.use_cassette('northbound') do |cassette|
|
|
17
|
-
time =
|
|
18
|
+
time = helper_get_original_time(cassette.originally_recorded_at)
|
|
18
19
|
|
|
19
20
|
Timecop.freeze(time || Time.now) do
|
|
20
21
|
northbound_train = @ir.northbound_from('Dublin Connolly').sample
|
|
@@ -22,7 +23,7 @@ class IERailTest < MiniTest::Unit::TestCase
|
|
|
22
23
|
end
|
|
23
24
|
end
|
|
24
25
|
VCR.use_cassette('northbound') do |cassette|
|
|
25
|
-
time =
|
|
26
|
+
time = helper_get_original_time(cassette.originally_recorded_at)
|
|
26
27
|
|
|
27
28
|
Timecop.freeze(time || Time.now) do
|
|
28
29
|
southbound_train = @ir.southbound_from('Dublin Connolly').sample
|
|
@@ -33,7 +34,7 @@ class IERailTest < MiniTest::Unit::TestCase
|
|
|
33
34
|
|
|
34
35
|
def test_that_an_empty_array_is_returned_when_no_data
|
|
35
36
|
VCR.use_cassette('westbound') do |cassette|
|
|
36
|
-
time =
|
|
37
|
+
time = helper_get_original_time(cassette.originally_recorded_at)
|
|
37
38
|
|
|
38
39
|
Timecop.freeze(time || Time.now) do
|
|
39
40
|
nonexistant = @ir.westbound_from('Clongriffin')
|
|
@@ -44,42 +45,33 @@ class IERailTest < MiniTest::Unit::TestCase
|
|
|
44
45
|
|
|
45
46
|
def test_that_the_before_time_constraint_works
|
|
46
47
|
VCR.use_cassette('northbound') do |cassette|
|
|
47
|
-
time =
|
|
48
|
-
|
|
48
|
+
time = helper_get_original_time(cassette.originally_recorded_at)
|
|
49
49
|
Timecop.freeze(time || Time.now) do
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
time = "#{thirty_mins.hour}:#{thirty_mins.min}" # "HH:MM"
|
|
53
|
-
before_train = @ir.southbound_from('Dublin Connolly').before(time).sample
|
|
54
|
-
assert before_train.expected_departure <= thirty_mins
|
|
50
|
+
before_train = @ir.southbound_from('Dublin Connolly').before(helper_get_thirty_mins()).sample
|
|
51
|
+
assert before_train.expected_arrival.to_i - before_train.server_time.to_i < (30 * 60)
|
|
55
52
|
end
|
|
56
53
|
end
|
|
57
54
|
end
|
|
58
55
|
|
|
59
56
|
def test_that_the_after_time_constraint_works
|
|
60
57
|
VCR.use_cassette('southbound') do |cassette|
|
|
61
|
-
time =
|
|
62
|
-
|
|
58
|
+
time = helper_get_original_time(cassette.originally_recorded_at)
|
|
63
59
|
Timecop.freeze(time || Time.now) do
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
time = "#{thirty_mins.hour}:#{thirty_mins.min}" # "HH:MM"
|
|
67
|
-
after_train = @ir.southbound_from('Dublin Connolly').after(time).sample
|
|
68
|
-
assert after_train.expected_departure >= thirty_mins
|
|
60
|
+
after_train = @ir.southbound_from('Dublin Connolly').after(helper_get_thirty_mins()).sample
|
|
61
|
+
assert after_train.expected_arrival.to_i - after_train.server_time.to_i >= (30 * 60)
|
|
69
62
|
end
|
|
70
63
|
end
|
|
71
64
|
end
|
|
72
65
|
|
|
73
66
|
def test_that_the_in_constraint_works
|
|
74
67
|
VCR.use_cassette('southbound_from') do |cassette|
|
|
75
|
-
time =
|
|
68
|
+
time = helper_get_original_time(cassette.originally_recorded_at)
|
|
76
69
|
|
|
77
70
|
Timecop.freeze(time || Time.now) do
|
|
78
71
|
mins = 30
|
|
79
72
|
thirty_mins = Time.now + (60 * mins)
|
|
80
73
|
time = "#{thirty_mins.hour}:#{thirty_mins.min}" # "HH:MM"
|
|
81
74
|
southbounds = @ir.southbound_from('Dublin Connolly')
|
|
82
|
-
|
|
83
75
|
before_train = southbounds.before(time)
|
|
84
76
|
|
|
85
77
|
in_half_an_hour = southbounds.in(mins)
|
|
@@ -93,7 +85,7 @@ class IERailTest < MiniTest::Unit::TestCase
|
|
|
93
85
|
|
|
94
86
|
def test_station_times
|
|
95
87
|
VCR.use_cassette('station_times') do |cassette|
|
|
96
|
-
time =
|
|
88
|
+
time = helper_get_original_time(cassette.originally_recorded_at)
|
|
97
89
|
|
|
98
90
|
Timecop.freeze(time || Time.now) do
|
|
99
91
|
station_data = @ir.station_times('Dublin Connolly',30).sample
|
|
@@ -104,7 +96,7 @@ class IERailTest < MiniTest::Unit::TestCase
|
|
|
104
96
|
|
|
105
97
|
def test_find_station
|
|
106
98
|
VCR.use_cassette('find_station') do |cassette|
|
|
107
|
-
time =
|
|
99
|
+
time = helper_get_original_time(cassette.originally_recorded_at)
|
|
108
100
|
|
|
109
101
|
Timecop.freeze(time || Time.now) do
|
|
110
102
|
station = @ir.find_station('Dublin Connolly').sample
|
|
@@ -115,7 +107,7 @@ class IERailTest < MiniTest::Unit::TestCase
|
|
|
115
107
|
|
|
116
108
|
def test_that_station_times_returns_station_data
|
|
117
109
|
VCR.use_cassette('station_times') do |cassette|
|
|
118
|
-
time =
|
|
110
|
+
time = helper_get_original_time(cassette.originally_recorded_at)
|
|
119
111
|
|
|
120
112
|
Timecop.freeze(time || Time.now) do
|
|
121
113
|
train = @ir.station_times('Dublin Connolly', 30).sample #random train in next 30 mins
|
|
@@ -125,10 +117,10 @@ class IERailTest < MiniTest::Unit::TestCase
|
|
|
125
117
|
end
|
|
126
118
|
|
|
127
119
|
def test_that_station_times_equivalent_to_in
|
|
128
|
-
VCR.use_cassette('station_times') do
|
|
120
|
+
VCR.use_cassette('station_times') do
|
|
129
121
|
trains = @ir.station_times('Dublin Connolly', 30)
|
|
130
122
|
|
|
131
|
-
VCR.use_cassette('station') do
|
|
123
|
+
VCR.use_cassette('station') do
|
|
132
124
|
in_half_an_hour = @ir.station('Dublin Connolly').in(30)
|
|
133
125
|
|
|
134
126
|
assert_equal trains.count, in_half_an_hour.count
|
|
@@ -140,7 +132,7 @@ class IERailTest < MiniTest::Unit::TestCase
|
|
|
140
132
|
end
|
|
141
133
|
|
|
142
134
|
def test_that_found_station_is_a_struct_with_name_description_code
|
|
143
|
-
VCR.use_cassette('find_station') do
|
|
135
|
+
VCR.use_cassette('find_station') do
|
|
144
136
|
station = @ir.find_station('Dublin Connolly').sample
|
|
145
137
|
assert_equal station.class, Struct::Station
|
|
146
138
|
refute_nil station.name
|
data/test/unit/station.rb
CHANGED
data/test/unit/station_data.rb
CHANGED
|
@@ -2,7 +2,7 @@ $:.unshift(File.join(File.dirname(__FILE__), '..','..', 'lib'))
|
|
|
2
2
|
|
|
3
3
|
require_relative 'helper'
|
|
4
4
|
|
|
5
|
-
class StationDataTest <
|
|
5
|
+
class StationDataTest < Minitest::Test
|
|
6
6
|
def setup
|
|
7
7
|
ir = IERail.new
|
|
8
8
|
|
|
@@ -29,10 +29,6 @@ class StationDataTest < MiniTest::Unit::TestCase
|
|
|
29
29
|
refute_empty @station_data.code
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
def test_that_there_is_a_query_time
|
|
33
|
-
refute_nil @station_data.query_time
|
|
34
|
-
end
|
|
35
|
-
|
|
36
32
|
def test_that_there_is_a_status
|
|
37
33
|
refute_empty @station_data.status
|
|
38
34
|
end
|