mbta-realtime 0.1.2 → 0.1.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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/mbta-realtime/client.rb +29 -9
- data/lib/mbta-realtime/version.rb +1 -1
- data/mbta-realtime.gemspec +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7502a15244bd9b2909ffaa3ffdedc7863cf5fa87
|
4
|
+
data.tar.gz: 7a218c049d825a54f47eddee4c24fcf9ade2f9a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66b1f0107cb808defb87069af8b73daa75ee99e534bdcebbf8d41709646ae292f3d5c7bfd53c5ac31302a9257dce722432e70fa574acb1bde73ce6c1c3424799
|
7
|
+
data.tar.gz: 5d9601b982ac5ca874db3a8b9cf6fd036cc22c852434a9fb4726598874ef139b339fa64216470f7a50b9b1e20ab0a33c08ec0e06bcf224f95a20cf289c50c348
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/mbta-realtime/client.rb
CHANGED
@@ -75,8 +75,9 @@ module MBTARealtime
|
|
75
75
|
end
|
76
76
|
|
77
77
|
|
78
|
-
def predictions_by_stop(stop_id)
|
79
|
-
|
78
|
+
def predictions_by_stop(stop_id, flatten=false)
|
79
|
+
ps = self.class.get("/predictionsbystop", url_opts({stop: stop_id})).to_h
|
80
|
+
flatten ? flatten_predictions(ps) : ps
|
80
81
|
end
|
81
82
|
|
82
83
|
|
@@ -85,13 +86,9 @@ module MBTARealtime
|
|
85
86
|
end
|
86
87
|
|
87
88
|
|
88
|
-
def
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
def predictions_by_location_name(intersection)
|
94
|
-
raise NotImplementedError
|
89
|
+
def predictions_by_location_name(intersection, flatten=false)
|
90
|
+
ps = predictions_by_stop( nearest_stop_id_by_location_name(intersection) )
|
91
|
+
flatten ? flatten_predictions( ps ) : ps
|
95
92
|
end
|
96
93
|
|
97
94
|
|
@@ -102,6 +99,29 @@ module MBTARealtime
|
|
102
99
|
{ query: @options[:query].merge( args ) }
|
103
100
|
end
|
104
101
|
|
102
|
+
def flatten_predictions(predictions_response)
|
103
|
+
@predictions = []
|
104
|
+
|
105
|
+
travel_modes = predictions_response['mode']
|
106
|
+
travel_modes.each do |mode|
|
107
|
+
routes = mode['route']
|
108
|
+
routes.each do |route|
|
109
|
+
route_obj = OpenStruct.new(id: route['route_id'], name: route['route_name'], trips: [])
|
110
|
+
directions = route['direction']
|
111
|
+
directions.each do |dir|
|
112
|
+
trips = dir['trip']
|
113
|
+
trips.each do |trip|
|
114
|
+
route_obj.trips << OpenStruct.new(id: trip['trip_id'],
|
115
|
+
time: trip['pre_away'])
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
@predictions << route_obj
|
120
|
+
end
|
121
|
+
end
|
122
|
+
@predictions
|
123
|
+
end
|
124
|
+
|
105
125
|
end
|
106
126
|
end
|
107
127
|
|
data/mbta-realtime.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: mbta-realtime 0.1.
|
5
|
+
# stub: mbta-realtime 0.1.3 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "mbta-realtime"
|
9
|
-
s.version = "0.1.
|
9
|
+
s.version = "0.1.3"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|