nextbus 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.gitignore +22 -0
  2. data/Gemfile +6 -0
  3. data/Gemfile.lock +29 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +17 -0
  6. data/Rakefile +27 -0
  7. data/VERSION +1 -0
  8. data/doc/ERM.graffle +1318 -0
  9. data/doc/MBTA_XML_Feed_Trial_Docs_13Nov09-1.pdf +0 -0
  10. data/lib/attr_with_default.rb +51 -0
  11. data/lib/instantiate_with_attrs.rb +12 -0
  12. data/lib/nextbus.rb +10 -0
  13. data/lib/nextbus/agency.rb +18 -0
  14. data/lib/nextbus/client.rb +70 -0
  15. data/lib/nextbus/direction.rb +18 -0
  16. data/lib/nextbus/mash_extensions.rb +12 -0
  17. data/lib/nextbus/prediction.rb +18 -0
  18. data/lib/nextbus/report.rb +10 -0
  19. data/lib/nextbus/route.rb +18 -0
  20. data/lib/nextbus/stop.rb +18 -0
  21. data/lib/nextbus/string_extensions.rb +16 -0
  22. data/lib/nextbus/vehicle.rb +18 -0
  23. data/nextbus.gemspec +106 -0
  24. data/test/fixtures/agency_list.xml +5 -0
  25. data/test/fixtures/error.xml +6 -0
  26. data/test/fixtures/predictions.xml +12 -0
  27. data/test/fixtures/predictions_for_multi_stops.xml +21 -0
  28. data/test/fixtures/route_config.xml +755 -0
  29. data/test/fixtures/route_list.xml +5 -0
  30. data/test/fixtures/vehicle_locations.xml +11 -0
  31. data/test/helper.rb +78 -0
  32. data/test/unit/test_agency.rb +56 -0
  33. data/test/unit/test_attr_with_default.rb +158 -0
  34. data/test/unit/test_client.rb +107 -0
  35. data/test/unit/test_direction.rb +59 -0
  36. data/test/unit/test_instantiate_with_attrs.rb +31 -0
  37. data/test/unit/test_mash_extensions.rb +45 -0
  38. data/test/unit/test_nextbus.rb +9 -0
  39. data/test/unit/test_prediction.rb +47 -0
  40. data/test/unit/test_report.rb +34 -0
  41. data/test/unit/test_route.rb +51 -0
  42. data/test/unit/test_stop.rb +64 -0
  43. data/test/unit/test_string_extensions.rb +33 -0
  44. data/test/unit/test_vehicle.rb +52 -0
  45. data/vendor/cache/columnize-0.3.1.gem +0 -0
  46. data/vendor/cache/crack-0.1.6.gem +0 -0
  47. data/vendor/cache/hashie-0.1.8.gem +0 -0
  48. data/vendor/cache/httparty-0.5.2.gem +0 -0
  49. data/vendor/cache/linecache-0.43.gem +0 -0
  50. data/vendor/cache/mocha-0.9.8.gem +0 -0
  51. data/vendor/cache/rake-0.8.7.gem +0 -0
  52. data/vendor/cache/ruby-debug-0.10.3.gem +0 -0
  53. data/vendor/cache/ruby-debug-base-0.10.3.gem +0 -0
  54. metadata +121 -0
