ratis 3.3.2 → 3.3.3
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/Gemfile.lock +1 -1
- data/lib/ratis/next_bus2.rb +4 -2
- data/lib/ratis/version.rb +1 -1
- data/spec/ratis/next_bus2_spec.rb +100 -109
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/lib/ratis/next_bus2.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Ratis
|
2
|
-
|
2
|
+
# This method returns the time of the next vehicles at a location based on TA ID or
|
3
|
+
# ATIS stop ID only. The date and time of the query are “today” and “now.” The response
|
4
|
+
# is a subset of the data returned by the Nextbus method.
|
3
5
|
class NextBus2
|
4
6
|
|
5
7
|
attr_accessor :stops, :runs
|
@@ -47,7 +49,7 @@ module Ratis
|
|
47
49
|
stops = response.to_array :nextbus2_response, :stops, :stop
|
48
50
|
runs = response.to_array :nextbus2_response, :runs, :run
|
49
51
|
|
50
|
-
|
52
|
+
NextBus2.new stops, runs
|
51
53
|
end
|
52
54
|
|
53
55
|
# Gets description of first stop
|
data/lib/ratis/version.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
# NOTE: this should be called NextBus2 or something as that's the API call it really makes.
|
4
|
-
# need to find all places where this is used and update them before being able to push a new
|
5
|
-
# gem version for this backwards breaking change
|
6
3
|
describe Ratis::NextBus2 do
|
7
4
|
before do
|
8
5
|
Ratis.reset
|
@@ -12,137 +9,131 @@ describe Ratis::NextBus2 do
|
|
12
9
|
end
|
13
10
|
end
|
14
11
|
|
12
|
+
let(:empty_body){ {:nextbus_response => {:atstop => {:service => []}}} }
|
13
|
+
|
15
14
|
describe '#where' do
|
16
15
|
before do
|
17
16
|
# appid
|
18
17
|
# a short string that can be used to separate requests from different applications or different modules with
|
19
18
|
# Optional (highly recommended)
|
20
|
-
@
|
21
|
-
@conditions = {:stop_id =>
|
19
|
+
@stop_id = 10050
|
20
|
+
@conditions = {:stop_id => @stop_id,
|
22
21
|
:app_id => 'ratis-specs'}
|
23
22
|
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
x = 1
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'runs' do
|
36
|
-
pending
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe 'single next bus at 10496' do
|
24
|
+
describe 'single next bus' do
|
25
|
+
it "only makes one request" do
|
26
|
+
# false just to stop further processing of response
|
27
|
+
Ratis::Request.should_receive(:get).once.and_call_original
|
28
|
+
Ratis::NextBus.where(@conditions.dup)
|
29
|
+
end
|
41
30
|
|
42
|
-
|
43
|
-
|
31
|
+
it 'requests the correct SOAP action with args' do
|
32
|
+
Ratis::Request.should_receive(:get) do |action, options|
|
33
|
+
action.should eq('Nextbus2')
|
34
|
+
options["Stopid"].should eq(@stop_id)
|
44
35
|
|
45
|
-
|
46
|
-
stub_atis_request.to_return( atis_response 'Nextbus2', '1.3', '0', <<-BODY )
|
47
|
-
<Input>
|
48
|
-
<Stopid>10496</Stopid>
|
49
|
-
<Atisstopid>0</Atisstopid>
|
50
|
-
<Route></Route>
|
51
|
-
<Runs>999</Runs>
|
52
|
-
<Xmode></Xmode>
|
53
|
-
<Date>#{ Time.now.strftime '%m/%d/%y' }</Date>
|
54
|
-
<Time>#{ Time.now.strftime '%H:%M %p' }</Time>
|
55
|
-
</Input>
|
56
|
-
<Stops>
|
57
|
-
<Stop>
|
58
|
-
<Stopid>10496</Stopid>
|
59
|
-
<Atisstopid>366</Atisstopid>
|
60
|
-
<Stopstatustype>N</Stopstatustype>
|
61
|
-
<Description>FILLMORE ST & CENTRAL AVE</Description>
|
62
|
-
<Lat>33.454483</Lat>
|
63
|
-
<Long>-112.073307</Long>
|
64
|
-
<Stopposition>G</Stopposition>
|
65
|
-
<Heading>EB</Heading>
|
66
|
-
<Side>Far</Side>
|
67
|
-
</Stop>
|
68
|
-
</Stops>
|
69
|
-
<Runs>
|
70
|
-
<Run>
|
71
|
-
<Route>7</Route>
|
72
|
-
<Sign>7 7th Street to Union Hills Via Cent Station</Sign>
|
73
|
-
<Operator>AP</Operator>
|
74
|
-
<Direction>N</Direction>
|
75
|
-
<Status>N</Status>
|
76
|
-
<Servicetype>W</Servicetype>
|
77
|
-
<Routetype>B</Routetype>
|
78
|
-
<Triptime>#{ next_bus_time_scheduled }</Triptime>
|
79
|
-
<Tripid>85-20</Tripid>
|
80
|
-
<Adherence>0</Adherence>
|
81
|
-
<Estimatedtime>#{ next_bus_time_estimated }</Estimatedtime>
|
82
|
-
<Polltime></Polltime>
|
83
|
-
<Lat></Lat>
|
84
|
-
<Long></Long>
|
85
|
-
<Block>22</Block>
|
86
|
-
<Exception></Exception>
|
87
|
-
<Atisstopid>366</Atisstopid>
|
88
|
-
<Stopid>10496</Stopid>
|
89
|
-
</Run>
|
90
|
-
</Runs>
|
91
|
-
BODY
|
92
|
-
|
93
|
-
# @next_bus = Ratis::NextBus2.where :stop_id => 10496, :app_id => 'web'
|
94
|
-
end
|
95
|
-
|
96
|
-
describe '#where' do
|
36
|
+
end.and_return(double('response', :success? => false, :body => empty_body)) # false only to stop further running
|
97
37
|
|
98
|
-
|
99
|
-
pending
|
100
|
-
an_atis_request.should have_been_made.times 1
|
38
|
+
Ratis::NextBus2.where(@conditions.dup)
|
101
39
|
end
|
102
40
|
|
103
41
|
it 'requests the correct SOAP action' do
|
104
|
-
|
105
|
-
|
42
|
+
response = Ratis::NextBus2.where(@conditions.dup)
|
43
|
+
expect(response.stops).to_not be_empty
|
44
|
+
expect(response.runs).to_not be_empty
|
106
45
|
end
|
107
46
|
|
108
|
-
it
|
109
|
-
|
110
|
-
|
47
|
+
it "should raise error when no stop id provided" do
|
48
|
+
lambda {
|
49
|
+
Ratis::NextBus2.where(@conditions.dup.merge(:stop_id => nil))
|
50
|
+
}.should raise_error(ArgumentError, 'You must provide a stop ID')
|
111
51
|
end
|
112
52
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
:
|
123
|
-
|
124
|
-
]
|
125
|
-
|
53
|
+
describe 'stops' do
|
54
|
+
# TODO: should return Stops not hashes
|
55
|
+
it 'should set the stop values to instance vars' do
|
56
|
+
response = Ratis::NextBus2.where(@conditions.dup)
|
57
|
+
stop = response.stops.first
|
58
|
+
|
59
|
+
expect(response).to be_a(Ratis::NextBus2)
|
60
|
+
expect(response.stops).to be_a(Array)
|
61
|
+
|
62
|
+
expect(stop[:area]).to eq("Phoenix")
|
63
|
+
expect(stop[:atisstopid]).to eq("3317")
|
64
|
+
expect(stop[:stopposition]).to eq("O")
|
65
|
+
expect(stop[:description]).to eq("CENTRAL AVE & DOBBINS RD")
|
66
|
+
expect(stop[:stopstatustype]).to eq("N")
|
67
|
+
expect(stop[:lat]).to eq("33.363692")
|
68
|
+
expect(stop[:long]).to eq("-112.073191")
|
69
|
+
expect(stop[:side]).to eq("Far")
|
70
|
+
expect(stop[:stopid]).to eq("10050")
|
71
|
+
expect(stop[:heading]).to eq("NB")
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should return an empty array if the api request isn't successful" do
|
75
|
+
Ratis::Request.should_receive(:get) do |action, options|
|
76
|
+
action.should eq('Nextbus2')
|
77
|
+
options["Stopid"].should eq(@stop_id)
|
78
|
+
|
79
|
+
end.and_return(double('response', :success? => false, :body => empty_body)) # false only to stop further running
|
80
|
+
|
81
|
+
response = Ratis::NextBus2.where(@conditions.dup)
|
82
|
+
expect(response).to be_a(Array)
|
83
|
+
expect(response).to be_empty
|
84
|
+
end
|
85
|
+
end
|
126
86
|
|
127
|
-
|
87
|
+
describe 'runs' do
|
88
|
+
# TODO: should return Runs not hashes
|
89
|
+
it "should set the run values to instance vars" do
|
90
|
+
response = Ratis::NextBus2.where(@conditions.dup)
|
91
|
+
run = response.runs.first
|
92
|
+
|
93
|
+
expect(response).to be_a(Ratis::NextBus2)
|
94
|
+
expect(response.runs).to be_a(Array)
|
95
|
+
|
96
|
+
expect(run[:operator]).to eq "AP"
|
97
|
+
expect(run[:status]).to eq "N"
|
98
|
+
expect(run[:sign]).to eq "0 CENTRAL North to Dunlap/3rd St."
|
99
|
+
expect(run[:triptime]).to_not be_nil #eq "12:29 PM"
|
100
|
+
expect(run[:triptime]).to_not be_empty
|
101
|
+
# expect(run.realtime=>{:valid=>nil, :estimatedminutes=>nil, :polltime=>nil, :lat=>nil, :trend=>nil, :vehicleid=>nil, :speed=>nil, :adherence=>nil, :long=>nil, :reliable=>nil, :estimatedtime=>"12:09 PM", :stopped=>nil}
|
102
|
+
expect(run[:exception]).to be_nil
|
103
|
+
expect(run[:tripid]).to eq "10709-11"
|
104
|
+
expect(run[:routetype]).to eq "B"
|
105
|
+
expect(run[:skedtripid]).to be_nil
|
106
|
+
expect(run[:stopid]).to eq "10050"
|
107
|
+
expect(run[:servicetype]).to eq "W"
|
108
|
+
expect(run[:adherence]).to be_nil
|
109
|
+
expect(run[:atisstopid]).to eq "3317"
|
110
|
+
# expect(run[:block]).to eq "5"
|
111
|
+
expect(run[:route]).to eq "ZERO"
|
112
|
+
expect(run[:estimatedtime]).to_not be_nil
|
113
|
+
expect(run[:estimatedtime]).to_not be_empty
|
114
|
+
expect(run[:direction]).to eq "N"
|
115
|
+
end
|
128
116
|
end
|
129
|
-
end
|
130
117
|
|
131
|
-
|
118
|
+
end
|
119
|
+
end
|
132
120
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
{ :time => next_bus_time_estimated, :adherence => '0', :route => '7', :sign => '7 7th Street to Union Hills Via Cent Station', :scheduled_time => next_bus_time_scheduled }
|
139
|
-
]
|
140
|
-
}
|
121
|
+
describe '#first_stop_description' do
|
122
|
+
it "should return the correct description" do
|
123
|
+
pending
|
124
|
+
end
|
125
|
+
end
|
141
126
|
|
142
|
-
|
143
|
-
|
127
|
+
describe '#to_hash' do
|
128
|
+
it "description" do
|
129
|
+
pending
|
144
130
|
end
|
145
131
|
end
|
146
132
|
|
133
|
+
describe '#to_hash_for_xml' do
|
134
|
+
it "description" do
|
135
|
+
pending
|
136
|
+
end
|
137
|
+
end
|
147
138
|
end
|
148
139
|
|
metadata
CHANGED