mbta_wrapper 0.0.2 → 0.0.200

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/sicentendu/mbta_wrapper.png?branch=master)](https://travis-ci.org/sicentendu/mbta_wrapper)
4
4
 
5
- Ruby MBTA API wrapper, nothing is really built yet but maybe it will be soon
5
+ Ruby MBTA API wrapper gem, not much is really built yet but maybe it will be soon. If you think of any features you want, let me know.
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,20 +22,29 @@ Or install it yourself as:
22
22
 
23
23
  This gem provides super easy access to the MBTA's API.
24
24
 
25
- MbtaWrapper::Subway
26
- MbtaWrapper::CommuterRail
27
- MbtaWrapper::Bus
25
+ MbtaWrapper::Subway # Built
26
+ MbtaWrapper::CommuterRail # Not Built
27
+ MbtaWrapper::Bus # Not Built
28
+
29
+ MbtaWrapper::SubwayLine # Built
30
+ MbtaWrapper::CommuterRailLine # Not Built
31
+ MbtaWrapper::BusLine # Not Built
28
32
 
29
33
  To view the current number of red line trains running:
30
34
 
31
- MbtaWrapper::SubwayLine.new('red').active_trains
35
+ MbtaWrapper.red_line.active_trains
32
36
 
33
37
  To create an array of current trains on the red line:
34
38
 
35
- MbtaWrapper::SubwayLine.new('red').current_trains
39
+ MbtaWrapper.red_line.current_trains
36
40
 
37
41
  ## Contributing
38
42
 
43
+ TODO:
44
+ Implement CommuterRail and Bus (lines), create tests, think of more ways to supply data
45
+
46
+ If you'd like to help:
47
+
39
48
  1. Fork it
40
49
  2. Create your feature branch (`git checkout -b my-new-feature`)
41
50
  3. Commit your changes (`git commit -am 'Add some feature'`)
data/lib/mbta_wrapper.rb CHANGED
@@ -10,5 +10,17 @@ require 'net/http'
10
10
  require 'rexml/document'
11
11
 
12
12
  module MbtaWrapper
13
+
14
+ def self.orange_line
15
+ MbtaWrapper::SubwayLine.new('orange')
16
+ end
17
+
18
+ def self.blue_line
19
+ MbtaWrapper::SubwayLine.new('blue')
20
+ end
21
+
22
+ def self.red_line
23
+ MbtaWrapper::SubwayLine.new('red')
24
+ end
13
25
 
14
26
  end
@@ -1,21 +1,5 @@
1
1
  module MbtaWrapper
2
2
  class Bus
3
- def initialize(line)
4
- @line = line
5
- end
6
-
7
- def self.get_xml(command)
8
- resp = Net::HTTP.get_response(URI.parse("http://webservices.nextbus.com/service/publicXMLFeed?command=#{command}&a=mbta")).body
9
- data = REXML::Document.new(resp)
10
- end
11
-
12
- def self.all_lines
13
- line_names = []
14
- routes = Bus.get_xml('routeList')[2]
15
- routes.each do |title|
16
- line_names << title.text
17
- end
18
- line_names
19
- end
3
+
20
4
  end
21
5
  end
@@ -1,5 +1,37 @@
1
1
  module MbtaWrapper
2
2
  class BusLine
3
+ def initialize(line)
4
+ @line = line
5
+ end
3
6
 
7
+ def line
8
+ @line
9
+ end
10
+
11
+ def self.get_xml_no_route(command)
12
+ resp = Net::HTTP.get_response(URI.parse("http://webservices.nextbus.com/service/publicXMLFeed?command=#{command}&a=mbta")).body
13
+ data = REXML::Document.new(resp)
14
+ end
15
+
16
+ def self.get_xml(command, route)
17
+ resp = Net::HTTP.get_response(URI.parse("http://webservices.nextbus.com/service/publicXMLFeed?command=#{command}&a=mbta&r=#{route}")).body
18
+ data = REXML::Document.new(resp)
19
+ end
20
+
21
+
22
+ def self.all_lines
23
+ line_names = []
24
+ routes = MbtaWrapper::BusLine.get_xml_no_route('routeList')
25
+ routes.elements.each('*/route') do |title|
26
+ line_names << title.attributes['title']
27
+ end
28
+ line_names
29
+ end
30
+
31
+ ##
32
+ # Display inbound or outbound route for Bus
33
+ def route_config(bus_line, direction)
34
+ stops = MbtaWrapper::BusLine.get_xml('routeConfig', bus_line.to_i)
35
+ end
4
36
  end
5
37
  end
@@ -1,4 +1,13 @@
1
1
  module MbtaWrapper
2
+ ##
3
+ # This class represents an individual T (subway train)
4
+ #
5
+ # Train number is the ID number given by the MBTA \n
6
+ # Destination is the end destination of the train \n
7
+ # Stops is an array of hashes containing the stop name and seconds until it will be reached \n
8
+ # Position is the last updated latitude and longitude coordinates of the train \n
9
+ #
10
+ # Subway should be generated from SubwayLine, it will constantly need to be regenerated to reflect current train status
2
11
  class Subway
3
12
  def initialize(train_number, destination, stops, position)
4
13
  @train_number = train_number
@@ -23,12 +32,16 @@ module MbtaWrapper
23
32
  @position
24
33
  end
25
34
 
35
+ ##
36
+ # Returns the next stop the train will make
26
37
  def next_stop
27
38
  stops.first
28
39
  end
29
40
 
41
+ ##
42
+ # Returns the time in seconds it will take the train to reach the given station
30
43
  def time_to_stop_at(station)
31
- stops.select {|stop| stop['Stop'] == station}.first['Seconds']
44
+ stops.select {|stop| stop['Stop'] == station}.first['Seconds'] ||= nil
32
45
  end
33
46
  end
34
47
  end
@@ -1,10 +1,26 @@
1
1
  module MbtaWrapper
2
+ ##
3
+ # This class represents a colored T (subway) line
4
+ #
5
+ # It is initialized with the given color
2
6
  class SubwayLine
3
7
  def initialize(line)
4
8
  @line = line
5
9
  @default_json_url = "http://developer.mbta.com/lib/rthr/" + @line.to_s.downcase + ".json"
6
10
  end
7
11
 
12
+ def get_json(url = @default_json_url)
13
+ Net::HTTP.get_response(URI.parse(url)).body
14
+ end
15
+
16
+ def parse_json(url = @default_json_url)
17
+ resp = get_json(url)
18
+ data = JSON.parse(resp)
19
+ ready = data['TripList']
20
+ end
21
+
22
+ ##
23
+ # Returns an array of MbtaWrapper::Subway, representing the current trains running
8
24
  def current_trains
9
25
  data = parse_json
10
26
  current_trains = []
@@ -22,25 +38,16 @@ module MbtaWrapper
22
38
  end
23
39
  current_trains
24
40
  end
25
-
26
-
27
- def get_json(url = @default_json_url)
28
- Net::HTTP.get_response(URI.parse(url)).body
29
- end
30
-
31
- def parse_json(url = @default_json_url)
32
- resp = get_json(url)
33
- data = JSON.parse(resp)
34
- ready = data['TripList']
35
- end
36
41
 
37
- # Number of current active trains
42
+ ##
43
+ # Returns the number of current active trains
38
44
  def active_trains
39
45
  data = parse_json
40
46
  data['Trips'].length
41
47
  end
42
48
 
43
- # Time until next train at station
49
+ ##
50
+ # Incomplete
44
51
  def time_until(station)
45
52
  data = parse_json
46
53
  time = 0
@@ -48,7 +55,8 @@ module MbtaWrapper
48
55
  end
49
56
  end
50
57
 
51
- #
58
+ ##
59
+ # Incomplete
52
60
  def upcoming(number = 10)
53
61
  data = parse_json
54
62
  data['Trips'].each do |trip|
@@ -63,6 +71,8 @@ module MbtaWrapper
63
71
  end
64
72
  end
65
73
 
74
+ ##
75
+ # Incomplete
66
76
  def next_stops
67
77
  end
68
78
  end
@@ -1,3 +1,3 @@
1
1
  module MbtaWrapper
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.200"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mbta_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.200
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-10 00:00:00.000000000 Z
12
+ date: 2013-02-11 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Simple MBTA Ruby wrapper
15
15
  email: