next_muni 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ v0.1.1 Fixed gem for release
2
+
3
+ v0.1.0 get_stops and get_times implemented. Basic organization set up.
data/Manifest ADDED
@@ -0,0 +1,6 @@
1
+ CHANGELOG
2
+ README
3
+ Rakefile
4
+ lib/next_muni.rb
5
+ lib/next_muni/api.rb
6
+ Manifest
data/README ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('next_muni', '0.1.1') do |p|
6
+ p.description = "A gem to access San Francisco's Next Muni API easily"
7
+ p.url = "http://www.github.com/hjhart/next_muni_gem"
8
+ p.author = "James Hart"
9
+ p.email = "hjhart@gmail.com"
10
+ p.ignore_pattern = ["tmp/*", "scripts/*"]
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ def name
15
+ @name ||= Dir['*.gemspec'].first.split('.').first
16
+ end
17
+
18
+ task :default => [:test, :features]
19
+
20
+ desc "Open an irb session preloaded with this library"
21
+ task :console do
22
+ sh "irb -rubygems -r ./lib/#{name}.rb"
23
+ end
@@ -0,0 +1,20 @@
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
data/lib/next_muni.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+
3
+ require 'rexml/document'
4
+ require 'net/http'
5
+
6
+ require 'next_muni/api'
7
+
8
+ module NextMuni
9
+ def self.get_stops(route)
10
+ url = NextMuni::Api.build_url(route)
11
+ xml = Net::HTTP.get(URI.parse(url))
12
+ doc = REXML::Document.new(xml)
13
+ stops = {}
14
+ doc.elements.each('body/route/stop') do |ele|
15
+ stops[ele.attributes['tag']] = ele.attributes['title']
16
+ end
17
+ stops
18
+ end
19
+
20
+ def self.get_times(route_no, stop_no)
21
+ url = NextMuni::Api.build_url(route_no, stop_no)
22
+ xml = Net::HTTP.get(URI.parse(url))
23
+
24
+ doc = REXML::Document.new(xml)
25
+ times = []
26
+ doc.elements.each('body/predictions/direction/prediction') do |time|
27
+ times << time.attributes['minutes']
28
+ end
29
+ times
30
+ end
31
+ end
data/next_muni.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{next_muni}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["James Hart"]
9
+ s.date = %q{2011-03-14}
10
+ s.description = %q{A gem to access San Francisco's Next Muni API easily}
11
+ s.email = %q{hjhart@gmail.com}
12
+ s.extra_rdoc_files = ["CHANGELOG", "README", "lib/next_muni.rb", "lib/next_muni/api.rb"]
13
+ s.files = ["CHANGELOG", "README", "Rakefile", "lib/next_muni.rb", "lib/next_muni/api.rb", "Manifest", "next_muni.gemspec"]
14
+ s.homepage = %q{http://www.github.com/hjhart/next_muni_gem}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Next_muni", "--main", "README"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{next_muni}
18
+ s.rubygems_version = %q{1.5.3}
19
+ s.summary = %q{A gem to access San Francisco's Next Muni API easily}
20
+
21
+ if s.respond_to? :specification_version then
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ else
26
+ end
27
+ else
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: next_muni
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.1
6
+ platform: ruby
7
+ authors:
8
+ - James Hart
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-03-14 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: A gem to access San Francisco's Next Muni API easily
18
+ email: hjhart@gmail.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - CHANGELOG
25
+ - README
26
+ - lib/next_muni.rb
27
+ - lib/next_muni/api.rb
28
+ files:
29
+ - CHANGELOG
30
+ - README
31
+ - Rakefile
32
+ - lib/next_muni.rb
33
+ - lib/next_muni/api.rb
34
+ - Manifest
35
+ - next_muni.gemspec
36
+ has_rdoc: true
37
+ homepage: http://www.github.com/hjhart/next_muni_gem
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --line-numbers
43
+ - --inline-source
44
+ - --title
45
+ - Next_muni
46
+ - --main
47
+ - README
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "1.2"
62
+ requirements: []
63
+
64
+ rubyforge_project: next_muni
65
+ rubygems_version: 1.5.3
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: A gem to access San Francisco's Next Muni API easily
69
+ test_files: []
70
+