onebusaway_updated 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.1"
12
+ gem "rcov", ">= 0"
13
+ end
@@ -0,0 +1,23 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.1)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.8.7)
10
+ rcov (0.9.9)
11
+ shoulda (2.11.3)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.0.0)
18
+ jeweler (~> 1.5.1)
19
+ rcov
20
+ shoulda
21
+
22
+ METADATA
23
+ version: 1.0.6
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Jeff Ching
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ OneBusAway API
2
+ --------------
3
+
4
+ Unofficial Ruby library for interacting with the [OneBusAway API](http://code.google.com/p/onebusaway/wiki/OneBusAwayApiReference)
5
+
6
+ ### Documentation & Requirements
7
+ * REXML
8
+
9
+ ### Examples
10
+
11
+ Basic usage:
12
+
13
+ require 'rubygems'
14
+ require 'onebusaway'
15
+
16
+ Onebusaway.api_key = 'YOUR_API_KEY'
17
+
18
+ # find a stop by id - returns a Onebusaway::Stop instance
19
+ stop = Onebusaway.stop_by_id(:id => "1_10020")
20
+
21
+ # find a route by id - returns a Onebusaway::Route instance
22
+ route = Onebusaway.route_by_id(:id => "1_30")
23
+
24
+ # find stops nearby a given latitude and longitude
25
+ # - returns an array of Onebusaway::Stop instances
26
+ stops = Onebusaway.stops_for_location(:lat => "47.66", :lon => "-122.29")
27
+
28
+ # find routes nearby a given latitude and longitude
29
+ # - returns an array of Onebusaway::Route instances
30
+ routes = Onebusaway.routes_for_location(:lat => "47.66", :lon => "-122.29")
31
+
32
+ # find stops for a route - returns an array of Onebusaway::Stop instances
33
+ stops = Onebusaway.stops_for_route(:id => "1_30")
34
+
35
+ # find arrivals/departures for a given stop
36
+ # - returns an array of Onebusaway::ArrivalAndDeparture instances
37
+ arrivals = Onebusaway.arrivals_and_departures_for_stop(:id => "1_570")
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "onebusaway"
16
+ gem.homepage = "http://github.com/chingor13/onebusaway"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Unofficial Ruby library for interacting with the OneBusAway API}
19
+ gem.description = %Q{Unofficial Ruby library for interacting with the OneBusAway API. See http://code.google.com/p/onebusaway/wiki/OneBusAwayRestApi}
20
+ gem.email = "ching.jeff@gmail.com"
21
+ gem.authors = ["Jeff Ching"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "onebusaway #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,104 @@
1
+ require 'open-uri'
2
+ require 'json'
3
+
4
+ class Onebusaway
5
+
6
+ attr_reader :api_base
7
+
8
+ def initialize api_key
9
+ @api_key = api_key
10
+ @api_base = URI 'http://api.onebusaway.org/api/where/'
11
+ end
12
+
13
+ def make_id agency_id, sub_id
14
+ "#{agency_id}_#{sub_id}"
15
+ end
16
+
17
+ def api_base= url
18
+ @api_base = URI url
19
+ end
20
+
21
+ def stop_by_id agency_id, stop_id
22
+ result = request 'stop', id: make_id(agency_id, stop_id)
23
+
24
+ Stop.new result
25
+ end
26
+
27
+ def route_by_id agency_id, route_id
28
+ result = request 'route', id: make_id(agency_id, route_id)
29
+
30
+ Route.new result
31
+ end
32
+
33
+ def stops_for_location lat, lon
34
+ result = request 'stops-for-location', lat: lat, lon: lon
35
+
36
+ result['stops'].map do |stop|
37
+ Stop.new stop
38
+ end
39
+ end
40
+
41
+ def routes_for_location lat, lon
42
+ result = request 'routes-for-location', lat: lat, lon: lon
43
+
44
+ result['routes'].map do |route|
45
+ Route.new route
46
+ end
47
+ end
48
+
49
+ def stops_for_route agency_id, route_id
50
+ result = request 'stops-for-route', id: make_id(agency_id, route_id)
51
+
52
+ result['stops'].map do |stop|
53
+ Stop.new stop
54
+ end
55
+ end
56
+
57
+ def arrivals_and_departures_for_stop agency_id, stop_id
58
+ result = request 'arrivals-and-departures-for-stop',
59
+ id: make_id(agency_id, stop_id)
60
+
61
+ result['arrivalsAndDepartures'].map do |arr_dep|
62
+ ArrivalAndDeparture.new arr_dep
63
+ end
64
+ end
65
+
66
+ private
67
+
68
+ def api_url method, options = {}
69
+ options[:key] = @api_key
70
+
71
+ id = options.delete :id
72
+
73
+ method = [method, id].compact.join '/'
74
+ method << '.json'
75
+
76
+ url = @api_base + method
77
+
78
+ url.query = options.to_a.map{|pair| "#{pair[0]}=#{pair[1]}"}.join("&")
79
+ url
80
+ end
81
+
82
+ def request call, url_options
83
+ url = api_url call, url_options
84
+
85
+ json = open(url).read
86
+
87
+ result = JSON.parse json
88
+ code = result['code'].to_s
89
+ text = result['text']
90
+
91
+ raise "Request failed (#{code}): #{text}" unless code.start_with? '2'
92
+
93
+ result['data']
94
+ end
95
+
96
+ autoload :Agency, 'onebusaway/agency'
97
+ autoload :ArrivalAndDeparture, 'onebusaway/arrival_and_departure'
98
+ autoload :EncodedPolyline, 'onebusaway/encoded_polyline'
99
+ autoload :Object, 'onebusaway/object'
100
+ autoload :Route, 'onebusaway/route'
101
+ autoload :Stop, 'onebusaway/stop'
102
+
103
+ end
104
+
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'onebusaway'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,76 @@
1
+ module Onebusaway
2
+ module SampleData
3
+ STOP_DATA = <<EOS
4
+ <response>
5
+ <version>1.0</version>
6
+ <code>200</code>
7
+ <text>OK</text>
8
+ <data class="stop">
9
+ <id>1_10020</id>
10
+ <lat>47.6685829</lat>
11
+ <lon>-122.2883</lon>
12
+ <direction>W</direction>
13
+ <name>NE 55th St &amp; 37th Ave NE</name>
14
+ <code>10020</code>
15
+ <locationType>0</locationType>
16
+ <routes>
17
+ <route>
18
+ <id>1_30</id>
19
+ <shortName>30</shortName>
20
+ <description>Sandpoint/U-Dist/Seattle Center</description>
21
+ <type>3</type>
22
+ <url>http://metro.kingcounty.gov/tops/bus/schedules/s030_0_.html</url>
23
+ <agency>
24
+ <id>1</id>
25
+ <name>Metro Transit</name>
26
+ <url>http://metro.kingcounty.gov</url>
27
+ <timezone>America/Los_Angeles</timezone>
28
+ <lang>en</lang>
29
+ <phone>206-553-3000</phone>
30
+ </agency>
31
+ </route>
32
+ <route>
33
+ <id>1_74</id>
34
+ <shortName>74</shortName>
35
+ <description>Sandpoint/U-Dist/CPS</description>
36
+ <type>3</type>
37
+ <url>http://metro.kingcounty.gov/tops/bus/schedules/s074_0_.html</url>
38
+ <agency>
39
+ <id>1</id>
40
+ <name>Metro Transit</name>
41
+ <url>http://metro.kingcounty.gov</url>
42
+ <timezone>America/Los_Angeles</timezone>
43
+ <lang>en</lang>
44
+ <phone>206-553-3000</phone>
45
+ </agency>
46
+ </route>
47
+ </routes>
48
+ </data>
49
+ </response>
50
+ EOS
51
+ ROUTE_DATA = <<EOS
52
+ <response>
53
+ <version>1.0</version>
54
+ <code>200</code>
55
+ <text>OK</text>
56
+ <data class="route">
57
+ <id>1_30</id>
58
+ <shortName>30</shortName>
59
+
60
+ <description>Sandpoint/U-Dist/Seattle Center</description>
61
+ <type>3</type>
62
+ <url>http://metro.kingcounty.gov/tops/bus/schedules/s030_0_.html</url>
63
+ <agency>
64
+ <id>1</id>
65
+ <name>Metro Transit</name>
66
+
67
+ <url>http://metro.kingcounty.gov</url>
68
+ <timezone>America/Los_Angeles</timezone>
69
+ <lang>en</lang>
70
+ <phone>206-553-3000</phone>
71
+ </agency>
72
+ </data>
73
+ </response>
74
+ EOS
75
+ end
76
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestOnebusaway < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ #flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: onebusaway_updated
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeff Ching
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: shoulda
16
+ requirement: !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: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.0.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: jeweler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.5.1
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.5.1
62
+ - !ruby/object:Gem::Dependency
63
+ name: rcov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Unofficial Ruby library for interacting with the OneBusAway API. See
79
+ http://code.google.com/p/onebusaway/wiki/OneBusAwayRestApi
80
+ email: ching.jeff@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files:
84
+ - LICENSE.txt
85
+ - README.markdown
86
+ files:
87
+ - Gemfile
88
+ - Gemfile.lock
89
+ - LICENSE.txt
90
+ - README.markdown
91
+ - Rakefile
92
+ - VERSION
93
+ - lib/onebusaway.rb
94
+ - test/helper.rb
95
+ - test/sample_data.rb
96
+ - test/unit/test_onebusaway.rb
97
+ homepage: http://github.com/Ponyboy47/onebusaway
98
+ licenses:
99
+ - MIT
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 1.8.21
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Unofficial Ruby library for interacting with the OneBusAway API
122
+ test_files:
123
+ - test/helper.rb
124
+ - test/sample_data.rb
125
+ - test/unit/test_onebusaway.rb