bus-o-matic 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/LICENSE.txt +24 -0
- data/README.md +155 -0
- data/Rakefile +2 -0
- data/bus-o-matic-0.0.1.gem +0 -0
- data/bus-o-matic-0.0.2.gem +0 -0
- data/bus-o-matic.gemspec +17 -0
- data/lib/bus-o-matic.rb +133 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7a886fce58da346faaf023ea93d7119dc101bce
|
4
|
+
data.tar.gz: b25ace7e55ca30109cc5d65712257139a7928168
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4277dbcc6bb94b238992d5272bbbac69971ea72099f2e440bf9544bd6af46e10d3a02086612cd22362d6500e081868c444a95262a578ddf983d49b6d136bb84f
|
7
|
+
data.tar.gz: 0bf32c7ca5f84195ed5f337b3978ef7dc97bc55606768df7cd461369eb3a5ec7c511f4b63f29375bd1dd2381044eb02ac6a9f7d40ce1bd2c80a6be9ba08ec72b
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Copyright (c) 2015 Matt Cone
|
2
|
+
|
3
|
+
Copyright (c) 2013 fbonetti
|
4
|
+
|
5
|
+
MIT License
|
6
|
+
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
8
|
+
a copy of this software and associated documentation files (the
|
9
|
+
"Software"), to deal in the Software without restriction, including
|
10
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
11
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
+
permit persons to whom the Software is furnished to do so, subject to
|
13
|
+
the following conditions:
|
14
|
+
|
15
|
+
The above copyright notice and this permission notice shall be
|
16
|
+
included in all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
22
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
23
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
24
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
# Bus-o-matic
|
2
|
+
|
3
|
+
Bus-o-matic is a simple Ruby wrapper for the [Pittsburgh Port Authority API]
|
4
|
+
(http://www.portauthority.org/paac/CompanyInfoProjects/DeveloperResources.aspx).
|
5
|
+
This gem allows you to retrieve real-time information about vehicles, routes,
|
6
|
+
stops, and predicted arrival times for buses in Pittsburgh, Pennsylvania.
|
7
|
+
This gem borrows heavily from [cta-api] (https://github.com/fbonetti/cta-api)
|
8
|
+
by [Frank Bonetti] (https://github.com/fbonetti).
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'bus-o-matic'
|
16
|
+
```
|
17
|
+
|
18
|
+
## Setup
|
19
|
+
|
20
|
+
Before using Bus-o-matic, you'll need to request an API key from the [Port
|
21
|
+
Authority] (http://www.portauthority.org/paac/CompanyInfoProjects/DeveloperResources.aspx).
|
22
|
+
Require the gem and add your Port Authority API key. This can be put in an initializer.
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'bus-o-matic'
|
26
|
+
|
27
|
+
key = "xxxxxxxxxxxxxxxxxxxx"
|
28
|
+
PIT::Busomatic.key = key
|
29
|
+
```
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
The following examples illustrate how you can use Bus-o-matic.
|
34
|
+
|
35
|
+
### Routes and Stops
|
36
|
+
|
37
|
+
Bus-o-matic can list all of the routes availabe in the Port Authority API.
|
38
|
+
You can also get the directions for a particular route, and a list all of
|
39
|
+
the stops on a route.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
|
43
|
+
# Retrieve a list of all available routes
|
44
|
+
PIT::Busomatic.routes
|
45
|
+
|
46
|
+
# Retrieve the available directions for the specified route (INBOUND, OUTBOUND, etc.)
|
47
|
+
PIT::Busomatic.directions :rt => 16
|
48
|
+
|
49
|
+
# Retrieve the stops for Route 16 heading Inbound
|
50
|
+
PIT::Busomatic.stops :rt => 16, :dir => :INBOUND
|
51
|
+
```
|
52
|
+
|
53
|
+
Note that the available directions (INBOUND, etc.) appear to be case sensitive.
|
54
|
+
|
55
|
+
### Patterns
|
56
|
+
|
57
|
+
Bus-o-matic can retrieve a set of geo-positional points for a route, something
|
58
|
+
known as a "pattern." Patterns can be used to outline routes on maps.
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
# Retrieve the pattern for Route 16
|
62
|
+
PIT::Busomatic.patterns :rt => 16
|
63
|
+
```
|
64
|
+
|
65
|
+
### Vehicles
|
66
|
+
|
67
|
+
Bus-o-matic can find all of the vehicles that are currently active on a route,
|
68
|
+
or retrieve information about a specific vehicle. The first step is finding
|
69
|
+
the active vehicles on a route.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
# Returns an array of vehicles that are active on Route 16.
|
73
|
+
PIT::Busomatic.vehicles :rt => 16
|
74
|
+
```
|
75
|
+
|
76
|
+
You can retrieve information for vehicles on more than one route. Up to 10
|
77
|
+
routes can be specified at once.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
# Returns an array of vehicles that are active on Routes 13, 16, and 17.
|
81
|
+
PIT::Busomatic.vehicles :rt => ["16","17","13"]
|
82
|
+
```
|
83
|
+
|
84
|
+
You can also find information about one or more vehicles that are currently
|
85
|
+
active. Up to 10 vehicle IDs can be specified at once.
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
# Returns information about a specific vehicle.
|
89
|
+
PIT::Busomatic.vehicles :vid => 6013
|
90
|
+
|
91
|
+
# Returns information about multiple vehicles.
|
92
|
+
PIT::Busomatic.vehicles :vid => ["6013","6001"]
|
93
|
+
```
|
94
|
+
|
95
|
+
Note that you cannot combine both `rt` and `vid` parameters in a single request.
|
96
|
+
|
97
|
+
### Predicted Arrival Times
|
98
|
+
|
99
|
+
Bus-o-matic can return predicted arrival times for one or more buses. Up to 10
|
100
|
+
vehicle IDs can be specified at once. Note that you cannot combine both `vid`
|
101
|
+
and `stpid` parameters in a single request.
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
# Returns predictions for a single vehicle.
|
105
|
+
PIT::Busomatic.predictions :vid => 5629
|
106
|
+
|
107
|
+
# Returns predictions for multiple vehicles.
|
108
|
+
PIT::Busomatic.predictions :vid => ["5629","5604"]
|
109
|
+
```
|
110
|
+
|
111
|
+
You can also retrieve predictions for one or more stops. Up to 10 stop IDs can
|
112
|
+
be specified at once. You can combine the `stpid` and `rt` parameters, as shown
|
113
|
+
below.
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
|
117
|
+
# Returns predictions for all buses on all applicable routes for single stop.
|
118
|
+
PIT::Busomatic.predictions :stpid => 1326
|
119
|
+
|
120
|
+
# Returns predictions for multiple stops.
|
121
|
+
PIT::Busomatic.predictions :stpid => ["1326","18320","18563"]
|
122
|
+
|
123
|
+
# Returns predictions for all buses on Route 16 for a single stop
|
124
|
+
PIT::Busomatic.predictions :stpid => 1326, :rt => 16
|
125
|
+
|
126
|
+
# Returns predictions for buses on Routes 13, 16, and 17 for Stop 1326.
|
127
|
+
PIT::Busomatic.predictions :stpid => 1326, :rt => ["13","16","17"]
|
128
|
+
```
|
129
|
+
|
130
|
+
### System Time
|
131
|
+
|
132
|
+
Returns the official Port Authority API system time.
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
PIT::Busomatic.time
|
136
|
+
```
|
137
|
+
|
138
|
+
|
139
|
+
## Contributing
|
140
|
+
|
141
|
+
This is my first Ruby gem, so I'd appreciate you reporting issues or creating
|
142
|
+
pull requests.
|
143
|
+
|
144
|
+
1. Fork it
|
145
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
146
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
147
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
148
|
+
5. Create a new Pull Request
|
149
|
+
|
150
|
+
|
151
|
+
## License
|
152
|
+
|
153
|
+
Copyright (c) 2015 Matt Cone and 2013 fbonetti.
|
154
|
+
|
155
|
+
The MIT License (MIT). See the LICENSE.txt file for details.
|
data/Rakefile
ADDED
Binary file
|
Binary file
|
data/bus-o-matic.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
|
3
|
+
s.name = "bus-o-matic"
|
4
|
+
s.version = "0.0.3"
|
5
|
+
s.authors = ["Matt Cone"]
|
6
|
+
s.email = ["matt@macinstruct.com"]
|
7
|
+
s.summary = %q{A wrapper for the Pittsburgh Port Authority TrueTime Bus API}
|
8
|
+
s.description = %q{A wrapper for the Pittsburgh Port Authority TrueTime Bus API}
|
9
|
+
s.homepage = "https://github.com/mattcone/bus-o-matic"
|
10
|
+
s.license = "MIT"
|
11
|
+
s.platform = Gem::Platform::RUBY
|
12
|
+
|
13
|
+
s.require_paths = ['lib']
|
14
|
+
s.files = Dir.glob("**/*").reject { |x| File.directory?(x) }
|
15
|
+
s.add_dependency "httparty", '~> 0.10.2'
|
16
|
+
s.add_dependency "hashie", '~> 2.0'
|
17
|
+
end
|
data/lib/bus-o-matic.rb
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'hashie'
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
class Array
|
6
|
+
def self.wrap(object)
|
7
|
+
if object.nil?
|
8
|
+
[]
|
9
|
+
elsif object.respond_to?(:to_ary)
|
10
|
+
object.to_ary || [object]
|
11
|
+
else
|
12
|
+
[object]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module PIT
|
18
|
+
class Busomatic
|
19
|
+
include HTTParty
|
20
|
+
base_uri 'http://realtime.portauthority.org/bustime/api/v2/'
|
21
|
+
format :xml
|
22
|
+
@@key = nil
|
23
|
+
|
24
|
+
def self.time(options={})
|
25
|
+
options.merge!({
|
26
|
+
:key => @@key
|
27
|
+
})
|
28
|
+
response = get("/gettime", :query => options)['bustime_response']
|
29
|
+
check_for_errors response['error']
|
30
|
+
|
31
|
+
Time.parse response['tm']
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.vehicles(options={})
|
35
|
+
options.merge!({
|
36
|
+
:key => @@key
|
37
|
+
})
|
38
|
+
options[:vid] = options[:vid].join(',') if options[:vid].kind_of?(Array)
|
39
|
+
options[:rt] = options[:rt].join(',') if options[:rt].kind_of?(Array)
|
40
|
+
|
41
|
+
response = get("/getvehicles", :query => options)['bustime_response']
|
42
|
+
check_for_errors response['error']
|
43
|
+
|
44
|
+
results = Array.wrap response['vehicle']
|
45
|
+
results.map { |result| Hashie::Mash.new result } unless results.nil?
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.routes(options={})
|
49
|
+
options.merge!({
|
50
|
+
:key => @@key
|
51
|
+
})
|
52
|
+
response = get("/getroutes", :query => options)['bustime_response']
|
53
|
+
check_for_errors response['error']
|
54
|
+
|
55
|
+
results = Array.wrap response['route']
|
56
|
+
Hash[ results.map { |result| [result['rt'], result['rtnm']] } ] unless results.nil?
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.directions(options={})
|
60
|
+
options.merge!({
|
61
|
+
:key => @@key
|
62
|
+
})
|
63
|
+
response = get("/getdirections", :query => options)['bustime_response']
|
64
|
+
check_for_errors response['error']
|
65
|
+
|
66
|
+
results = Array.wrap response['dir']
|
67
|
+
results.map { |direction| direction.split(/ /)[0] } unless results.nil?
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.stops(options={})
|
71
|
+
options.merge!({
|
72
|
+
:key => @@key
|
73
|
+
})
|
74
|
+
response = get("/getstops", :query => options)['bustime_response']
|
75
|
+
check_for_errors response['error']
|
76
|
+
|
77
|
+
results = Array.wrap response['stop']
|
78
|
+
results.map { |result| Hashie::Mash.new result } unless results.nil?
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.patterns(options={})
|
82
|
+
options.merge!({
|
83
|
+
:key => @@key
|
84
|
+
})
|
85
|
+
options['pid'] = options['pid'].join(',') if options['pid'].kind_of?(Array)
|
86
|
+
|
87
|
+
response = get("/getpatterns", :query => options)['bustime_response']
|
88
|
+
check_for_errors response['error']
|
89
|
+
|
90
|
+
results = Array.wrap response['ptr']
|
91
|
+
results.map { |result| Hashie::Mash.new result } unless results.nil?
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.predictions(options={})
|
95
|
+
options.merge!({
|
96
|
+
:key => @@key
|
97
|
+
})
|
98
|
+
options[:stpid] = options[:stpid].join(',') if options[:stpid].kind_of?(Array)
|
99
|
+
options[:rt] = options[:rt].join(',') if options[:rt].kind_of?(Array)
|
100
|
+
options[:vid] = options[:vid].join(',') if options[:vid].kind_of?(Array)
|
101
|
+
|
102
|
+
response = get("/getpredictions", :query => options)['bustime_response']
|
103
|
+
check_for_errors response['error']
|
104
|
+
|
105
|
+
results = Array.wrap response['prd']
|
106
|
+
results.map { |result| Hashie::Mash.new result } unless results.nil?
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.bulletins(options={})
|
110
|
+
options.merge!({
|
111
|
+
:key => @@key
|
112
|
+
})
|
113
|
+
options['rt'] = options['rt'].join(',') if options['rt'].kind_of?(Array)
|
114
|
+
options['stpid'] = options['stpid'].join(',') if options['stpid'].kind_of?(Array)
|
115
|
+
|
116
|
+
response = get("/getservicebulletins", :query => options)['bustime_response']
|
117
|
+
check_for_errors response['error']
|
118
|
+
|
119
|
+
results = Array.wrap response['sb']
|
120
|
+
results.map { |result| Hashie::Mash.new result } unless results.nil?
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.key=(key)
|
124
|
+
@@key = key
|
125
|
+
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def self.check_for_errors(error)
|
130
|
+
puts "API ERROR: #{error['msg']}" if error
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bus-o-matic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Cone
|
@@ -44,7 +44,15 @@ email:
|
|
44
44
|
executables: []
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
|
-
files:
|
47
|
+
files:
|
48
|
+
- Gemfile
|
49
|
+
- LICENSE.txt
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- bus-o-matic-0.0.1.gem
|
53
|
+
- bus-o-matic-0.0.2.gem
|
54
|
+
- bus-o-matic.gemspec
|
55
|
+
- lib/bus-o-matic.rb
|
48
56
|
homepage: https://github.com/mattcone/bus-o-matic
|
49
57
|
licenses:
|
50
58
|
- MIT
|