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 CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ratis (3.3.0)
4
+ ratis (3.3.2)
5
5
  savon (< 2.0)
6
6
 
7
7
  GEM
@@ -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
- NextBus.new stops, runs
52
+ NextBus2.new stops, runs
51
53
  end
52
54
 
53
55
  # Gets description of first stop
data/lib/ratis/version.rb CHANGED
@@ -5,7 +5,7 @@ module Ratis
5
5
  def version
6
6
  @version ||= begin
7
7
 
8
- string = '3.3.2'
8
+ string = '3.3.3'
9
9
 
10
10
  def string.parts
11
11
  split('.').map { |p| p.to_i }
@@ -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
- @today = Time.now.strftime("%m/%d/%Y")
21
- @conditions = {:stop_id => 10050,
19
+ @stop_id = 10050
20
+ @conditions = {:stop_id => @stop_id,
22
21
  :app_id => 'ratis-specs'}
23
22
  end
24
23
 
25
- it 'stops' do
26
- pending
27
- # raises exception when no runs available:
28
- # Ratis::Errors::SoapError:
29
- # SOAP - no runs available
30
- response = Ratis::NextBus2.where(@conditions.dup)
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
- let(:next_bus_time_scheduled) { 10.minutes.from_now.strftime '%H:%M %p' }
43
- let(:next_bus_time_estimated) { 12.minutes.from_now.strftime '%H:%M %p' }
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
- before do
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
- it 'only makes one request' do
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
- pending
105
- an_atis_request_for('Nextbus2', 'Stopid' => '10496', 'Appid' => 'web').should have_been_made
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 'returns a non nil NextBus' do
109
- pending
110
- @next_bus.should_not be_nil
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
- end
114
-
115
- describe '#to_hash' do
116
-
117
- it 'returns a subset of NextBus params' do
118
- pending
119
- hash = {
120
- :stopname => 'FILLMORE ST & CENTRAL AVE',
121
- :signs => ['7 7th Street to Union Hills Via Cent Station'],
122
- :runs => [
123
- { :time => next_bus_time_estimated, :adherence => '0', :route => '7', :sign => '7 7th Street to Union Hills Via Cent Station' }
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
- HashDiff.diff(@next_bus.to_hash, hash).should eql []
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
- describe '#to_hash_for_xml' do
118
+ end
119
+ end
132
120
 
133
- it 'returns a subset of NextBus params' do
134
- pending
135
- hash = {
136
- :stopname => 'FILLMORE ST & CENTRAL AVE',
137
- :runs => [
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
- HashDiff.diff(@next_bus.to_hash_for_xml, hash).should eql []
143
- end
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
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ratis
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 3
9
- - 2
10
- version: 3.3.2
9
+ - 3
10
+ version: 3.3.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Burst Software