mass_highways 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/CONTRIBUTING.md +25 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +20 -0
- data/lib/mass_highways/event.rb +42 -0
- data/lib/mass_highways/event_feed.rb +16 -0
- data/lib/mass_highways/pair.rb +29 -0
- data/lib/mass_highways/travel_feed.rb +16 -0
- data/lib/mass_highways/version.rb +3 -0
- data/lib/mass_highways.rb +11 -0
- data/mass_highways.gemspec +26 -0
- data/test/cassettes/event_feed.yml +3143 -0
- data/test/cassettes/travel_feed.yml +48977 -0
- data/test/event_feed_test.rb +41 -0
- data/test/test_helper.rb +11 -0
- data/test/travel_feed_test.rb +40 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5e9e645e6088037a00b7149f009ff0666fed86fa
|
4
|
+
data.tar.gz: 917f62025a5fae6c57bc6703124990a0b41d997f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 87246c023e71f5b693bf013191f83ce5d04da02e77b72d9ec9ebf186089de2a9eeba8955604c0787d4250b6d2178b0bbe15c96d98616a562831b2a14a46415d9
|
7
|
+
data.tar.gz: b64d1bec56a49d93997fa9540e0afc6902b7699af7f1ec7aae83b540455295cbd160c0b136c85a771a5697184fe5ac8797825d0bce72563eebf941a55a715419
|
data/.gitignore
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Contribution Guidelines #
|
2
|
+
|
3
|
+
## Submitting a new issue ##
|
4
|
+
|
5
|
+
If you want to ensure that your issue gets fixed *fast* you should
|
6
|
+
attempt to reproduce the issue in an isolated example application that
|
7
|
+
you can share.
|
8
|
+
|
9
|
+
## Making a pull request ##
|
10
|
+
|
11
|
+
If you'd like to submit a pull request please adhere to the following:
|
12
|
+
|
13
|
+
1. Your code *must* be tested. Please TDD your code!
|
14
|
+
2. No single-character variables
|
15
|
+
3. Two-spaces instead of tabs
|
16
|
+
4. Single-quotes instead of double-quotes unless you are using string
|
17
|
+
interpolation or escapes.
|
18
|
+
5. General Rails/Ruby naming conventions for files and classes
|
19
|
+
|
20
|
+
Please note that you must adhere to each of the aforementioned rules.
|
21
|
+
Failure to do so will result in an immediate closing of the pull
|
22
|
+
request. If you update and rebase the pull request to follow the
|
23
|
+
guidelines your pull request will be re-opened and considered for
|
24
|
+
inclusion.
|
25
|
+
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Dan McClain
|
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,46 @@
|
|
1
|
+
# MassHighways
|
2
|
+
|
3
|
+
Ruby wrapper for Massachusetts DOT traffic and event feeds
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'mass_highways'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install mass_highways
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Authors ##
|
24
|
+
|
25
|
+
* [Dan McClain](http://twitter.com/_danmcclain)
|
26
|
+
|
27
|
+
[We are very thankful for the many
|
28
|
+
contributors](https://github.com/dockyard/mass_highways/graphs/contributors)
|
29
|
+
|
30
|
+
## Versioning ##
|
31
|
+
|
32
|
+
This gem follows [Semantic Versioning](http://semver.org)
|
33
|
+
|
34
|
+
## Want to help? ##
|
35
|
+
|
36
|
+
Please do! We are always looking to improve this gem. Please see our
|
37
|
+
[Contribution Guidelines](https://github.com/dockyard/mass_highways/blob/master/CONTRIBUTING.md)
|
38
|
+
on how to properly submit issues and pull requests.
|
39
|
+
|
40
|
+
## Legal ##
|
41
|
+
|
42
|
+
[DockYard](http://dockyard.com), Inc. © 2014
|
43
|
+
|
44
|
+
[@dockyard](http://twitter.com/dockyard)
|
45
|
+
|
46
|
+
[Licensed under the MIT license](http://www.opensource.org/licenses/mit-license.php)
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
task :console do
|
4
|
+
require 'irb'
|
5
|
+
require 'irb/completion'
|
6
|
+
require 'mass_highways'
|
7
|
+
ARGV.clear
|
8
|
+
IRB.start
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'rake/testtask'
|
12
|
+
|
13
|
+
Rake::TestTask.new(:test) do |t|
|
14
|
+
t.libs << 'lib'
|
15
|
+
t.libs << 'test'
|
16
|
+
t.pattern = 'test/**/*_test.rb'
|
17
|
+
t.verbose = false
|
18
|
+
end
|
19
|
+
|
20
|
+
task :default => :test
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module MassHighways
|
2
|
+
class Event
|
3
|
+
attr_accessor :event_id, :event_created_date, :event_start_date, :event_end_date,
|
4
|
+
:last_update, :event_status, :event_category, :event_type, :event_sub_type,
|
5
|
+
:roadway_name, :direction, :location_type, :primary_latitude, :primary_longitude,
|
6
|
+
:secondary_latitude, :secondary_longitude, :location_description,
|
7
|
+
:lane_blockage_description, :recurrence_description
|
8
|
+
def self.parse(node)
|
9
|
+
event = self.new
|
10
|
+
event.event_id = node.search('EventId').first.text.to_i
|
11
|
+
event.event_created_date = DateTime.parse node.search('EventCreatedDate').first.text
|
12
|
+
event.event_start_date = DateTime.parse node.search('EventStartDate').first.text
|
13
|
+
|
14
|
+
end_date = node.search('EventEndDate').first.text
|
15
|
+
event.event_end_date = DateTime.parse end_date unless end_date.empty?
|
16
|
+
|
17
|
+
event.last_update = DateTime.parse node.search('LastUpdate').first.text
|
18
|
+
event.event_status = node.search('EventStatus').first.text
|
19
|
+
event.event_category = node.search('EventCategory').first.text
|
20
|
+
event.event_type = node.search('EventType').first.text
|
21
|
+
event.event_sub_type = node.search('EventSubType').first.text
|
22
|
+
|
23
|
+
event.roadway_name = node.search('RoadwayName').first.text
|
24
|
+
event.direction = node.search('Direction').first.text
|
25
|
+
event.location_type = node.search('LocationType').first.text
|
26
|
+
event.primary_latitude = node.search('PrimaryLatitude').first.text.to_f
|
27
|
+
event.primary_longitude = node.search('PrimaryLongitude').first.text.to_f
|
28
|
+
|
29
|
+
secondary_latitude = node.search('SecondaryLatitude').first.text
|
30
|
+
event.secondary_latitude = secondary_latitude.to_i unless secondary_latitude == 'NaN'
|
31
|
+
|
32
|
+
secondary_longitude = node.search('SecondaryLongitude').first.text
|
33
|
+
event.secondary_longitude = secondary_longitude.to_i unless secondary_longitude == 'NaN'
|
34
|
+
|
35
|
+
event.location_description = node.search('LocationDescription').first.text
|
36
|
+
event.lane_blockage_description = node.search('LaneBlockageDescription').first.text
|
37
|
+
event.recurrence_description = node.search('RecurrenceDescription').first.text
|
38
|
+
|
39
|
+
event
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module MassHighways
|
2
|
+
class EventFeed
|
3
|
+
FeedUrl = 'http://www.massdot.state.ma.us/feeds/MARoadwayEventsXML.aspx'
|
4
|
+
|
5
|
+
def self.retrieve
|
6
|
+
response = Excon.get FeedUrl
|
7
|
+
doc = Nokogiri::XML(response.body)
|
8
|
+
|
9
|
+
events = doc.search('ERS_Events Events Event')
|
10
|
+
|
11
|
+
events.map do |event|
|
12
|
+
Event.parse event
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module MassHighways
|
2
|
+
class Pair
|
3
|
+
attr_accessor :title, :direction, :origin, :destination, :speed, :freeflow, :status, :route, :pair_id, :travel_time, :stale
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@route = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.parse(node)
|
10
|
+
pair = self.new
|
11
|
+
pair.pair_id = node.search('PairID').first.text.to_i
|
12
|
+
pair.title = node.search('Title').first.text
|
13
|
+
pair.direction = node.search('Direction').first.text
|
14
|
+
pair.origin = node.search('Origin').first.text
|
15
|
+
pair.destination = node.search('Destination').first.text
|
16
|
+
pair.speed = node.search('Speed').first.text.to_f
|
17
|
+
pair.travel_time = node.search('TravelTime').first.text.to_f
|
18
|
+
pair.freeflow = node.search('FreeFlow').first.text.to_f
|
19
|
+
|
20
|
+
node.search('Routes Route').each do |route_node|
|
21
|
+
lat = route_node.search('lat').first.text.to_f
|
22
|
+
lon = route_node.search('lon').first.text.to_f
|
23
|
+
pair.route << { lat: lat, lon: lon }
|
24
|
+
end
|
25
|
+
|
26
|
+
pair
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module MassHighways
|
2
|
+
class TravelFeed
|
3
|
+
FeedUrl = 'http://www.massdot.state.ma.us/feeds/traveltimes/RTTM_feed.aspx'
|
4
|
+
|
5
|
+
def self.retrieve
|
6
|
+
response = Excon.get FeedUrl
|
7
|
+
doc = Nokogiri::XML(response.body)
|
8
|
+
|
9
|
+
pairs = doc.search('btdata TRAVELDATA PAIRDATA')
|
10
|
+
|
11
|
+
pairs.map do |pair|
|
12
|
+
Pair.parse pair
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mass_highways/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'mass_highways'
|
8
|
+
spec.version = MassHighways::VERSION
|
9
|
+
spec.authors = ['Dan McClain']
|
10
|
+
spec.email = ['git@danmcclain.net']
|
11
|
+
spec.summary = %q{Ruby wrapper for Massachusetts DOT traffic and event feeds}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'excon'
|
22
|
+
spec.add_runtime_dependency 'nokogiri'
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency 'vcr'
|
26
|
+
end
|