ttc_feed 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/lib/ttc_feed/ttc_urls.rb +29 -0
- data/lib/ttc_feed/version.rb +3 -0
- data/lib/ttc_feed/zurl.rb +20 -0
- data/lib/ttc_feed.rb +17 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/url_spec.rb +7 -0
- data/spec/zurl_spec.rb +29 -0
- data/ttc_feed.gemspec +26 -0
- metadata +92 -0
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "ttc_feed/version"
|
2
|
+
require "ttc_feed/zurl"
|
3
|
+
|
4
|
+
module TtcUrls
|
5
|
+
def self.base
|
6
|
+
Zurl.new("http://webservices.nextbus.com/service/publicXMLFeed")
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.route_list
|
10
|
+
base.command("routeList").a("ttc").to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
# route_tag = "512"
|
14
|
+
def self.route_config(route_tag)
|
15
|
+
base.command("routeConfig").a(agency_tag).r(route_tag).to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
# stop_id = "14935"
|
19
|
+
# route_tag = "512"
|
20
|
+
def self.predictions(stop_id, route_tag)
|
21
|
+
base.stopId(stop_id).r(route_tag).a("ttc").to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
# route_tag = "512"
|
25
|
+
def self.vehicle_locations(route_tag)
|
26
|
+
base.command("vehicleLocations").a("ttc").r(route_tag).to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Zurl
|
2
|
+
def initialize(base_url)
|
3
|
+
@url_so_far = base_url
|
4
|
+
@first_param_already_used = false
|
5
|
+
end
|
6
|
+
|
7
|
+
def method_missing(meth, *args)
|
8
|
+
param_prefix = @first_param_already_used ? "&" : "?"
|
9
|
+
|
10
|
+
@url_so_far << param_prefix << meth.to_s
|
11
|
+
@url_so_far << "=" << args.first unless args.first.nil?
|
12
|
+
|
13
|
+
@first_param_already_used = true
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
@url_so_far
|
19
|
+
end
|
20
|
+
end
|
data/lib/ttc_feed.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'ttc_feed/ttc_urls'
|
2
|
+
require 'faraday'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
module TtcFeed
|
6
|
+
def self.streetcar_xml_data
|
7
|
+
[
|
8
|
+
["512", Faraday.get(TtcUrls.vehicle_locations("512")).body]
|
9
|
+
]
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.num_vehicles(route_id)
|
13
|
+
body = Faraday.get(TtcUrls.vehicle_locations(route_id)).body
|
14
|
+
doc = Nokogiri::XML(body)
|
15
|
+
doc.css("vehicle").length
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/url_spec.rb
ADDED
data/spec/zurl_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Zurl" do
|
4
|
+
it "builds a simple base url" do
|
5
|
+
url = Zurl.new("http://blah.com").to_s
|
6
|
+
url.should == "http://blah.com"
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "with a command parameter" do
|
10
|
+
it "will show the parameter in the url string" do
|
11
|
+
url = Zurl.new("http://blah.com").command("destroy").to_s
|
12
|
+
url.should == "http://blah.com?command=destroy"
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "and another parameter" do
|
16
|
+
it "will show both parameters" do
|
17
|
+
url = Zurl.new("http://blah.com").command("destroy").person("Santa_Claus").to_s
|
18
|
+
url.should == "http://blah.com?command=destroy&person=Santa_Claus"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "parameter with an empty value" do
|
24
|
+
it "will display the parameter but with no value (or equals sign)" do
|
25
|
+
url = Zurl.new("http://blah.com").my_param.to_s
|
26
|
+
url.should == "http://blah.com?my_param"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/ttc_feed.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ttc_feed/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "ttc_feed"
|
7
|
+
s.version = TtcFeed::VERSION
|
8
|
+
s.authors = ["David Wright"]
|
9
|
+
s.email = ["davidwright@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = "Simplified ruby interface for Open TTC Feed"
|
12
|
+
s.description = "Access some simple metrics provided by the TTC via their open data feed"
|
13
|
+
|
14
|
+
s.rubyforge_project = "ttc_feed"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency "rspec"
|
22
|
+
|
23
|
+
s.add_runtime_dependency "faraday"
|
24
|
+
s.add_runtime_dependency "nokogiri"
|
25
|
+
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ttc_feed
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- David Wright
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70286347930400 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70286347930400
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: faraday
|
27
|
+
requirement: &70286347929780 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70286347929780
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: nokogiri
|
38
|
+
requirement: &70286347929180 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70286347929180
|
47
|
+
description: Access some simple metrics provided by the TTC via their open data feed
|
48
|
+
email:
|
49
|
+
- davidwright@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- Rakefile
|
57
|
+
- lib/ttc_feed.rb
|
58
|
+
- lib/ttc_feed/ttc_urls.rb
|
59
|
+
- lib/ttc_feed/version.rb
|
60
|
+
- lib/ttc_feed/zurl.rb
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
- spec/url_spec.rb
|
63
|
+
- spec/zurl_spec.rb
|
64
|
+
- ttc_feed.gemspec
|
65
|
+
homepage: ''
|
66
|
+
licenses: []
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project: ttc_feed
|
85
|
+
rubygems_version: 1.8.10
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Simplified ruby interface for Open TTC Feed
|
89
|
+
test_files:
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
- spec/url_spec.rb
|
92
|
+
- spec/zurl_spec.rb
|