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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf278fc1b4b1fb54457bef6ee6a3058495423ec1
4
- data.tar.gz: 7527e81c76a23c6bb14d24c0a3c89faf1ccc026b
3
+ metadata.gz: abc5f8ed69eb1364577bd557f538dfa04d53cb72
4
+ data.tar.gz: 15ad208790e2df9d69a04f50fa6b483da1c3d929
5
5
  SHA512:
6
- metadata.gz: b1ec67b5e70c17c18c1dec41b0ab5dbe006a871b2946f6fa54d74f3588d55446ad25d50e6876904b8732f5055a60749d4fb793c8d0e64431acf4aafcda700592
7
- data.tar.gz: aaacdf66a3759e5f619359594c5928c32d48b21621f40cf71296f28448d7d97cb4edbd32d941b5f35232557176997bb1267a4623cae449cfa834b306074357d5
6
+ metadata.gz: 30f341fbe00ff73925c243f2907ac118168d58e8cfdb123346b8970c9d439f8366fd516c974a0c4ceaf3b079a339827121e8263d4d6863cffff1dd90d2ca84ad
7
+ data.tar.gz: e90a9ceff51ee9e32ea205c0a3e57d323180d47ab5e92880e5e4da1f19dc110b929a1ab36748d6721394c1de317262f1e2bad5a551c8d4905b7c7de8cda203db
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Bubus
2
2
 
3
- TODO: Write a gem description
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
- TODO: Write usage instructions here
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
 
@@ -1,6 +1,7 @@
1
1
  require "bubus/version"
2
2
  require "bubus/client"
3
3
  require "bubus/bus"
4
+ require "bubus/stop"
4
5
 
5
6
  module BuBus
6
7
  end
@@ -1,13 +1,16 @@
1
- class Bus
2
- attr_accessor :call_name, :coordinates, :general_heading, :id, :speed, :lat, :lng
3
-
4
- def initialize(bus_hash)
5
- @call_name = bus_hash["call_name"]
6
- @coordinates = bus_hash["coordinates"]
7
- @general_heading = bus_hash["general_heading"]
8
- @id = bus_hash["id"]
9
- @speed = bus_hash["speed"]
10
- @lat = bus_hash["lat"]
11
- @lng = bus_hash["lng"]
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
@@ -3,35 +3,33 @@ require 'json'
3
3
 
4
4
  module BuBus
5
5
  class Client
6
- BASE_URL = "http://www.bu.edu/bumobile/rpc/bus/livebus.json.php"
7
-
6
+
8
7
  def initialize()
9
- @buses = []
10
8
  end
11
9
 
12
10
  def buses(&block)
13
- res = request
14
- buses = res["ResultSet"]["Result"]
15
- @buses = buses.map do |bus|
16
- Bus.new(bus)
17
- end
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 request
29
- uri = URI(BASE_URL)
30
- res = Net::HTTP.get_response(uri)
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Bubus
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
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-02-13 00:00:00.000000000 Z
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: ''