ruby-irail 0.3.0 → 0.4.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.
- data/lib/ruby-irail/packages/nmbs/api.rb +45 -0
- data/lib/ruby-irail/packages/nmbs/models/liveboard.rb +13 -0
- data/lib/ruby-irail/packages/nmbs/parser/document_parser.rb +4 -0
- data/lib/version.rb +1 -1
- data/spec/packages/nmbs/api_spec.rb +110 -0
- data/spec/packages/nmbs/models/liveboard_spec.rb +17 -0
- data/spec/packages/nmbs/parser/document_parser_spec.rb +22 -0
- metadata +13 -10
@@ -4,6 +4,7 @@ module IRail::API
|
|
4
4
|
STATIONS_URI = "stations/"
|
5
5
|
CONNECTIONS_URI = "connections/"
|
6
6
|
VEHICLE_URI = "vehicle/"
|
7
|
+
LIVEBOARD_URI = "liveboard/"
|
7
8
|
|
8
9
|
def stations(options = {})
|
9
10
|
station_list_url = build_station_list_url
|
@@ -23,6 +24,18 @@ module IRail::API
|
|
23
24
|
IRail::NMBS::DocumentParser.parse_vehicle(xml_vehicle)
|
24
25
|
end
|
25
26
|
|
27
|
+
def departures(station_id, options = {})
|
28
|
+
liveboard_url = build_liveboard_url
|
29
|
+
xml_departures = get_departures(liveboard_url, station_id, options)
|
30
|
+
IRail::NMBS::DocumentParser.parse_liveboard(xml_departures)
|
31
|
+
end
|
32
|
+
|
33
|
+
def arrivals(station_id, options = {})
|
34
|
+
liveboard_url = build_liveboard_url
|
35
|
+
xml_arrivals = get_arrivals(liveboard_url, station_id, options)
|
36
|
+
IRail::NMBS::DocumentParser.parse_liveboard(xml_arrivals)
|
37
|
+
end
|
38
|
+
|
26
39
|
def get_station_list(station_list_url, options = {})
|
27
40
|
options = { :query => options } if options.any?
|
28
41
|
IRail::Request.get(station_list_url, options)
|
@@ -38,6 +51,16 @@ module IRail::API
|
|
38
51
|
IRail::Request.get(vehicle_url, options)
|
39
52
|
end
|
40
53
|
|
54
|
+
def get_departures(liveboard_url, station_id, options = {})
|
55
|
+
options = build_departures_option_hash(station_id, options)
|
56
|
+
IRail::Request.get(liveboard_url, options)
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_arrivals(liveboard_url, station_id, options = {})
|
60
|
+
options = build_arrivals_option_hash(station_id, options)
|
61
|
+
IRail::Request.get(liveboard_url, options)
|
62
|
+
end
|
63
|
+
|
41
64
|
private
|
42
65
|
def build_connections_option_hash(origin_station, destination_station, options = {})
|
43
66
|
{
|
@@ -56,6 +79,24 @@ module IRail::API
|
|
56
79
|
}
|
57
80
|
end
|
58
81
|
|
82
|
+
def build_departures_option_hash(station_id, options = {})
|
83
|
+
{
|
84
|
+
:query => options.merge({
|
85
|
+
:id => station_id,
|
86
|
+
:arrdep => "DEP"
|
87
|
+
})
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
def build_arrivals_option_hash(station_id, options = {})
|
92
|
+
{
|
93
|
+
:query => options.merge({
|
94
|
+
:id => station_id,
|
95
|
+
:arrdep => "ARR"
|
96
|
+
})
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
59
100
|
def build_station_list_url
|
60
101
|
[API_URL, STATIONS_URI].join('/')
|
61
102
|
end
|
@@ -67,5 +108,9 @@ module IRail::API
|
|
67
108
|
def build_vehicle_url
|
68
109
|
[API_URL, VEHICLE_URI].join('/')
|
69
110
|
end
|
111
|
+
|
112
|
+
def build_liveboard_url
|
113
|
+
[API_URL, LIVEBOARD_URI].join('/')
|
114
|
+
end
|
70
115
|
end
|
71
116
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "roxml"
|
2
|
+
|
3
|
+
module IRail::NMBS
|
4
|
+
class Liveboard
|
5
|
+
include ROXML
|
6
|
+
|
7
|
+
xml_name 'liveboard'
|
8
|
+
|
9
|
+
xml_accessor :station, :as => Station
|
10
|
+
xml_accessor :departures, :from => "departures/departure", :as => [Step]
|
11
|
+
xml_accessor :arrivals, :from => "arrivals/arrival", :as => [Step]
|
12
|
+
end
|
13
|
+
end
|
@@ -21,6 +21,10 @@ module IRail::NMBS
|
|
21
21
|
IRail::NMBS::VehicleInformation.from_xml(vehicle.to_s)
|
22
22
|
end
|
23
23
|
|
24
|
+
def self.parse_liveboard(xml_string)
|
25
|
+
IRail::NMBS::Liveboard.from_xml(xml_string)
|
26
|
+
end
|
27
|
+
|
24
28
|
def self.xml_vehicle(xml_string)
|
25
29
|
xml_payload = Nokogiri::XML(xml_string)
|
26
30
|
xml_payload.xpath(VEHICLE_XPATH)
|
data/lib/version.rb
CHANGED
@@ -87,6 +87,62 @@ describe IRail::API::NMBS do
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
+
describe :departures do
|
91
|
+
let(:liveboard_url) { mock("Url") }
|
92
|
+
let(:station_id) { mock("Station id") }
|
93
|
+
let(:options) { mock("Options") }
|
94
|
+
let(:liveboard) { mock("Liveboard") }
|
95
|
+
let(:xml_departures) { mock("Xml departures") }
|
96
|
+
|
97
|
+
before :each do
|
98
|
+
irail.stub(:build_liveboard_url => liveboard_url)
|
99
|
+
irail.stub(:get_departures => xml_departures)
|
100
|
+
IRail::NMBS::DocumentParser.stub(:parse_liveboard => liveboard)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "builds the liveboard url" do
|
104
|
+
irail.should_receive(:build_liveboard_url)
|
105
|
+
irail.departures(station_id, options)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "gets the departures xml" do
|
109
|
+
irail.should_receive(:get_departures).with(liveboard_url, station_id, options)
|
110
|
+
irail.departures(station_id, options)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "returns the liveboard" do
|
114
|
+
irail.departures(station_id, options).should eql liveboard
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe :arrivals do
|
119
|
+
let(:liveboard_url) { mock("Url") }
|
120
|
+
let(:station_id) { mock("Station id") }
|
121
|
+
let(:options) { mock("Options") }
|
122
|
+
let(:liveboard) { mock("Liveboard") }
|
123
|
+
let(:xml_arrivals) { mock("Xml arrivals") }
|
124
|
+
|
125
|
+
before :each do
|
126
|
+
irail.stub(:build_liveboard_url => liveboard_url)
|
127
|
+
irail.stub(:get_arrivals => xml_arrivals)
|
128
|
+
IRail::NMBS::DocumentParser.stub(:parse_liveboard => liveboard)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "builds the liveboard url" do
|
132
|
+
irail.should_receive(:build_liveboard_url)
|
133
|
+
irail.arrivals(station_id, options)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "gets the arrivals xml" do
|
137
|
+
irail.should_receive(:get_arrivals).with(liveboard_url, station_id, options)
|
138
|
+
irail.arrivals(station_id, options)
|
139
|
+
end
|
140
|
+
|
141
|
+
it "returns the parsed departures" do
|
142
|
+
irail.arrivals(station_id, options).should eql liveboard
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
90
146
|
describe :get_connections do
|
91
147
|
let(:origin_station) { mock("Origin station") }
|
92
148
|
let(:destination_station) { mock("Destination station") }
|
@@ -115,6 +171,60 @@ describe IRail::API::NMBS do
|
|
115
171
|
end
|
116
172
|
end
|
117
173
|
|
174
|
+
describe :get_departures do
|
175
|
+
let(:station_id) { mock("Station id") }
|
176
|
+
let(:options) { mock("Options") }
|
177
|
+
let(:liveboard_url) { mock("Liveboard url") }
|
178
|
+
let(:options_hash) { mock("Options hash") }
|
179
|
+
let(:response) { mock("Response") }
|
180
|
+
|
181
|
+
before :each do
|
182
|
+
irail.stub(:build_departures_option_hash => options_hash)
|
183
|
+
IRail::Request.stub(:get => response)
|
184
|
+
end
|
185
|
+
|
186
|
+
it "builds the options hash" do
|
187
|
+
irail.should_receive(:build_departures_option_hash).with(station_id, options)
|
188
|
+
irail.get_departures(liveboard_url, station_id, options)
|
189
|
+
end
|
190
|
+
|
191
|
+
it "calls the connections url through a get request" do
|
192
|
+
IRail::Request.should_receive(:get).with(liveboard_url, options_hash)
|
193
|
+
irail.get_departures(liveboard_url, station_id, options)
|
194
|
+
end
|
195
|
+
|
196
|
+
it "returns the response" do
|
197
|
+
irail.get_departures(liveboard_url, station_id, options).should eql response
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe :get_arrivals do
|
202
|
+
let(:station_id) { mock("Station id") }
|
203
|
+
let(:options) { mock("Options") }
|
204
|
+
let(:liveboard_url) { mock("Liveboard url") }
|
205
|
+
let(:options_hash) { mock("Options hash") }
|
206
|
+
let(:response) { mock("Response") }
|
207
|
+
|
208
|
+
before :each do
|
209
|
+
irail.stub(:build_arrivals_option_hash => options_hash)
|
210
|
+
IRail::Request.stub(:get => response)
|
211
|
+
end
|
212
|
+
|
213
|
+
it "builds the options hash" do
|
214
|
+
irail.should_receive(:build_arrivals_option_hash).with(station_id, options)
|
215
|
+
irail.get_arrivals(liveboard_url, station_id, options)
|
216
|
+
end
|
217
|
+
|
218
|
+
it "calls the connections url through a get request" do
|
219
|
+
IRail::Request.should_receive(:get).with(liveboard_url, options_hash)
|
220
|
+
irail.get_arrivals(liveboard_url, station_id, options)
|
221
|
+
end
|
222
|
+
|
223
|
+
it "returns the response" do
|
224
|
+
irail.get_arrivals(liveboard_url, station_id, options).should eql response
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
118
228
|
describe :get_station_list do
|
119
229
|
let(:url) { mock("Url") }
|
120
230
|
let(:response) { mock("Response") }
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative '../../../../lib/ruby-irail/packages/nmbs/models/liveboard.rb'
|
2
|
+
|
3
|
+
describe IRail::NMBS::Liveboard do
|
4
|
+
let(:liveboard) { IRail::NMBS::Liveboard.new }
|
5
|
+
|
6
|
+
it "has a station" do
|
7
|
+
liveboard.should respond_to(:station)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has many departures" do
|
11
|
+
liveboard.should respond_to(:departures)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has many arrivals" do
|
15
|
+
liveboard.should respond_to(:arrivals)
|
16
|
+
end
|
17
|
+
end
|
@@ -12,6 +12,9 @@ describe IRail::NMBS::DocumentParser do
|
|
12
12
|
class IRail::NMBS::Connection
|
13
13
|
end
|
14
14
|
|
15
|
+
class IRail::NMBS::Liveboard
|
16
|
+
end
|
17
|
+
|
15
18
|
describe :'self.parse_stations' do
|
16
19
|
let(:xml_string) { mock("Xml string") }
|
17
20
|
let(:xml_payload) { mock("Xml payload") }
|
@@ -109,4 +112,23 @@ describe IRail::NMBS::DocumentParser do
|
|
109
112
|
IRail::NMBS::DocumentParser.parse_vehicle(xml_string).should eql vehicle_instance
|
110
113
|
end
|
111
114
|
end
|
115
|
+
|
116
|
+
describe :'self.parse_liveboard' do
|
117
|
+
let(:xml_string) { mock("Xml string") }
|
118
|
+
let(:liveboard) { mock("Loveboard") }
|
119
|
+
let(:liveboard_instance) { mock("Liveboard instance") }
|
120
|
+
|
121
|
+
before :each do
|
122
|
+
IRail::NMBS::Liveboard.stub(:from_xml => liveboard_instance)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "creates a liveboard from the xml payload" do
|
126
|
+
IRail::NMBS::Liveboard.should_receive(:from_xml).with(xml_string)
|
127
|
+
IRail::NMBS::DocumentParser.parse_liveboard(xml_string)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "returns a liveboard instance" do
|
131
|
+
IRail::NMBS::DocumentParser.parse_liveboard(xml_string).should eql liveboard_instance
|
132
|
+
end
|
133
|
+
end
|
112
134
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-irail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-19 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70221051588820 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70221051588820
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: httparty
|
27
|
-
requirement: &
|
27
|
+
requirement: &70221051588400 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70221051588400
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: roxml
|
38
|
-
requirement: &
|
38
|
+
requirement: &70221051587980 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70221051587980
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: nokogiri
|
49
|
-
requirement: &
|
49
|
+
requirement: &70221051587560 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70221051587560
|
58
58
|
description: IRail makes Belgian railway schedule easily available for anyone. This
|
59
59
|
is a Ruby wrapper for their API.
|
60
60
|
email:
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- lib/ruby-irail/packages/mivbstib/parser/station_parser.rb
|
80
80
|
- lib/ruby-irail/packages/nmbs/api.rb
|
81
81
|
- lib/ruby-irail/packages/nmbs/models/connection.rb
|
82
|
+
- lib/ruby-irail/packages/nmbs/models/liveboard.rb
|
82
83
|
- lib/ruby-irail/packages/nmbs/models/platform.rb
|
83
84
|
- lib/ruby-irail/packages/nmbs/models/station.rb
|
84
85
|
- lib/ruby-irail/packages/nmbs/models/step.rb
|
@@ -98,6 +99,7 @@ files:
|
|
98
99
|
- spec/packages/mivbstib/parser/station_parser_spec.rb
|
99
100
|
- spec/packages/nmbs/api_spec.rb
|
100
101
|
- spec/packages/nmbs/models/connection_spec.rb
|
102
|
+
- spec/packages/nmbs/models/liveboard_spec.rb
|
101
103
|
- spec/packages/nmbs/models/platform_spec.rb
|
102
104
|
- spec/packages/nmbs/models/station_spec.rb
|
103
105
|
- spec/packages/nmbs/models/step_spec.rb
|
@@ -140,6 +142,7 @@ test_files:
|
|
140
142
|
- spec/packages/mivbstib/parser/station_parser_spec.rb
|
141
143
|
- spec/packages/nmbs/api_spec.rb
|
142
144
|
- spec/packages/nmbs/models/connection_spec.rb
|
145
|
+
- spec/packages/nmbs/models/liveboard_spec.rb
|
143
146
|
- spec/packages/nmbs/models/platform_spec.rb
|
144
147
|
- spec/packages/nmbs/models/station_spec.rb
|
145
148
|
- spec/packages/nmbs/models/step_spec.rb
|