cumtd 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cumtd.rb +28 -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: b9b29b282253fd7d5f524f61e7e65092e0421018
|
4
|
+
data.tar.gz: c0b228e68084015682b7a547aabb5a4d8bafa92f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a6c9f5aebe2c84db2176df6641c377f6fe3736f46632c0266a240bf11c8679c7991e64c3b460cbffcc51bf905ae0d46507b98a373541d2d0bcbe5cc639babfa
|
7
|
+
data.tar.gz: 2ad657f57f944cdeb8e9705cf755250cc8d96b2841dada811b2765f465492a91602f918e2459c8266a26fd527962612462ddca0fa57e6d47cdecea48903705af
|
data/lib/cumtd.rb
CHANGED
@@ -10,8 +10,13 @@ class CUMTD
|
|
10
10
|
@api_key
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
|
13
|
+
def current_stops
|
14
|
+
@current_stops
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_stops(lat, lon, count=20)
|
18
|
+
response = self.class.get("/GetStopsByLatLon?key=#{api_key}&lat=#{lat}&lon=#{lon}&count=#{count}")
|
19
|
+
current_stops = response["stops"]
|
15
20
|
return stops = response["stops"]
|
16
21
|
end
|
17
22
|
|
@@ -28,6 +33,11 @@ class CUMTD
|
|
28
33
|
return response.parsed_response["routes"]
|
29
34
|
end
|
30
35
|
|
36
|
+
def get_stop_by_id(stop_id)
|
37
|
+
response = self.class.get("/GetStop?key=#{api_key}&stop_id=#{stop_id}")
|
38
|
+
return response.parsed_response["stops"].first["stop_name"]
|
39
|
+
end
|
40
|
+
|
31
41
|
def get_departures_by_stop(stop_id)
|
32
42
|
response = self.class.get("/GetDeparturesByStop?key=#{api_key}&stop_id=#{stop_id}")
|
33
43
|
return departures = response.parsed_response["departures"]
|
@@ -40,4 +50,20 @@ class CUMTD
|
|
40
50
|
end
|
41
51
|
end
|
42
52
|
|
53
|
+
# Returns an array of hashes. Each hash contains a "stop" key denoting the stop
|
54
|
+
# and the "departures" key contains one departure. These hashes are sorted
|
55
|
+
# based on length of time until they depart, given stops to get departures for.
|
56
|
+
|
57
|
+
def nearest_departures(stops)
|
58
|
+
master_deps = Array.new
|
59
|
+
stops.each do |stop|
|
60
|
+
# master_deps.concat(Hash["stop", stop, "departures", get_departures_by_stop(stop["stop_id"]))
|
61
|
+
stops_from_deps = get_departures_by_stop(stop["stop_id"])
|
62
|
+
stops_from_deps.each do |stop_dep|
|
63
|
+
master_deps << Hash["stop", stop, "departures", stop_dep]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
return master_deps.sort_by! { |stop| stop["departures"]["expected_mins"] }
|
67
|
+
end
|
68
|
+
|
43
69
|
end
|