septa 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/septa.rb +1 -1
  2. data/lib/septa/bus.rb +30 -9
  3. data/lib/septa/train.rb +12 -0
  4. metadata +20 -43
@@ -1,7 +1,7 @@
1
+ require "septa/train"
1
2
  require "septa/bus"
2
3
 
3
4
  module Septa
4
5
  VERSION = '1.0.0'
5
- extend Bus
6
6
  end
7
7
 
@@ -2,17 +2,38 @@ require 'resourceful'
2
2
  require 'json'
3
3
 
4
4
  module Septa
5
- module Bus
6
- def get_bus_data(bus_number)
7
- septa_url = 'http://www3.septa.org/transitview/bus_route_data/'+bus_number.to_s
8
- resp = Resourceful.get(septa_url)
9
- JSON.parse(resp.body)
5
+ class Bus
6
+ attr_accessor :bus_number
7
+ def initialize(bus_number)
8
+ @bus_number = bus_number
9
+ end
10
+
11
+ def locations
12
+ locations = {}
13
+ loc = self.bus_locations()
14
+ unless loc.nil?
15
+ loc.each do |l|
16
+ locations[l['VehicleID']] = [l['lat'].to_f, l['lng'].to_f]
17
+ end
18
+ end
19
+ locations
10
20
  end
11
21
 
12
- def next_to_arrive(city1, city2)
13
- septa_url = "http://www3.septa.org/api/nta/"
14
- resp = Resourceful.get("#{septa_url}#{city1}/#{city2}")
15
- JSON.parse(resp.body)
22
+ def format_locations(locations)
23
+ location = []
24
+ locations.each do |loc|
25
+ loc['lat'] = loc['lat'].to_f
26
+ loc['lng'] = loc['lng'].to_f
27
+ end
28
+ end
29
+
30
+ def bus_locations
31
+ septa_url = "http://www3.septa.org/transitview/bus_route_data/#{@bus_number.to_s}"
32
+ resp = Resourceful.get(septa_url)
33
+ unless resp.body.downcase.include? 'invalid route'
34
+ locations = JSON.parse(resp.body)
35
+ return self.format_locations(locations['bus'])
36
+ end
16
37
  end
17
38
  end
18
39
  end
@@ -0,0 +1,12 @@
1
+ require 'resourceful'
2
+ require 'json'
3
+
4
+ module Septa
5
+ class Train
6
+ def self.next_to_arrive(city1, city2)
7
+ septa_url = "http://www3.septa.org/api/nta/"
8
+ resp = Resourceful.get("#{septa_url}#{city1}/#{city2}")
9
+ JSON.parse(resp.body)
10
+ end
11
+ end
12
+ end
metadata CHANGED
@@ -1,71 +1,48 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: septa
3
- version: !ruby/object:Gem::Version
4
- hash: 21
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 1
10
- version: 1.0.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Joanne Cheng
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-09-12 00:00:00 -06:00
19
- default_executable:
12
+ date: 2012-10-16 00:00:00.000000000 Z
20
13
  dependencies: []
21
-
22
- description: An easier way to access SEPTA (Southeastern Pennsylvania Transit Authority) data.
23
- email:
14
+ description: Ruby wrapper for the septa api
15
+ email:
24
16
  - chengjoanne2@gmail.com
25
17
  executables: []
26
-
27
18
  extensions: []
28
-
29
19
  extra_rdoc_files: []
30
-
31
- files:
20
+ files:
32
21
  - lib/septa.rb
33
22
  - lib/septa/bus.rb
34
- has_rdoc: true
23
+ - lib/septa/train.rb
35
24
  homepage: http://github.com/joannecheng/septa-ruby
36
25
  licenses: []
37
-
38
26
  post_install_message:
39
27
  rdoc_options: []
40
-
41
- require_paths:
28
+ require_paths:
42
29
  - lib
43
- required_ruby_version: !ruby/object:Gem::Requirement
30
+ required_ruby_version: !ruby/object:Gem::Requirement
44
31
  none: false
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- hash: 3
49
- segments:
50
- - 0
51
- version: "0"
52
- required_rubygems_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
37
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 23
58
- segments:
59
- - 1
60
- - 3
61
- - 6
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
62
41
  version: 1.3.6
63
42
  requirements: []
64
-
65
43
  rubyforge_project: septa
66
- rubygems_version: 1.6.2
44
+ rubygems_version: 1.8.24
67
45
  signing_key:
68
46
  specification_version: 3
69
47
  summary: Ruby wrapper for the septa api
70
48
  test_files: []
71
-