ruby-irail 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ruby-irail/packages/nmbs/api.rb +15 -17
- data/lib/version.rb +1 -1
- data/spec/packages/nmbs/api_spec.rb +35 -39
- metadata +9 -9
@@ -4,37 +4,35 @@ module IRail::API
|
|
4
4
|
STATIONS_URI = "stations/"
|
5
5
|
CONNECTIONS_URI = "connections/"
|
6
6
|
|
7
|
-
def stations
|
8
|
-
|
7
|
+
def stations(options = {})
|
8
|
+
station_list_url = build_station_list_url
|
9
|
+
xml_station_list = get_station_list(station_list_url, options)
|
10
|
+
IRail::NMBS::DocumentParser.parse_stations(xml_station_list)
|
9
11
|
end
|
10
12
|
|
11
|
-
def connections(origin_station, destination_station)
|
13
|
+
def connections(origin_station, destination_station, options = {})
|
12
14
|
connections_url = build_connections_url
|
13
|
-
xml_connections = get_connections(connections_url, origin_station, destination_station)
|
15
|
+
xml_connections = get_connections(connections_url, origin_station, destination_station, options)
|
14
16
|
IRail::NMBS::DocumentParser.parse_connections(xml_connections)
|
15
17
|
end
|
16
18
|
|
17
|
-
def
|
18
|
-
|
19
|
-
xml_station_list = get_station_list(station_list_url)
|
20
|
-
IRail::NMBS::DocumentParser.parse_stations(xml_station_list)
|
21
|
-
end
|
22
|
-
|
23
|
-
def get_connections(connections_url, origin_station, destination_station)
|
24
|
-
options = build_connections_option_hash(origin_station, destination_station)
|
19
|
+
def get_connections(connections_url, origin_station, destination_station, options = {})
|
20
|
+
options = build_connections_option_hash(origin_station, destination_station, options)
|
25
21
|
IRail::Request.get(connections_url, options)
|
26
22
|
end
|
27
23
|
|
28
|
-
def get_station_list(station_list_url)
|
29
|
-
|
24
|
+
def get_station_list(station_list_url, options = {})
|
25
|
+
options = { :query => options } if options.any?
|
26
|
+
IRail::Request.get(station_list_url, options)
|
30
27
|
end
|
31
28
|
|
32
29
|
private
|
33
|
-
def build_connections_option_hash(origin_station, destination_station)
|
30
|
+
def build_connections_option_hash(origin_station, destination_station, options = {})
|
34
31
|
{
|
35
|
-
:query => {
|
32
|
+
:query => options.merge({
|
36
33
|
:from => origin_station.name,
|
37
|
-
:to => destination_station.name
|
34
|
+
:to => destination_station.name
|
35
|
+
})
|
38
36
|
}
|
39
37
|
end
|
40
38
|
|
data/lib/version.rb
CHANGED
@@ -3,37 +3,13 @@ require_relative "../../../lib/ruby-irail/packages/nmbs/api.rb"
|
|
3
3
|
describe IRail::API::NMBS do
|
4
4
|
let(:irail) { IRail::API::NMBS.new }
|
5
5
|
|
6
|
-
describe :stations do
|
7
|
-
let(:stations) { mock("Stations") }
|
8
|
-
let(:fetched_stations) { mock("Fetched stations") }
|
9
|
-
|
10
|
-
before :each do
|
11
|
-
irail.stub(:get_stations => fetched_stations)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "returns the stations when they were already fetched" do
|
15
|
-
irail.instance_variable_set(:@stations, stations)
|
16
|
-
irail.stations.should eql stations
|
17
|
-
end
|
18
|
-
|
19
|
-
context "when stations have not been fetched yet" do
|
20
|
-
it "fetches them" do
|
21
|
-
irail.should_receive(:get_stations)
|
22
|
-
irail.stations
|
23
|
-
end
|
24
|
-
|
25
|
-
it "returns them" do
|
26
|
-
irail.stations.should eql fetched_stations
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
6
|
describe :connections do
|
32
7
|
let(:origin_station) { mock("Origin station") }
|
33
8
|
let(:destination_station) { mock("Destination station") }
|
34
9
|
let(:connections_url) { mock("Connections url") }
|
35
10
|
let(:xml_connections) { mock("Xml connections") }
|
36
11
|
let(:connections) { mock("Connections") }
|
12
|
+
let(:options) { mock("Options") }
|
37
13
|
|
38
14
|
before :each do
|
39
15
|
irail.stub(:build_connections_url => connections_url)
|
@@ -47,8 +23,8 @@ describe IRail::API::NMBS do
|
|
47
23
|
end
|
48
24
|
|
49
25
|
it "gets the connections" do
|
50
|
-
irail.should_receive(:get_connections).with(connections_url, origin_station, destination_station)
|
51
|
-
irail.connections(origin_station, destination_station)
|
26
|
+
irail.should_receive(:get_connections).with(connections_url, origin_station, destination_station, options)
|
27
|
+
irail.connections(origin_station, destination_station, options)
|
52
28
|
end
|
53
29
|
|
54
30
|
it "returns the parsed connections" do
|
@@ -56,10 +32,11 @@ describe IRail::API::NMBS do
|
|
56
32
|
end
|
57
33
|
end
|
58
34
|
|
59
|
-
describe :
|
35
|
+
describe :stations do
|
60
36
|
let(:station_list_url) { mock("Url") }
|
61
37
|
let(:xml_station_list) { mock("Xml station list") }
|
62
38
|
let(:stations) { mock("Stations") }
|
39
|
+
let(:options) { mock("Options") }
|
63
40
|
|
64
41
|
before :each do
|
65
42
|
irail.stub(:build_station_list_url => station_list_url)
|
@@ -69,16 +46,16 @@ describe IRail::API::NMBS do
|
|
69
46
|
|
70
47
|
it "builds the station list url" do
|
71
48
|
irail.should_receive(:build_station_list_url)
|
72
|
-
irail.
|
49
|
+
irail.stations(options)
|
73
50
|
end
|
74
51
|
|
75
52
|
it "gets the xml station list" do
|
76
|
-
irail.should_receive(:get_station_list).with(station_list_url)
|
77
|
-
irail.
|
53
|
+
irail.should_receive(:get_station_list).with(station_list_url, options)
|
54
|
+
irail.stations(options)
|
78
55
|
end
|
79
56
|
|
80
57
|
it "returns the parsed stations" do
|
81
|
-
irail.
|
58
|
+
irail.stations(options).should eql stations
|
82
59
|
end
|
83
60
|
end
|
84
61
|
|
@@ -88,6 +65,7 @@ describe IRail::API::NMBS do
|
|
88
65
|
let(:connections_url) { mock("Connections url") }
|
89
66
|
let(:options_hash) { mock("Options hash") }
|
90
67
|
let(:response) { mock("Response") }
|
68
|
+
let(:options) { mock("Oprions") }
|
91
69
|
|
92
70
|
before :each do
|
93
71
|
irail.stub(:build_connections_option_hash => options_hash)
|
@@ -95,8 +73,8 @@ describe IRail::API::NMBS do
|
|
95
73
|
end
|
96
74
|
|
97
75
|
it "builds the options hash" do
|
98
|
-
irail.should_receive(:build_connections_option_hash).with(origin_station, destination_station)
|
99
|
-
irail.get_connections(connections_url, origin_station, destination_station)
|
76
|
+
irail.should_receive(:build_connections_option_hash).with(origin_station, destination_station, options)
|
77
|
+
irail.get_connections(connections_url, origin_station, destination_station, options)
|
100
78
|
end
|
101
79
|
|
102
80
|
it "calls the connections url through a get request" do
|
@@ -117,13 +95,31 @@ describe IRail::API::NMBS do
|
|
117
95
|
IRail::Request.stub(:get => response)
|
118
96
|
end
|
119
97
|
|
120
|
-
|
121
|
-
|
122
|
-
|
98
|
+
context "when there are no options" do
|
99
|
+
let(:options) { {} }
|
100
|
+
|
101
|
+
it "calls the station list url through a get request" do
|
102
|
+
IRail::Request.should_receive(:get).with(url, options)
|
103
|
+
irail.get_station_list(url, options)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "returns the response" do
|
107
|
+
irail.get_station_list(url, options).should eql response
|
108
|
+
end
|
123
109
|
end
|
124
110
|
|
125
|
-
|
126
|
-
|
111
|
+
context "when there are options" do
|
112
|
+
let(:options) { {:a => 1} }
|
113
|
+
|
114
|
+
it "calls the station list url with query options" do
|
115
|
+
expected_options = { :query => options }
|
116
|
+
IRail::Request.should_receive(:get).with(url, expected_options)
|
117
|
+
irail.get_station_list(url, options)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "returns the response" do
|
121
|
+
irail.get_station_list(url, options).should eql response
|
122
|
+
end
|
127
123
|
end
|
128
124
|
end
|
129
125
|
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-07-18 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70214013650340 !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: *70214013650340
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: httparty
|
27
|
-
requirement: &
|
27
|
+
requirement: &70214013649860 !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: *70214013649860
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: roxml
|
38
|
-
requirement: &
|
38
|
+
requirement: &70214013649380 !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: *70214013649380
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: nokogiri
|
49
|
-
requirement: &
|
49
|
+
requirement: &70214013648800 !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: *70214013648800
|
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:
|