@@ -0,0 +1,31 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'helper')
2
+
3
+ module Testing__
4
+ class Foo
5
+ attr_accessor :name
6
+ include InstantiateWithAttrs
7
+ end
8
+ end
9
+
10
+ class TestInstantiateWithAttrs < Test::Unit::TestCase
11
+
12
+ def test_instantiated_without_any_attrs
13
+ object = Testing__::Foo.new
14
+ assert_nil object.name
15
+ end
16
+
17
+ def test_instantiated_with_attrs
18
+ name = 'my name'
19
+ attrs = {:name => name}
20
+ object = Testing__::Foo.new attrs
21
+ assert_equal name, object.name
22
+ end
23
+
24
+ def test_instantiated_with_invalid_attr
25
+ attrs = {:wrong => 'boom'}
26
+ assert_nothing_raised do
27
+ Testing__::Foo.new attrs
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,45 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'helper')
2
+
3
+ class TestMashExtensions < Test::Unit::TestCase
4
+
5
+ def setup
6
+ super
7
+ @value = 'my value'
8
+ end
9
+
10
+ def test_convert_hash_with_camel_case_key
11
+ hash = { 'CamelCaseKey' => @value }
12
+ mash = Hashie::Mash.new(hash)
13
+ assert_equal @value, mash['camel_case_key']
14
+ assert_equal @value, mash.camel_case_key
15
+ end
16
+
17
+ def test_convert_hash_with_uppercase_key
18
+ hash = { 'UPPERCASEKEY' => @value }
19
+ mash = Hashie::Mash.new(hash)
20
+ assert_equal @value, mash['uppercasekey']
21
+ assert_equal @value, mash.uppercasekey
22
+ end
23
+
24
+ def test_convert_hash_with_camel_case_with_space_in_key
25
+ hash = { 'CamelCase Key' => @value }
26
+ mash = Hashie::Mash.new(hash)
27
+ assert_equal @value, mash['camel_case_key']
28
+ assert_equal @value, mash.camel_case_key
29
+ end
30
+
31
+ def test_convert_hash_with_underscored_key
32
+ hash = { 'already_underscored_key' => @value }
33
+ mash = Hashie::Mash.new(hash)
34
+ assert_equal @value, mash['already_underscored_key']
35
+ assert_equal @value, mash.already_underscored_key
36
+ end
37
+
38
+ def test_convert_nested_hash_with_camel_case_key
39
+ hash = { 'CamelCaseKey1' => { 'CamelCaseKey2' => @value } }
40
+ mash = Hashie::Mash.new(hash)
41
+ assert_equal @value, mash['camel_case_key1']['camel_case_key2']
42
+ assert_equal @value, mash.camel_case_key1.camel_case_key2
43
+ end
44
+
45
+ end
@@ -0,0 +1,9 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'helper')
2
+
3
+ class TestNextbus < Test::Unit::TestCase
4
+
5
+ def test_nextbus_module
6
+ assert Nextbus.is_a?(Module)
7
+ end
8
+
9
+ end
@@ -0,0 +1,47 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'helper')
2
+
3
+ class TestPrediction < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @prediction1 = Nextbus::Prediction.new
7
+ end
8
+
9
+ def test_time_attr
10
+ assert_attr_accessor @prediction1, :time
11
+ end
12
+ def test_departure_attr
13
+ assert_attr_accessor @prediction1, :departure
14
+ end
15
+
16
+ def test_stop_attr
17
+ assert_attr_accessor @prediction1, :stop
18
+ end
19
+
20
+ def test_instantiated_with_attrs
21
+ attrs = {:time => Time.now, :departure => false}
22
+ assert_instantiated_with_attrs Nextbus::Prediction, attrs
23
+ end
24
+
25
+ def test_epoch_time_setter
26
+ nanosecs = 1266681828070
27
+ time = Time.at(nanosecs/1000)
28
+ @prediction1.epoch_time = nanosecs
29
+ assert_equal time.to_i, @prediction1.time.to_i
30
+ end
31
+
32
+ def test_all
33
+ prediction_time1 = Time.at(1266681828.070)
34
+ prediction_time2 = Time.at(1266681828.075)
35
+ agency_id = 'abc'
36
+ route_id = '321'
37
+ stop_id = '22365'
38
+ expect_response('predictions.xml', /#{agency_id}.+#{route_id}.+#{stop_id}/, Net::HTTP::Get)
39
+ all = Nextbus::Prediction.all(agency_id, route_id, stop_id)
40
+ assert all.is_a?(Array)
41
+ assert_equal 5, all.length
42
+ assert all[0].is_a?(Nextbus::Prediction)
43
+ assert_equal prediction_time1.to_i, all[0].time.to_i
44
+ assert_equal prediction_time2.to_i, all[1].time.to_i
45
+ end
46
+
47
+ end
@@ -0,0 +1,34 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'helper')
2
+
3
+ class TestReport < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @report1 = Nextbus::Report.new
7
+ end
8
+
9
+ def test_lat_attr
10
+ assert_attr_accessor @report1, :lat
11
+ end
12
+ def test_lon_attr
13
+ assert_attr_accessor @report1, :lon
14
+ end
15
+ def test_heading_attr
16
+ assert_attr_accessor @report1, :heading
17
+ end
18
+ def test_time_attr
19
+ assert_attr_accessor @report1, :time
20
+ end
21
+
22
+ def test_vehicle_attr
23
+ assert_attr_accessor @report1, :vehicle
24
+ end
25
+ def test_direction_attr
26
+ assert_attr_accessor @report1, :direction
27
+ end
28
+
29
+ def test_instantiated_with_attrs
30
+ attrs = {:lat => 'my lat', :lon => 'my lon', :heading => 'my heading', :time => Time.now}
31
+ assert_instantiated_with_attrs Nextbus::Report, attrs
32
+ end
33
+
34
+ end
@@ -0,0 +1,51 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'helper')
2
+
3
+ class TestRoute < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @route1 = Nextbus::Route.new
7
+ end
8
+
9
+ def test_tag_attr
10
+ assert_attr_accessor @route1, :tag
11
+ end
12
+ def test_title_attr
13
+ assert_attr_accessor @route1, :title
14
+ end
15
+
16
+ def test_agency_attr
17
+ assert_attr_accessor @route1, :agency
18
+ end
19
+ def test_directions_attr
20
+ assert_attr_accessor @route1, :directions, []
21
+ end
22
+
23
+ def test_instantiated_with_attrs
24
+ attrs = {:tag => 'my tag', :title => 'my title'}
25
+ assert_instantiated_with_attrs Nextbus::Route, attrs
26
+ end
27
+
28
+ def test_all
29
+ route_title1 = '39'
30
+ route_title2 = '111'
31
+ agency_id = 'abc'
32
+ expect_response('route_list.xml', /#{agency_id}/, Net::HTTP::Get)
33
+ all = Nextbus::Route.all(agency_id)
34
+ assert all.is_a?(Array)
35
+ assert_equal 2, all.length
36
+ assert all[0].is_a?(Nextbus::Route)
37
+ assert_equal route_title1, all[0].title
38
+ assert_equal route_title2, all[1].title
39
+ end
40
+
41
+ def test_find
42
+ route_title = '39'
43
+ agency_id = 'abc'
44
+ route_id = '123'
45
+ expect_response('route_config.xml', /#{agency_id}.+#{route_id}/, Net::HTTP::Get)
46
+ route = Nextbus::Route.find(agency_id, route_id)
47
+ assert route.is_a?(Nextbus::Route)
48
+ assert_equal route_title, route.title
49
+ end
50
+
51
+ end
@@ -0,0 +1,64 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'helper')
2
+
3
+ class TestStop < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @stop1 = Nextbus::Stop.new
7
+ end
8
+
9
+ def test_tag_attr
10
+ assert_attr_accessor @stop1, :tag
11
+ end
12
+ def test_title_attr
13
+ assert_attr_accessor @stop1, :title
14
+ end
15
+ def test_short_lat_attr
16
+ assert_attr_accessor @stop1, :lat
17
+ end
18
+ def test_region_lon_attr
19
+ assert_attr_accessor @stop1, :lon
20
+ end
21
+ def test_region_id_attr
22
+ assert_attr_accessor @stop1, :id
23
+ end
24
+
25
+ def test_direction_attr
26
+ assert_attr_accessor @stop1, :direction
27
+ end
28
+ def test_predictions_attr
29
+ assert_attr_accessor @stop1, :predictions, []
30
+ end
31
+
32
+ def test_instantiated_with_attrs
33
+ attrs = {:tag => 'my tag', :title => 'my title', :lat => 'my lat', :lon => 'my lon', :id => 'my id'}
34
+ assert_instantiated_with_attrs Nextbus::Stop, attrs
35
+ end
36
+
37
+ def test_all
38
+ stop_tag1 = '23391'
39
+ stop_tag2 = '173'
40
+ agency_id = 'abc'
41
+ route_id = '321'
42
+ direction_id = 'out'
43
+ expect_response('route_config.xml', /#{agency_id}.+#{route_id}/, Net::HTTP::Get)
44
+ all = Nextbus::Stop.all(agency_id, route_id, direction_id)
45
+ assert all.is_a?(Array)
46
+ assert_equal 32, all.length
47
+ assert all[0].is_a?(Nextbus::Stop)
48
+ assert_equal stop_tag1, all[0].tag
49
+ assert_equal stop_tag2, all[1].tag
50
+ end
51
+
52
+ def test_find
53
+ stop_tag = '23391'
54
+ agency_id = 'abc'
55
+ route_id = '321'
56
+ direction_id = 'out'
57
+ stop_id = '23391'
58
+ expect_response('route_config.xml', /#{agency_id}.+#{route_id}/, Net::HTTP::Get)
59
+ stop = Nextbus::Stop.find(agency_id, route_id, direction_id, stop_id)
60
+ assert stop.is_a?(Nextbus::Stop)
61
+ assert_equal stop_tag, stop.tag
62
+ end
63
+
64
+ end
@@ -0,0 +1,33 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'helper')
2
+
3
+ class TestStringExtensions < Test::Unit::TestCase
4
+
5
+ def setup
6
+ super
7
+ end
8
+
9
+ def test_camel_case
10
+ str = 'CamelCaseString'
11
+ assert_equal 'camel_case_string', String.underscore(str)
12
+ assert_equal 'camel_case_string', str.underscore
13
+ end
14
+
15
+ def test_uppercase
16
+ str = 'UPPERCASE'
17
+ assert_equal 'uppercase', String.underscore(str)
18
+ assert_equal 'uppercase', str.underscore
19
+ end
20
+
21
+ def test_camel_case_with_space
22
+ str = 'CamelCase String'
23
+ assert_equal 'camel_case_string', String.underscore(str)
24
+ assert_equal 'camel_case_string', str.underscore
25
+ end
26
+
27
+ def test_underscored
28
+ str = 'already_underscored'
29
+ assert_equal 'already_underscored', String.underscore(str)
30
+ assert_equal 'already_underscored', str.underscore
31
+ end
32
+
33
+ end
@@ -0,0 +1,52 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'helper')
2
+
3
+ class TestVehicle < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @vehicle1 = Nextbus::Vehicle.new
7
+ end
8
+
9
+ def test_id_attr
10
+ assert_attr_accessor @vehicle1, :id
11
+ end
12
+
13
+ def test_agency_attr
14
+ assert_attr_accessor @vehicle1, :agency
15
+ end
16
+ def test_route_attr
17
+ assert_attr_accessor @vehicle1, :route
18
+ end
19
+ def test_reports_attr
20
+ assert_attr_accessor @vehicle1, :reports, []
21
+ end
22
+
23
+ def test_instantiated_with_attrs
24
+ attrs = {:id => 'my id'}
25
+ assert_instantiated_with_attrs Nextbus::Vehicle, attrs
26
+ end
27
+
28
+ def test_all
29
+ vehicle_id1 = '1022'
30
+ vehicle_id2 = '1041'
31
+ agency_id = 'abc'
32
+ route_id = '123'
33
+ expect_response('vehicle_locations.xml', /#{agency_id}.+#{route_id}/, Net::HTTP::Get)
34
+ all = Nextbus::Vehicle.all(agency_id, route_id)
35
+ assert all.is_a?(Array)
36
+ assert_equal 7, all.length
37
+ assert all[0].is_a?(Nextbus::Vehicle)
38
+ assert_equal vehicle_id1, all[0].id
39
+ assert_equal vehicle_id2, all[1].id
40
+ end
41
+
42
+ def test_find
43
+ vehicle_id = '1022'
44
+ agency_id = 'abc'
45
+ route_id = '123'
46
+ expect_response('vehicle_locations.xml', /#{agency_id}.+#{route_id}/, Net::HTTP::Get)
47
+ vehicle = Nextbus::Vehicle.find(agency_id, route_id, vehicle_id)
48
+ assert vehicle.is_a?(Nextbus::Vehicle)
49
+ assert_equal vehicle_id, vehicle.id
50
+ end
51
+
52
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nextbus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Greg Sterndale
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-23 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: NextBus API client
17
+ email: gsterndale@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .gitignore
27
+ - Gemfile
28
+ - Gemfile.lock
29
+ - LICENSE
30
+ - README.rdoc
31
+ - Rakefile
32
+ - VERSION
33
+ - doc/ERM.graffle
34
+ - doc/MBTA_XML_Feed_Trial_Docs_13Nov09-1.pdf
35
+ - lib/attr_with_default.rb
36
+ - lib/instantiate_with_attrs.rb
37
+ - lib/nextbus.rb
38
+ - lib/nextbus/agency.rb
39
+ - lib/nextbus/client.rb
40
+ - lib/nextbus/direction.rb
41
+ - lib/nextbus/mash_extensions.rb
42
+ - lib/nextbus/prediction.rb
43
+ - lib/nextbus/report.rb
44
+ - lib/nextbus/route.rb
45
+ - lib/nextbus/stop.rb
46
+ - lib/nextbus/string_extensions.rb
47
+ - lib/nextbus/vehicle.rb
48
+ - nextbus.gemspec
49
+ - test/fixtures/agency_list.xml
50
+ - test/fixtures/error.xml
51
+ - test/fixtures/predictions.xml
52
+ - test/fixtures/predictions_for_multi_stops.xml
53
+ - test/fixtures/route_config.xml
54
+ - test/fixtures/route_list.xml
55
+ - test/fixtures/vehicle_locations.xml
56
+ - test/helper.rb
57
+ - test/unit/test_agency.rb
58
+ - test/unit/test_attr_with_default.rb
59
+ - test/unit/test_client.rb
60
+ - test/unit/test_direction.rb
61
+ - test/unit/test_instantiate_with_attrs.rb
62
+ - test/unit/test_mash_extensions.rb
63
+ - test/unit/test_nextbus.rb
64
+ - test/unit/test_prediction.rb
65
+ - test/unit/test_report.rb
66
+ - test/unit/test_route.rb
67
+ - test/unit/test_stop.rb
68
+ - test/unit/test_string_extensions.rb
69
+ - test/unit/test_vehicle.rb
70
+ - vendor/cache/columnize-0.3.1.gem
71
+ - vendor/cache/crack-0.1.6.gem
72
+ - vendor/cache/hashie-0.1.8.gem
73
+ - vendor/cache/httparty-0.5.2.gem
74
+ - vendor/cache/linecache-0.43.gem
75
+ - vendor/cache/mocha-0.9.8.gem
76
+ - vendor/cache/rake-0.8.7.gem
77
+ - vendor/cache/ruby-debug-0.10.3.gem
78
+ - vendor/cache/ruby-debug-base-0.10.3.gem
79
+ has_rdoc: true
80
+ homepage: http://github.com/neweryankee/nextbus
81
+ licenses: []
82
+
83
+ post_install_message:
84
+ rdoc_options:
85
+ - --charset=UTF-8
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: "0"
93
+ version:
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: "0"
99
+ version:
100
+ requirements: []
101
+
102
+ rubyforge_project:
103
+ rubygems_version: 1.3.5
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: NextBus API client
107
+ test_files:
108
+ - test/helper.rb
109
+ - test/unit/test_agency.rb
110
+ - test/unit/test_attr_with_default.rb
111
+ - test/unit/test_client.rb
112
+ - test/unit/test_direction.rb
113
+ - test/unit/test_instantiate_with_attrs.rb
114
+ - test/unit/test_mash_extensions.rb
115
+ - test/unit/test_nextbus.rb
116
+ - test/unit/test_prediction.rb
117
+ - test/unit/test_report.rb
118
+ - test/unit/test_route.rb
119
+ - test/unit/test_stop.rb
120
+ - test/unit/test_string_extensions.rb
121
+ - test/unit/test_vehicle.rb