metrobus 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +7 -0
- data/.travis.yml +16 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +140 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/metrobus.rb +28 -0
- data/lib/metrobus/base.rb +17 -0
- data/lib/metrobus/connection.rb +36 -0
- data/lib/metrobus/departure.rb +32 -0
- data/lib/metrobus/direction.rb +20 -0
- data/lib/metrobus/route.rb +42 -0
- data/lib/metrobus/stop.rb +34 -0
- data/lib/metrobus/version.rb +5 -0
- data/metrobus.gemspec +33 -0
- metadata +177 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTAxYTY2NzI2Y2U3YjYzNDZlNzA3MTBjZTJkMDIzODkwMTJhNWI3Ng==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDJhMTQ4YmM1OTAyOWI2MzAzOTZiMmJjYjAwNzM4MmQ2MjM5ZGFiZA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NzYzNjc5NmM3NTA4MzkxMDdkNTQyMDM3ZGUxMTg0NzQ1MmU0MWZjZDFhZjli
|
10
|
+
YTVhMWJjMmM1ZGQ3OTkyMmUxMWQ5N2VhYzVmODliZTg1MmUxMWYzM2Q3NzFh
|
11
|
+
ZTVjYThlMGU1YjViODI1ZGE4MWFiZjc4NDYzZGRhNDcxMmE0NDA=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MzRlMTZkNWY2ZTkyMDI2MTdmMzBiNWJkOWRiOTlkZjM1ZjQ3YTVjYWYwM2Y5
|
14
|
+
ZmRkNTA0ZGUzNmI4NWMyNzc1ZGFlOWU4YTVmODk5YmQ5M2IwMjBiMjcyNmI2
|
15
|
+
Y2U2Zjc0OTMxNDE5MGI0NzlkM2UzMGJhYWI2Y2Q2NjNlM2IyYjc=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.0.0
|
5
|
+
before_install: gem install bundler -v 1.12.5
|
6
|
+
script:
|
7
|
+
- bundle exec rake spec
|
8
|
+
- bundle exec rubocop
|
9
|
+
deploy:
|
10
|
+
provider: rubygems
|
11
|
+
api_key:
|
12
|
+
secure: Jz0lM8uxp2T+Ek5AOAHTV6guOtx4C008n4X4Pa8BUc/Vki30CSBmgBwBvOzBGNjpnlKPK3hZsMegB1V1uYnB1FfXDxKGUWiEtOJ5YDAWnMXPfCwo7GUlykVc9fAAzERDc/Wr7IYZjsWga7iLga3NOdk/LIlvfjnWJzKDM7rWQ11T9qv8Jcpiq4kv8qgrZK1zbxNEpXL4PZfuBqm4tByCR2isxlUTUBzXque6YF3tQ9Xx6K+u/Jt9uONqSEcKpasJpbUmnKYynubX0JYT5qT+ZK+T93xAtXHQ7FXxDKy8hFu3Co3diBYZis80KRNGNK/oL1loB2jN2iGOvHs4FGMUQ4eVZZk7bxZpFeYmc0j83iGfEXWyRPYMIYstUl6+HFM7A3Ques3feF7zcMAVN5KzBGADEuGcLt/Qyy7ogGDBwgw9DNxK+xq+rkIZZhW7MhCbWu24b5lUh9sZectxRIoUr/67aT+wbB5sBEfyb8WsPX+FIlevx7bW+MbOn96pXxs8SAWMPy4XRCPB+6zD7OpgsbL0UlK3Z9kbVXFcguyox5jmmf3uJKykwwCZAtJspPjkxmBWwM3NjDhQNxf/GaGQ/DP8YeiOHVNZyxD7JyxzEnt1lvs+36Lm0sab6rtRJiBHyHjCs/NKWO5to+BVOY34jGpGl6ncnXsK6mgcMVoADgw=
|
13
|
+
gem: metrobus
|
14
|
+
on:
|
15
|
+
tags: true
|
16
|
+
repo: sbower/metrobus
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at shawn.bower@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 sbower
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
# Metrobus![Build Status](https://api.travis-ci.org/sbower/metrobus.svg) [![Gem Version](https://badge.fury.io/rb/metrobus.svg)](https://badge.fury.io/rb/metrobus)[![Coverage Status](https://coveralls.io/repos/github/sbower/metrobus/badge.svg?branch=master)](https://coveralls.io/github/sbower/metrobus?branch=master)
|
2
|
+
|
3
|
+
Library to wrap the metrotransit.org web services which provide real-time transit departure data
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'metrobus'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install metrobus
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Metrobus::Route
|
24
|
+
|
25
|
+
If you want to get all available routes for the day you can use the following.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
all_routes = Metrobus::Route.all
|
29
|
+
```
|
30
|
+
|
31
|
+
If you want to get the routes that match a string you can do something like.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
found_routes = Metrobus::Route.find("u of m")
|
35
|
+
```
|
36
|
+
|
37
|
+
In this example all routes containing the string "u of m" will be returned,
|
38
|
+
output might look something like.
|
39
|
+
|
40
|
+
>*************************
|
41
|
+
2 - Franklin Av - Riverside Av - U of M - 8th St SE
|
42
|
+
3 - U of M - Como Av - Energy Park Dr - Maryland Av
|
43
|
+
6 - U of M - Hennepin - Xerxes - France - Southdale
|
44
|
+
16 - U of M - University Av - Midway
|
45
|
+
87 - Rosedale - U of M St Paul - Cleveland Av
|
46
|
+
111 - Ltd Stop - 66th St - Chicago - Cedar - U of M
|
47
|
+
113 - Ltd Stop - Grand Av S - Lyndale Av S - U of M
|
48
|
+
114 - Ltd Stop - Excelsior Blvd - Uptown - U of M
|
49
|
+
115 - Ltd Stop - Grand Av S - Uptown - U of M
|
50
|
+
118 - Ltd Stop - Central Av - Lowry Av - U of M
|
51
|
+
120 - U of M Stadium Super Shuttle
|
52
|
+
121 - U of M - Campus Connector
|
53
|
+
122 - U of M - University Ave Circulator
|
54
|
+
123 - U of M - 4th Street Circulator
|
55
|
+
124 - U of M - Saint Paul Circulator
|
56
|
+
129 - U of M - Huron Shuttle
|
57
|
+
252 - 95AV P&R- U of M
|
58
|
+
272 - Express - Maplewood - Roseville - U of M
|
59
|
+
465 - Burnsville-Minneapolis-U of M
|
60
|
+
475 - Apple Valley-Cedar Grove-Mpls/U of M
|
61
|
+
579 - Express - U of M - Southdale
|
62
|
+
652 - Express - Plymouth Rd - Co Rd 73 P&R - U of M
|
63
|
+
789 - Maple Grove - U of M
|
64
|
+
*************************
|
65
|
+
|
66
|
+
If you have a route object you can get the direction_id with the following:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
found_routes = Metrobus::Route.find("u of m")
|
70
|
+
route = found_routes[0]
|
71
|
+
direction_id = route.get_direction_id(direction)
|
72
|
+
```
|
73
|
+
|
74
|
+
### Metrobus::Direction
|
75
|
+
|
76
|
+
You can get the valid directions for a route with the following. Note you have
|
77
|
+
to send the route number.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
directions = Metrobus::Direction.get('901')
|
81
|
+
```
|
82
|
+
The result is an array of directions which should be of length 2. Routes run
|
83
|
+
east/west and north/south. Directions are identified with an ID value. 1 = South,
|
84
|
+
2 = East, 3 = West, 4 = North.
|
85
|
+
|
86
|
+
|
87
|
+
### Metrobus::Stop
|
88
|
+
|
89
|
+
If you are looking for a stop on a specific route going a specific direction
|
90
|
+
you could use the following. Directions are identified with an ID value.
|
91
|
+
1 = South, 2 = East, 3 = West, 4 = North.
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
stops = Metrobus::Stop.get('121', '2')
|
95
|
+
```
|
96
|
+
|
97
|
+
If you want to get the stop that match a string you can do something like.
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
found_stop = Metrobus::Stop.find("target")
|
101
|
+
```
|
102
|
+
|
103
|
+
In this example all routes containing the string "target" will be returned,
|
104
|
+
output might look something like.
|
105
|
+
|
106
|
+
>*************************
|
107
|
+
Target Field Station Platform 1
|
108
|
+
Target Field Station Platform 2
|
109
|
+
*************************
|
110
|
+
|
111
|
+
### Metrobus::Departure
|
112
|
+
|
113
|
+
If you are looking for upcoming departures you can supply the route id, diercetion and stop_id like so.
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
departures = Metrobus::Departure.get('5', '4', '7SOL')
|
117
|
+
```
|
118
|
+
This will return an array of departures in ascending time order. If you wanted to get the time of the next departure
|
119
|
+
you could do something likes this.
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
departures = Metrobus::Departure.get('5', '4', '7SOL')
|
123
|
+
departures[0].get_next_departure_time
|
124
|
+
```
|
125
|
+
This will return a string with the number of minutes until the next departure.
|
126
|
+
|
127
|
+
## Development
|
128
|
+
|
129
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
130
|
+
|
131
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
132
|
+
|
133
|
+
## Contributing
|
134
|
+
|
135
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sbower/metrobus. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
136
|
+
|
137
|
+
|
138
|
+
## License
|
139
|
+
|
140
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'metrobus'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/metrobus.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
require 'json'
|
3
|
+
require 'rest-client'
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
# Metrobus module used to interact with the rest api at
|
7
|
+
# http://svc.metrotransit.org/NexTrip providing providing
|
8
|
+
# realtime departure data
|
9
|
+
module Metrobus
|
10
|
+
require 'metrobus/version'
|
11
|
+
require 'metrobus/base'
|
12
|
+
require 'metrobus/connection'
|
13
|
+
require 'metrobus/route'
|
14
|
+
require 'metrobus/direction'
|
15
|
+
require 'metrobus/stop'
|
16
|
+
require 'metrobus/departure'
|
17
|
+
|
18
|
+
# The REST endpoint for the metro transit realtime departure service
|
19
|
+
NEXT_TRIP = 'http://svc.metrotransit.org/NexTrip'.freeze
|
20
|
+
|
21
|
+
# get REST connection object to use, if non create a new object
|
22
|
+
# @return [Object] of type Metrobus::Conenction
|
23
|
+
def connection
|
24
|
+
@connection ||= Connection.new
|
25
|
+
end
|
26
|
+
|
27
|
+
module_function :connection
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Metrobus
|
2
|
+
# Base class - containes base functions used by other classes
|
3
|
+
# provides a facility for easily initializing classes.
|
4
|
+
class Base
|
5
|
+
attr_accessor :connection
|
6
|
+
|
7
|
+
# Initialization of metrobus objects from JSON from the REST service
|
8
|
+
# @param hash [Hash] key value hash constructed from JSON from the rest service
|
9
|
+
# @return [Object]
|
10
|
+
def initialize(hash = {}, connection = Metrobus.connection)
|
11
|
+
raise ArgumentError,
|
12
|
+
"Expected a Metrobus::Connection, got: #{connection}." unless connection.is_a?(Metrobus::Connection)
|
13
|
+
@connection = connection
|
14
|
+
hash.each { |name, value| instance_variable_set("@#{name.downcase}", value) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Metrobus
|
2
|
+
# Connection class - provides an abstration to the rest endpoint
|
3
|
+
class Connection
|
4
|
+
# Sends rest request to the metrobus REST service
|
5
|
+
# @param path [String] path string
|
6
|
+
# @param verb [String] get, post, head, etc.
|
7
|
+
# @param post_data [String] if sending a post, this data will be sent in the body
|
8
|
+
# @return [Hash] constructed from the parsed JSON
|
9
|
+
def request(path, verb = :get, post_data = {})
|
10
|
+
path = URI.escape(Metrobus::NEXT_TRIP + '/' + path)
|
11
|
+
|
12
|
+
JSON.parse(
|
13
|
+
RestClient::Request.execute(
|
14
|
+
construct_request_hash(path, verb, post_data)
|
15
|
+
)
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Sends rest request to the metrobus REST service
|
20
|
+
# @param path [String] path string
|
21
|
+
# @param verb [String] get, post, head, etc.
|
22
|
+
# @param post_data [String] if sending a post, this data will be sent in the body
|
23
|
+
# @return [Hash] constructed to send to rest-client
|
24
|
+
def construct_request_hash(path, verb, post_data)
|
25
|
+
opts = { payload: post_data.to_json }
|
26
|
+
verb = verb.to_sym if verb.is_a? String
|
27
|
+
{
|
28
|
+
method: verb,
|
29
|
+
url: path,
|
30
|
+
headers: {
|
31
|
+
Accept: 'application/json'
|
32
|
+
}
|
33
|
+
}.merge(opts).reject { |_, v| v.nil? }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Metrobus
|
2
|
+
# Departure class - domain object representing the departure times
|
3
|
+
class Departure < Base
|
4
|
+
attr_accessor :actual, :blockNumber, :departuretext, :departuretime,
|
5
|
+
:description, :Gate, :route, :routeDirection, :terminal, :vehicleheading,
|
6
|
+
:vehiclelatitude, :vehiclelongitude
|
7
|
+
|
8
|
+
# Get next depature time in minutes
|
9
|
+
# @return [String] of next departure time in mintues
|
10
|
+
def get_next_departure_time
|
11
|
+
if @actual
|
12
|
+
@departuretext
|
13
|
+
else
|
14
|
+
@departuretime =~ /Date\((\d+)-\d+\)/
|
15
|
+
departure_time = Time.at(Regexp.last_match(1).to_i / 1000)
|
16
|
+
minutes = ((departure_time - Time.now) / 60).round
|
17
|
+
"#{minutes} Min"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Get departure information for a a given route, direction and stop
|
22
|
+
# @param route_id [String] route_id for a metro route
|
23
|
+
# @param direction_id [String] direction_id attached to the route
|
24
|
+
# indicating north, south, east or west
|
25
|
+
# @param stop_id [String] stop id for a metro route
|
26
|
+
# @return [array] of Metrobus::Departure objects
|
27
|
+
def self.get(route_id, direction_id, stop_id, connection = Metrobus.connection)
|
28
|
+
directions = connection.request("#{route_id}/#{direction_id}/#{stop_id}")
|
29
|
+
directions.map { |hash| new(hash) }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Metrobus
|
2
|
+
# Direction class - domain object representing the directions for a route
|
3
|
+
class Direction < Base
|
4
|
+
# Path for the direction endpoint
|
5
|
+
DIRECTIONS_PATH = 'Directions/'.freeze
|
6
|
+
|
7
|
+
attr_accessor :text, :value
|
8
|
+
|
9
|
+
alias direction_name text
|
10
|
+
alias direction_id value
|
11
|
+
|
12
|
+
# Get direction information for a a given route
|
13
|
+
# @param route_id [String] route_id for a metro route
|
14
|
+
# @return [array] of Metrobus::Direction objects
|
15
|
+
def self.get(route_id, connection = Metrobus.connection)
|
16
|
+
directions = connection.request(DIRECTIONS_PATH + route_id)
|
17
|
+
directions.map { |hash| new(hash) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Metrobus
|
2
|
+
# Route class - domain object representing routes for the day
|
3
|
+
class Route < Base
|
4
|
+
# Path for the route endpoint
|
5
|
+
ROUTES_PATH = 'Routes'.freeze
|
6
|
+
|
7
|
+
attr_accessor :description, :providerid, :route
|
8
|
+
|
9
|
+
# Gets the valid directions for this route
|
10
|
+
# @return [Array] valid directions for this route
|
11
|
+
def directions
|
12
|
+
@directions ||= Metrobus::Direction.get(@route)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Finds directions_id containing the passed in direction_name for this route
|
16
|
+
# @param direction_name [String] direction_name a user is looking for
|
17
|
+
# @return [String] representing the diretion_id for the given route
|
18
|
+
def get_direction_id(direction_name)
|
19
|
+
matching_directions = directions.find do |matching_direction|
|
20
|
+
matching_direction.direction_name.downcase.include?(direction_name.downcase)
|
21
|
+
end
|
22
|
+
|
23
|
+
matching_directions.direction_id if matching_directions
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns all valid routes for the day
|
27
|
+
# @return [array] of Metrobus::Route objects
|
28
|
+
def self.all(connection = Metrobus.connection)
|
29
|
+
routes = connection.request(ROUTES_PATH)
|
30
|
+
routes.map { |hash| new(hash) }
|
31
|
+
end
|
32
|
+
|
33
|
+
# Finds routes containing the passed in route name
|
34
|
+
# @param route_name [String] route_name a user is looking for
|
35
|
+
# @return [array] of Metrobus::Route objects
|
36
|
+
def self.find(route_name, routes = all)
|
37
|
+
if routes
|
38
|
+
routes.find_all { |route| route.description.downcase.include?(route_name.downcase) }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Metrobus
|
2
|
+
# Stop class - domain object representing stops for a route going a specific direction
|
3
|
+
class Stop < Base
|
4
|
+
# Path for the stop endpoint
|
5
|
+
STOPS_PATH = 'Stops/'.freeze
|
6
|
+
|
7
|
+
attr_accessor :text, :value
|
8
|
+
|
9
|
+
alias stop_name text
|
10
|
+
alias stop_id value
|
11
|
+
|
12
|
+
# Get stop information for a a given route and direction
|
13
|
+
# @param route_id [String] route_id for a metro route
|
14
|
+
# @param direction_id [String] direction_id attached to the route
|
15
|
+
# indicating north, south, east or west
|
16
|
+
# @return [array] of Metrobus::Stop objects
|
17
|
+
def self.get(route_id, direction_id, connection = Metrobus.connection)
|
18
|
+
stops = connection.request(STOPS_PATH + "#{route_id}/#{direction_id}")
|
19
|
+
stops.map { |hash| new(hash) }
|
20
|
+
end
|
21
|
+
|
22
|
+
# Finds stops containing the passed in stop name
|
23
|
+
# @param stop_name [String] stop_name a user is looking for
|
24
|
+
# @param route_id [String] route_id for a metro route
|
25
|
+
# @param direction_id [String] direction_id attached to the route
|
26
|
+
# indicating north, south, east or west
|
27
|
+
# @return [array] of Metrobus::Stop objects
|
28
|
+
def self.find(stop_name, route_id, direction_id, stops = get(route_id, direction_id))
|
29
|
+
if stops
|
30
|
+
stops.find_all { |stop| stop.stop_name.downcase.include?(stop_name.downcase) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/metrobus.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'metrobus/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'metrobus'
|
8
|
+
spec.version = Metrobus::VERSION
|
9
|
+
spec.authors = ['sbower']
|
10
|
+
spec.email = ['shawn.bower@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Small Library to wrap the metrotransit.org web services'
|
13
|
+
spec.description = 'Small Library to wrap the metrotransit.org web services'
|
14
|
+
spec.homepage = 'https://github.com/sbower/metrobus'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.metadata['yard.run'] = 'yri'
|
23
|
+
|
24
|
+
spec.add_dependency 'rest-client'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'webmock'
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
|
+
spec.add_development_dependency 'coveralls'
|
31
|
+
spec.add_development_dependency 'rubocop', '~> 0.40.0'
|
32
|
+
spec.add_development_dependency 'yard', '~> 0.9.0'
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: metrobus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- sbower
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: webmock
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: coveralls
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.40.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.40.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: yard
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.9.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.9.0
|
125
|
+
description: Small Library to wrap the metrotransit.org web services
|
126
|
+
email:
|
127
|
+
- shawn.bower@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- .gitignore
|
133
|
+
- .rspec
|
134
|
+
- .rubocop.yml
|
135
|
+
- .travis.yml
|
136
|
+
- CODE_OF_CONDUCT.md
|
137
|
+
- Gemfile
|
138
|
+
- LICENSE.txt
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- bin/console
|
142
|
+
- bin/setup
|
143
|
+
- lib/metrobus.rb
|
144
|
+
- lib/metrobus/base.rb
|
145
|
+
- lib/metrobus/connection.rb
|
146
|
+
- lib/metrobus/departure.rb
|
147
|
+
- lib/metrobus/direction.rb
|
148
|
+
- lib/metrobus/route.rb
|
149
|
+
- lib/metrobus/stop.rb
|
150
|
+
- lib/metrobus/version.rb
|
151
|
+
- metrobus.gemspec
|
152
|
+
homepage: https://github.com/sbower/metrobus
|
153
|
+
licenses:
|
154
|
+
- MIT
|
155
|
+
metadata:
|
156
|
+
yard.run: yri
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ! '>='
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
requirements: []
|
172
|
+
rubyforge_project:
|
173
|
+
rubygems_version: 2.4.5
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: Small Library to wrap the metrotransit.org web services
|
177
|
+
test_files: []
|