ratis 3.1.8 → 3.2.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/CHANGELOG CHANGED
@@ -25,4 +25,7 @@
25
25
  - Removed to_hash, instead use better named to_hash_for_xml for use with NextRide SMS service end-point
26
26
 
27
27
  3.1.8
28
- - Within to_hash_from_xml, pull route and sign attributes from the service instead of the realtime info (they always seem to be blank)
28
+ - Within to_hash_from_xml, pull route and sign attributes from the service instead of the realtime info (they always seem to be blank)
29
+
30
+ 3.2.0
31
+ - When querying Nextbus for a Light Rail stop, in most cases you will actually get back 2 stops for a single NextRide ID. One for each side of the stop platform. Made changes to handle this case. Both stops services are flattened into the #services attribute.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ratis (3.1.5.1)
4
+ ratis (3.1.8)
5
5
  savon (< 2.0)
6
6
 
7
7
  GEM
@@ -5,37 +5,47 @@ module Ratis
5
5
  attr_accessor :stop, :services, :success
6
6
 
7
7
  def initialize(response)
8
- @success = response.success?
8
+ @success = response.success?
9
+ @stop = []
10
+ @services = []
9
11
 
10
12
  if @success
11
- @stop = response.body[:nextbus_response][:atstop]
12
-
13
- _services = @stop.delete(:service)
14
-
15
- unless _services.is_a?(Array)
16
- _services = [_services]
17
- end
18
-
19
- @services = _services.map do |service|
20
- OpenStruct.new(:status => service[:status],
21
- :sign => service[:sign],
22
- :routetype => service[:routetype],
23
- :times => service[:times],
24
- :direction => service[:direction],
25
- :servicetype => service[:servicetype],
26
- :route => service[:route],
27
- :operator => service[:operator],
28
- :trips => parse_trip_info(service[:tripinfo])
29
- )
13
+ @stop = response.body[:nextbus_response][:atstop]
14
+
15
+ # Only Light Rail stops will return 2 stops from ATIS for a single NextRide id
16
+ if @stop.is_a?(Array)
17
+ @stop.each do |_stop|
18
+ parse_stop(_stop)
19
+ end
20
+ else
21
+ parse_stop(@stop)
30
22
  end
31
23
 
32
- else
33
- @stop = {}
34
- @services = []
35
24
  end
36
25
 
37
26
  end
38
27
 
28
+ def parse_stop(single_stop)
29
+ _services = single_stop.delete(:service)
30
+
31
+ _services = [_services] unless _services.is_a?(Array)
32
+
33
+ @services << _services.map do |service|
34
+ OpenStruct.new(:status => service[:status],
35
+ :sign => service[:sign],
36
+ :routetype => service[:routetype],
37
+ :times => service[:times],
38
+ :direction => service[:direction],
39
+ :servicetype => service[:servicetype],
40
+ :route => service[:route],
41
+ :operator => service[:operator],
42
+ :trips => parse_trip_info(service[:tripinfo])
43
+ )
44
+ end
45
+
46
+ @services.flatten!
47
+ end
48
+
39
49
  def parse_trip_info(trips)
40
50
  # can come back as an Array or single Hash...
41
51
  if trips.is_a?(Array)
@@ -95,11 +105,19 @@ module Ratis
95
105
  @success
96
106
  end
97
107
 
108
+ def stop_description
109
+ if @stop.is_a?(Array)
110
+ @stop.first[:description]
111
+ else
112
+ @stop[:description]
113
+ end
114
+ end
115
+
98
116
  # Used to create an XML response for the NextBus SMS services which hits
99
117
  # /nextride.xml?stop_id=<STOPID>
100
118
 
101
119
  def to_hash_for_xml
