bubus 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -2
- data/lib/bubus.rb +1 -0
- data/lib/bubus/bus.rb +14 -11
- data/lib/bubus/client.rb +19 -21
- data/lib/bubus/stop.rb +15 -0
- data/lib/bubus/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abc5f8ed69eb1364577bd557f538dfa04d53cb72
|
4
|
+
data.tar.gz: 15ad208790e2df9d69a04f50fa6b483da1c3d929
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30f341fbe00ff73925c243f2907ac118168d58e8cfdb123346b8970c9d439f8366fd516c974a0c4ceaf3b079a339827121e8263d4d6863cffff1dd90d2ca84ad
|
7
|
+
data.tar.gz: e90a9ceff51ee9e32ea205c0a3e57d323180d47ab5e92880e5e4da1f19dc110b929a1ab36748d6721394c1de317262f1e2bad5a551c8d4905b7c7de8cda203db
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Bubus
|
2
2
|
|
3
|
-
|
3
|
+
API Client for playing with the BU Bus API. The BU Bus API is an internal, undocumented API Boston University uses to show students bus locations. It requires no authentication making it simple for anyone to work with. This gem handles the HTTP requests and abstracts the responses into ruby objects, making it very simple to work with.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -20,7 +20,29 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
$ client = BuBus::Client.new
|
24
|
+
|
25
|
+
$ client.buses {|bus| ... } # returns array of Bus objects, takes optional block
|
26
|
+
$ client.stops {|stop| ... } # returns array of Stop objects, takes optional block
|
27
|
+
|
28
|
+
###Bus
|
29
|
+
Bus object to abstract bus data
|
30
|
+
call_name: id
|
31
|
+
coordinates: "lng, lat"
|
32
|
+
general_heading: degrees clockwise from North
|
33
|
+
id: another id
|
34
|
+
speed: measuered in meters / hour
|
35
|
+
lat: latitude of bus's current position
|
36
|
+
lon: longitude of bus's current position
|
37
|
+
|
38
|
+
###Stop
|
39
|
+
Stop object to abstract bus stop data
|
40
|
+
id: id
|
41
|
+
name: name of bus stop
|
42
|
+
description: address of bus stop
|
43
|
+
lat: latitude of bus stop
|
44
|
+
lon: longitude of bus stop
|
45
|
+
times - array of estimated arrival times at bus stop
|
24
46
|
|
25
47
|
## Contributing
|
26
48
|
|
data/lib/bubus.rb
CHANGED
data/lib/bubus/bus.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
module BuBus
|
2
|
+
class Bus
|
3
|
+
attr_accessor :call_name, :coordinates, :general_heading, :id, :speed, :lat, :lng
|
4
|
+
URL = "http://www.bu.edu/bumobile/rpc/bus/livebus.json.php"
|
5
|
+
|
6
|
+
def initialize(bus_hash)
|
7
|
+
@call_name = bus_hash["call_name"]
|
8
|
+
@coordinates = bus_hash["coordinates"]
|
9
|
+
@general_heading = bus_hash["general_heading"]
|
10
|
+
@id = bus_hash["id"]
|
11
|
+
@speed = bus_hash["speed"]
|
12
|
+
@lat = bus_hash["lat"]
|
13
|
+
@lng = bus_hash["lng"]
|
14
|
+
end
|
12
15
|
end
|
13
16
|
end
|
data/lib/bubus/client.rb
CHANGED
@@ -3,35 +3,33 @@ require 'json'
|
|
3
3
|
|
4
4
|
module BuBus
|
5
5
|
class Client
|
6
|
-
|
7
|
-
|
6
|
+
|
8
7
|
def initialize()
|
9
|
-
@buses = []
|
10
8
|
end
|
11
9
|
|
12
10
|
def buses(&block)
|
13
|
-
|
14
|
-
buses =
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
if block_given?
|
20
|
-
@buses.map do |bus|
|
21
|
-
block.call(bus)
|
22
|
-
end
|
23
|
-
else
|
24
|
-
@buses
|
25
|
-
end
|
11
|
+
buses = request(BuBus::Bus::URL)["ResultSet"]["Result"]
|
12
|
+
buses = buses.map {|bus| Bus.new(bus) }
|
13
|
+
|
14
|
+
return buses unless block_given?
|
15
|
+
buses.map {|bus| block.call(bus)}
|
26
16
|
end
|
27
|
-
|
28
|
-
def
|
29
|
-
|
30
|
-
|
17
|
+
|
18
|
+
def stops(&block)
|
19
|
+
stops = request(BuBus::Stop::URL)["ResultSet"]["Result"]
|
20
|
+
stops = stops.map {|stop| Stop.new(stop)}
|
21
|
+
|
22
|
+
return stops unless block_given?
|
23
|
+
stops.map {|stop| block.call(stop)}
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def request(url)
|
28
|
+
res = Net::HTTP.get_response(URI(url))
|
31
29
|
if(res.is_a?(Net::HTTPOK))
|
32
30
|
res = JSON.parse(res.body)
|
33
31
|
else
|
34
|
-
raise 'Error'
|
32
|
+
raise 'Error server responded with: #{res.code}'
|
35
33
|
end
|
36
34
|
end
|
37
35
|
end
|
data/lib/bubus/stop.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module BuBus
|
2
|
+
class Stop
|
3
|
+
attr_accessor :id, :name, :description, :lat, :lon
|
4
|
+
URL = "http://www.bu.edu/bumobile/rpc/bus/stops.json.php?service_id=fall"
|
5
|
+
|
6
|
+
def initialize(res)
|
7
|
+
@id = res['stop_id']
|
8
|
+
@name = res['stop_name']
|
9
|
+
@description = res['stop_desc']
|
10
|
+
@lat = res['stop_lat']
|
11
|
+
@lon = res['stop_long']
|
12
|
+
@times = res['times']
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/bubus/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bubus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Wheeler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- lib/bubus.rb
|
108
108
|
- lib/bubus/bus.rb
|
109
109
|
- lib/bubus/client.rb
|
110
|
+
- lib/bubus/stop.rb
|
110
111
|
- lib/bubus/version.rb
|
111
112
|
- spec/spec_helper.rb
|
112
113
|
homepage: ''
|