next_muni 0.1.3 → 0.1.5
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 +2 -0
- data/Manifest +0 -1
- data/README.rdoc +6 -0
- data/Rakefile +1 -1
- data/lib/next_muni.rb +38 -5
- data/next_muni.gemspec +8 -8
- metadata +3 -7
- data/lib/next_muni/api.rb +0 -20
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
data/README.rdoc
CHANGED
@@ -9,6 +9,12 @@ Questions are welcome on the github wiki for now – https://github.com/hjhart/
|
|
9
9
|
|
10
10
|
== Usage
|
11
11
|
|
12
|
+
# get_routes(agency)
|
13
|
+
|
14
|
+
Gets a list of all routes (use the ID provided for querying get_stops)
|
15
|
+
|
16
|
+
# try NextMuni.get_routes('sf-muni') or NextMuni.get_routes('actransit')
|
17
|
+
|
12
18
|
# get_stops(route_no)
|
13
19
|
NextMuni.get_stops(45)
|
14
20
|
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('next_muni', '0.1.
|
5
|
+
Echoe.new('next_muni', '0.1.5') do |p|
|
6
6
|
p.description = "A gem to access San Francisco's Next Muni API easily"
|
7
7
|
p.url = "http://www.github.com/hjhart/next_muni_gem"
|
8
8
|
p.author = "James Hart"
|
data/lib/next_muni.rb
CHANGED
@@ -3,11 +3,10 @@ require 'rubygems'
|
|
3
3
|
require 'rexml/document'
|
4
4
|
require 'net/http'
|
5
5
|
|
6
|
-
require 'next_muni/api'
|
7
6
|
|
8
7
|
module NextMuni
|
9
|
-
def self.get_stops(route)
|
10
|
-
url = NextMuni
|
8
|
+
def self.get_stops(route, stop_no=nil, agency='sf-muni', direction_id=nil)
|
9
|
+
url = NextMuni.build_url(route.upcase, stop_no, agency, direction_id)
|
11
10
|
xml = Net::HTTP.get(URI.parse(url))
|
12
11
|
doc = REXML::Document.new(xml)
|
13
12
|
directions = []
|
@@ -32,8 +31,8 @@ module NextMuni
|
|
32
31
|
directions
|
33
32
|
end
|
34
33
|
|
35
|
-
def self.get_times(route_no, stop_no, direction_id=nil)
|
36
|
-
url = NextMuni
|
34
|
+
def self.get_times(route_no, stop_no, agency='sf-muni', direction_id=nil)
|
35
|
+
url = NextMuni.build_url(route_no.upcase, stop_no, agency, direction_id)
|
37
36
|
xml = Net::HTTP.get(URI.parse(url))
|
38
37
|
|
39
38
|
doc = REXML::Document.new(xml)
|
@@ -43,4 +42,38 @@ module NextMuni
|
|
43
42
|
end
|
44
43
|
times
|
45
44
|
end
|
45
|
+
|
46
|
+
# Some agencies: sf-muni, actransit
|
47
|
+
def self.get_routes(agency)
|
48
|
+
url = "http://webservices.nextbus.com/service/publicXMLFeed?command=routeList&a=#{agency}"
|
49
|
+
xml = Net::HTTP.get(URI.parse(url))
|
50
|
+
|
51
|
+
doc = REXML::Document.new(xml)
|
52
|
+
routes = []
|
53
|
+
|
54
|
+
doc.elements.each('body/route') do |route|
|
55
|
+
routes << {
|
56
|
+
:id => route.attributes['tag'],
|
57
|
+
:title => route.attributes['title']
|
58
|
+
}
|
59
|
+
end
|
60
|
+
routes
|
61
|
+
end
|
62
|
+
|
63
|
+
# get stops
|
64
|
+
# http://webservices.nextbus.com/service/publicXMLFeed?command=routeConfig&a=sf-muni&r=45
|
65
|
+
# get times
|
66
|
+
# http://webservices.nextbus.com/service/publicXMLFeed?command=predictions&a=sf-muni&r=<route tag>&d=<direction tag>&s=<stop tag>
|
67
|
+
# multiples
|
68
|
+
# http://webservices.nextbus.com/service/publicXMLFeed?command=predictionsForMultiStops&a=sf-muni&stops=45|45_IB2|6787&stops=45|45_IB2|6771
|
69
|
+
def self.build_url(route_number, stop_id = nil, agency='sf-muni', dir_id = nil)
|
70
|
+
if stop_id.nil?
|
71
|
+
url = "http://webservices.nextbus.com/service/publicXMLFeed?command=routeConfig&a=#{agency}&r=#{route_number}"
|
72
|
+
else
|
73
|
+
url = "http://webservices.nextbus.com/service/publicXMLFeed?command=predictions&a=#{agency}&r=#{route_number}&s=#{stop_id}"
|
74
|
+
url += "&d=#{dir_id}" unless dir_id.nil?
|
75
|
+
end
|
76
|
+
url
|
77
|
+
end
|
78
|
+
|
46
79
|
end
|
data/next_muni.gemspec
CHANGED
@@ -2,20 +2,20 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{next_muni}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.5"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = [
|
9
|
-
s.date = %q{2011-
|
8
|
+
s.authors = [%q{James Hart}]
|
9
|
+
s.date = %q{2011-09-16}
|
10
10
|
s.description = %q{A gem to access San Francisco's Next Muni API easily}
|
11
11
|
s.email = %q{hjhart@gmail.com}
|
12
|
-
s.extra_rdoc_files = [
|
13
|
-
s.files = [
|
12
|
+
s.extra_rdoc_files = [%q{CHANGELOG}, %q{README.rdoc}, %q{lib/next_muni.rb}]
|
13
|
+
s.files = [%q{CHANGELOG}, %q{README.rdoc}, %q{Rakefile}, %q{lib/next_muni.rb}, %q{next_muni.gemspec}, %q{Manifest}]
|
14
14
|
s.homepage = %q{http://www.github.com/hjhart/next_muni_gem}
|
15
|
-
s.rdoc_options = [
|
16
|
-
s.require_paths = [
|
15
|
+
s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Next_muni}, %q{--main}, %q{README.rdoc}]
|
16
|
+
s.require_paths = [%q{lib}]
|
17
17
|
s.rubyforge_project = %q{next_muni}
|
18
|
-
s.rubygems_version = %q{1.
|
18
|
+
s.rubygems_version = %q{1.8.9}
|
19
19
|
s.summary = %q{A gem to access San Francisco's Next Muni API easily}
|
20
20
|
|
21
21
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: next_muni
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Hart
|
@@ -10,8 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
14
|
-
default_executable:
|
13
|
+
date: 2011-09-16 00:00:00 Z
|
15
14
|
dependencies: []
|
16
15
|
|
17
16
|
description: A gem to access San Francisco's Next Muni API easily
|
@@ -24,16 +23,13 @@ extra_rdoc_files:
|
|
24
23
|
- CHANGELOG
|
25
24
|
- README.rdoc
|
26
25
|
- lib/next_muni.rb
|
27
|
-
- lib/next_muni/api.rb
|
28
26
|
files:
|
29
27
|
- CHANGELOG
|
30
28
|
- README.rdoc
|
31
29
|
- Rakefile
|
32
30
|
- lib/next_muni.rb
|
33
|
-
- lib/next_muni/api.rb
|
34
31
|
- next_muni.gemspec
|
35
32
|
- Manifest
|
36
|
-
has_rdoc: true
|
37
33
|
homepage: http://www.github.com/hjhart/next_muni_gem
|
38
34
|
licenses: []
|
39
35
|
|
@@ -62,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
58
|
requirements: []
|
63
59
|
|
64
60
|
rubyforge_project: next_muni
|
65
|
-
rubygems_version: 1.
|
61
|
+
rubygems_version: 1.8.9
|
66
62
|
signing_key:
|
67
63
|
specification_version: 3
|
68
64
|
summary: A gem to access San Francisco's Next Muni API easily
|
data/lib/next_muni/api.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module NextMuni
|
2
|
-
|
3
|
-
class Api
|
4
|
-
# get stops
|
5
|
-
# http://webservices.nextbus.com/service/publicXMLFeed?command=routeConfig&a=sf-muni&r=45
|
6
|
-
# get times
|
7
|
-
# http://webservices.nextbus.com/service/publicXMLFeed?command=predictions&a=sf-muni&r=<route tag>&d=<direction tag>&s=<stop tag>
|
8
|
-
# multiples
|
9
|
-
# http://webservices.nextbus.com/service/publicXMLFeed?command=predictionsForMultiStops&a=sf-muni&stops=45|45_IB2|6787&stops=45|45_IB2|6771
|
10
|
-
def self.build_url(route_number, stop_id = nil, dir_id = nil)
|
11
|
-
if stop_id.nil?
|
12
|
-
url = "http://webservices.nextbus.com/service/publicXMLFeed?command=routeConfig&a=sf-muni&r=#{route_number}"
|
13
|
-
else
|
14
|
-
url = "http://webservices.nextbus.com/service/publicXMLFeed?command=predictions&a=sf-muni&r=#{route_number}&s=#{stop_id}"
|
15
|
-
url += "&d=#{dir_id}" unless dir_id.nil?
|
16
|
-
end
|
17
|
-
url
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|