102
- { :stopname => @stop[:description],
120
+ { :stopname => stop_description,
103
121
  :runs => @services.map do |service|
104
122
  service.trips.map do |trip|
105
123
 
@@ -5,7 +5,7 @@ module Ratis
5
5
  def version
6
6
  @version ||= begin
7
7
 
8
- string = '3.1.8'
8
+ string = '3.2.0'
9
9
 
10
10
  def string.parts
11
11
  split('.').map { |p| p.to_i }
@@ -8,7 +8,7 @@ describe Ratis::NextBus do
8
8
  config.namespace = 'PX_WEB'
9
9
  end
10
10
 
11
- @time = Chronic.parse('tomorrow at 6am')
11
+ @time = Chronic.parse('next monday at 6am')
12
12
  end
13
13
 
14
14
  let(:empty_body){ {:nextbus_response => {:atstop => {:service => []}}} }
@@ -20,6 +20,13 @@ describe Ratis::NextBus do
20
20
  end
21
21
 
22
22
  describe '#where' do
23
+ # TODO: Light Rails Stops can return 2 Atstop tags... how do we best handle this case
24
+ describe 'Light Rails stops' do
25
+ it "description" do
26
+ pending
27
+ end
28
+ end
29
+
23
30
  describe 'time formatting' do
24
31
  it 'should make requests with 24 hour time format' do
25
32
  @stop_id = 10050
@@ -131,6 +138,7 @@ describe Ratis::NextBus do
131
138
  describe 'multiple services returned' do
132
139
  before do
133
140
  @stop_id = 15894
141
+ @time = Chronic.parse('next monday at 3pm')
134
142
  @conditions = {:stop_id => @stop_id,
135
143
  :app_id => 'ratis-specs', # a short string that can be used to separate requests from different applications or different modules with
136
144
  :type => 'N',
@@ -176,7 +184,7 @@ describe Ratis::NextBus do
176
184
  expect(service.status).to eq('N')
177
185
  expect(service.sign).to eq('108 Elliot West To Priest')
178
186
  expect(service.routetype).to eq('B')
179
- expect(service.times).to eq("06:46 AM, 07:46 AM, 08:46 AM, 09:46 AM")
187
+ expect(service.times).to eq("01:46 PM, 03:46 PM, 04:46 PM, 05:46 PM")
180
188
  expect(service.direction).to eq('W')
181
189
  expect(service.servicetype).to eq('W')
182
190
  expect(service.route).to eq('108')
@@ -188,7 +196,7 @@ describe Ratis::NextBus do
188
196
  expect(service.status).to eq('N')
189
197
  expect(service.sign).to eq('108 Elliot West To Priest Via Sosmn/Bsnln')
190
198
  expect(service.routetype).to eq('B')
191
- expect(service.times).to eq("10:46 AM, 02:46 PM, 06:46 PM")
199
+ expect(service.times).to eq("02:46 PM, 06:46 PM")
192
200
  expect(service.direction).to eq('W')
193
201
  expect(service.servicetype).to eq('W')
194
202
  expect(service.route).to eq('108')
@@ -13,7 +13,7 @@ describe Ratis::Point2Point do
13
13
  describe '#where' do
14
14
  describe 'services from origin to destination', {:vcr => {:cassette_name => "Point2Point"}} do
15
15
  before do
16
- @today = Time.now.strftime("%m/%d/%Y")
16
+ @today = Chronic.parse('next monday at 6am').strftime("%m/%d/%Y")
17
17
  @conditions = {:routes_only => true,
18
18
  :origin_lat => 33.446931,
19
19
  :origin_long => -112.097903,
@@ -126,7 +126,7 @@ describe Ratis::Point2Point do
126
126
 
127
127
  it 'gets the trips within each group' do
128
128
  schedule = Ratis::Point2Point.where(@conditions.dup)
129
- schedule.groups[0].should have(18).trips
129
+ schedule.groups[0].should have(15).trips
130
130
  schedule.groups[1].should have(16).trips
131
131
  schedule.groups[2].should have(4).trips
132
132
  end
@@ -20,27 +20,27 @@ http_interactions:
20
20
  aW50MnBvaW50PjwvZW52OkJvZHk+PC9lbnY6RW52ZWxvcGU+
21
21
 
22
22
  headers:
23
- Soapaction:
24
- - "\"PX_WEB#Point2point\""
25
23
  Content-Type:
26
24
  - text/xml;charset=UTF-8
27
- Accept:
28
- - "*/*"
29
25
  Content-Length:
30
26
  - "576"
27
+ Soapaction:
28
+ - "\"PX_WEB#Point2point\""
29
+ Accept:
30
+ - "*/*"
31
31
  response:
32
32
  status:
33
33
  code: 302
34
34
  message: Found
35
35
  headers:
36
+ Content-Length:
37
+ - "0"
38
+ Location:
39
+ - http://www.iana.org/domains/example/
36
40
  Connection:
37
41
  - Keep-Alive
38
42
  Server:
39
43
  - BigIP
40
- Location:
41
- - http://www.iana.org/domains/example/
42
- Content-Length:
43
- - "0"
44
44
  body:
45
45
  base64_string: ""
46
46
  http_version:
@@ -55,41 +55,41 @@ http_interactions:
55
55
  Y2hlbWEiIHhtbG5zOnhzaT0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxT
56
56
  Y2hlbWEtaW5zdGFuY2UiIHhtbG5zOndzZGw9IlBYX1dFQiIgeG1sbnM6ZW52
57
57
  PSJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy9zb2FwL2VudmVsb3BlLyI+
58
- PGVudjpCb2R5PjxQb2ludDJwb2ludCB4bWxucz0iUFhfV0VCIj48T3JpZ2lu
59
- bG9uZz4tMTEyLjA5NzkwMzwvT3JpZ2lubG9uZz48RGF0ZT4wNi8xMi8yMDEz
60
- PC9EYXRlPjxPcmlnaW5sYXQ+MzMuNDQ2OTMxPC9PcmlnaW5sYXQ+PERlc3Rp
61
- bmF0aW9ubGF0PjMzLjQ0NzA5ODwvRGVzdGluYXRpb25sYXQ+PFN0YXJ0dGlt
62
- ZT4xNzAwPC9TdGFydHRpbWU+PFJvdXRlcz4xPC9Sb3V0ZXM+PFJvdXRlc29u
63
- bHk+WTwvUm91dGVzb25seT48RGVzdGluYXRpb25sb25nPi0xMTIuMDc3MjEz
64
- PC9EZXN0aW5hdGlvbmxvbmc+PEVuZHRpbWU+MTgwMDwvRW5kdGltZT48L1Bv
58
+ PGVudjpCb2R5PjxQb2ludDJwb2ludCB4bWxucz0iUFhfV0VCIj48RW5kdGlt
59
+ ZT4xODAwPC9FbmR0aW1lPjxEYXRlPjA2LzE3LzIwMTM8L0RhdGU+PE9yaWdp
60
+ bmxhdD4zMy40NDY5MzE8L09yaWdpbmxhdD48T3JpZ2lubG9uZz4tMTEyLjA5
61
+ NzkwMzwvT3JpZ2lubG9uZz48U3RhcnR0aW1lPjE3MDA8L1N0YXJ0dGltZT48
62
+ RGVzdGluYXRpb25sYXQ+MzMuNDQ3MDk4PC9EZXN0aW5hdGlvbmxhdD48Um91
63
+ dGVzb25seT5ZPC9Sb3V0ZXNvbmx5PjxSb3V0ZXM+MTwvUm91dGVzPjxEZXN0
64
+ aW5hdGlvbmxvbmc+LTExMi4wNzcyMTM8L0Rlc3RpbmF0aW9ubG9uZz48L1Bv
65
65
  aW50MnBvaW50PjwvZW52OkJvZHk+PC9lbnY6RW52ZWxvcGU+
66
66
 
67
67
  headers:
68
- Soapaction:
69
- - "\"PX_WEB#Point2point\""
70
68
  Content-Type:
71
69
  - text/xml;charset=UTF-8
72
- Accept:
73
- - "*/*"
70
+ Soapaction:
71
+ - "\"PX_WEB#Point2point\""
74
72
  Content-Length:
75
73
  - "576"
74
+ Accept:
75
+ - "*/*"
76
76
  response:
77
77
  status:
78
78
  code: 200
79
79
  message: OK
80
80
  headers:
81
+ Content-Type:
82
+ - text/xml; charset=utf-8
81
83
  Date:
82
- - Wed, 12 Jun 2013 22:24:11 GMT
84
+ - Fri, 14 Jun 2013 17:03:34 GMT
85
+ Content-Length:
86
+ - "4558"
83
87
  Connection:
84
88
  - close
85
- Soapserver:
86
- - SOAP::Lite/Perl/0.55
87
89
  Server:
88
90
  - Apache/2.2.3 (CentOS)
89
- Content-Type:
90
- - text/xml; charset=utf-8
91
- Content-Length:
92
- - "4558"
91
+ Soapserver:
92
+ - SOAP::Lite/Perl/0.55
93
93
  body:
94
94
  base64_string: |
95
95
  PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48U09BUC1F
@@ -196,5 +196,5 @@ http_interactions:
196
196
  RU5WOkVudmVsb3BlPg==
197
197
 
198
198
  http_version:
199
- recorded_at: Wed, 12 Jun 2013 22:24:12 GMT
199
+ recorded_at: Fri, 14 Jun 2013 17:03:34 GMT
200
200
  recorded_with: VCR 2.4.0
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: 19
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
- - 1
9
- - 8
10
- version: 3.1.8
8
+ - 2
9
+ - 0
10
+ version: 3.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Burst Software
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-06-13 00:00:00 Z
18
+ date: 2013-06-14 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: savon