mbta_wrapper 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mbta_wrapper.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ryan Williams
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # MbtaWrapper
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mbta_wrapper'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mbta_wrapper
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ module MbtaWrapper
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
20
+ end
21
+ end
@@ -0,0 +1,47 @@
1
+ module MbtaWrapper
2
+ class CommuterRail
3
+ def initialize(line)
4
+ @line_name = line
5
+ @line = COMMUTER_RAIL_LINES[line.to_s]
6
+ if @line.nil?
7
+ puts 'Error: line name incorrect'
8
+ end
9
+ end
10
+
11
+ COMMUTER_RAIL_LINES = {'Greenbush' => '1', 'Kingston' => '2', 'Kingston/Plymouth' => '2', 'Plymouth' => '2', 'Middleborough/Lakeville' => '3', 'Middleborough' => '3', 'Lakeville' => '3', 'Fairmount' => '4', 'Providence/Stoughton' => '5', 'Providence' => '5', 'Stoughton' => '5', 'Franklin' => '6', 'Needham' => '7', 'Framingham/Worcester' => '8', 'Framingham' => '8', 'Worcester' => '8', 'Fitchburg' => '9', 'Lowell' => '10', 'Haverhill' => '11', 'Newburyport/Rockport' => '2', 'Newburyport' => '2', 'Rockport' => '2'}
12
+
13
+ COMMUTER_RAIL_JSON_URL = "http://developer.mbta.com/lib/RTCR/RailLine_"
14
+
15
+ def get_and_parse_json
16
+ resp = Net::HTTP.get_response(URI.parse("http://developer.mbta.com/lib/RTCR/RailLine_#{@line}.json"))
17
+ data = JSON.parse(resp.body)
18
+ end
19
+
20
+ # Total active trains in all lines
21
+ def self.total_active_trains
22
+ total = 0
23
+ for i in 1..12
24
+ resp = Net::HTTP.get_response(URI.parse(COMMUTER_RAIL_JSON_URL + i.to_s + ".json"))
25
+ data = JSON.parse(resp.body)
26
+ total += data['Trips'].length
27
+ end
28
+ total
29
+ end
30
+
31
+ def self.current_location_all_trains
32
+ locations = []
33
+ for i in 1..12
34
+ resp = Net::HTTP.get_response(URI.parse(COMMUTER_RAIL_JSON_URL + i.to_s + ".json"))
35
+ data = JSON.parse(resp.body)
36
+ data['Messages'].each do |trip|
37
+ locations << [trip[7]['Value'], trip[8]['Value']]
38
+ end
39
+ end
40
+ locations
41
+ end
42
+
43
+ # Active train for given lines
44
+ def active_trains
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,46 @@
1
+ module MbtaWrapper
2
+ class Subway
3
+ def initialize(line)
4
+ @line = line
5
+ end
6
+
7
+ def get_and_parse_json
8
+ resp = Net::HTTP.get_response(URI.parse("http://developer.mbta.com/lib/rthr/#{@line}.json"))
9
+ data = JSON.parse(resp.body)
10
+ ready = data['TripList']
11
+ end
12
+
13
+ # Number of current active trains
14
+ def active_trains
15
+ data = get_and_parse_json
16
+ data['Trips'].length
17
+ end
18
+
19
+ # Time until next train at station
20
+ def time_until(station)
21
+ data = get_and_parse_json
22
+ time = 0
23
+ data['Trips'].each do |trip|
24
+ end
25
+ end
26
+
27
+ #
28
+ def upcoming(number = 10)
29
+ data = get_and_parse_json
30
+ data['Trips'].each do |trip|
31
+ first_prediction = trip['Predictions'].first
32
+ stop = first_prediction['Stop']
33
+ time = (sec = first_prediction['Seconds'].to_i) < 60 ? sec : (sec / 60).round
34
+ if sec < 60
35
+ puts "A #{@line} line train will arrive at #{stop} in #{time} seconds"
36
+ else
37
+ puts "A #{@line} line train will arrive at #{stop} in #{time} minutes"
38
+ end
39
+ end
40
+ end
41
+
42
+ def next_stops
43
+ end
44
+ end
45
+ end
46
+
@@ -0,0 +1,3 @@
1
+ module MbtaWrapper
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,11 @@
1
+ require "mbta_wrapper/version"
2
+ require "mbta_wrapper/bus"
3
+ require "mbta_wrapper/commuterrail"
4
+ require "mbta_wrapper/subway"
5
+ require 'json'
6
+ require 'net/http'
7
+ require 'rexml/document'
8
+
9
+ module MBTAWrapper
10
+ # Your code goes here...
11
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mbta_wrapper/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "mbta_wrapper"
8
+ gem.version = MbtaWrapper::VERSION
9
+ gem.authors = ["Ryan Williams"]
10
+ gem.email = ["ryancwilliams9@gmail.com"]
11
+ gem.description = "Simple MBTA Ruby wrapper"
12
+ gem.summary = "Simple MBTA Ruby wrapper"
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mbta_wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Williams
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-10 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Simple MBTA Ruby wrapper
15
+ email:
16
+ - ryancwilliams9@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/mbta_wrapper.rb
27
+ - lib/mbta_wrapper/bus.rb
28
+ - lib/mbta_wrapper/commuterrail.rb
29
+ - lib/mbta_wrapper/subway.rb
30
+ - lib/mbta_wrapper/version.rb
31
+ - mbta_wrapper.gemspec
32
+ homepage: ''
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.25
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Simple MBTA Ruby wrapper
56
+ test_files: []