Class: PIT::Busomatic

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/bus-o-matic.rb

Constant Summary collapse

@@key =
nil

Class Method Summary collapse

Class Method Details

.bulletins(options = {}) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/bus-o-matic.rb', line 109

def self.bulletins(options={})
  options.merge!({
    :key => @@key
  })
  options[:rt] = options[:rt].join(',') if options[:rt].kind_of?(Array)
  options[:stpid] = options[:stpid].join(',') if options[:stpid].kind_of?(Array)

  response = get("/getservicebulletins", :query => options)['bustime_response']
  check_for_errors response['error']

  results = Array.wrap response['sb']
  results.map { |result| Hashie::Mash.new result } unless results.nil?
end

.directions(options = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/bus-o-matic.rb', line 59

def self.directions(options={})
  options.merge!({
    :key => @@key
  })
  response = get("/getdirections", :query => options)['bustime_response']
  check_for_errors response['error']

  results = Array.wrap response['dir']
  results.map { |direction| direction.split(/ /)[0] } unless results.nil?
end

.key=(key) ⇒ Object



123
124
125
# File 'lib/bus-o-matic.rb', line 123

def self.key=(key)
  @@key = key
end

.patterns(options = {}) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/bus-o-matic.rb', line 81

def self.patterns(options={})
  options.merge!({
    :key => @@key
  })
  options[:pid] = options[:pid].join(',') if options[:pid].kind_of?(Array)

  response = get("/getpatterns", :query => options)['bustime_response']
  check_for_errors response['error']

  results = Array.wrap response['ptr']
  results.map { |result| Hashie::Mash.new result } unless results.nil?
end

.predictions(options = {}) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/bus-o-matic.rb', line 94

def self.predictions(options={})
  options.merge!({
    :key => @@key
  })
  options[:stpid] = options[:stpid].join(',') if options[:stpid].kind_of?(Array)
  options[:rt] = options[:rt].join(',') if options[:rt].kind_of?(Array)
  options[:vid] = options[:vid].join(',') if options[:vid].kind_of?(Array)

  response = get("/getpredictions", :query => options)['bustime_response']
  check_for_errors response['error']

  results = Array.wrap response['prd']
  results.map { |result| Hashie::Mash.new result } unless results.nil?
end

.routes(options = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/bus-o-matic.rb', line 48

def self.routes(options={})
  options.merge!({
    :key => @@key
  })
  response = get("/getroutes", :query => options)['bustime_response']
  check_for_errors response['error']

  results = Array.wrap response['route']
  Hash[ results.map { |result| [result['rt'], result['rtnm']] } ] unless results.nil?
end

.stops(options = {}) ⇒ Object



70
71
72
73
74
75
76
77
78
79
# File 'lib/bus-o-matic.rb', line 70

def self.stops(options={})
  options.merge!({
    :key => @@key
  })
  response = get("/getstops", :query => options)['bustime_response']
  check_for_errors response['error']

  results = Array.wrap response['stop']
  results.map { |result| Hashie::Mash.new result } unless results.nil?
end

.time(options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/bus-o-matic.rb', line 24

def self.time(options={})
  options.merge!({
    :key => @@key
  })
  response = get("/gettime", :query => options)['bustime_response']
  check_for_errors response['error']

  Time.parse response['tm']
end

.vehicles(options = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bus-o-matic.rb', line 34

def self.vehicles(options={})
  options.merge!({
    :key => @@key
  })
  options[:vid] = options[:vid].join(',') if options[:vid].kind_of?(Array)
  options[:rt] = options[:rt].join(',') if options[:rt].kind_of?(Array)

  response = get("/getvehicles", :query => options)['bustime_response']
  check_for_errors response['error']

  results = Array.wrap response['vehicle']
  results.map { |result| Hashie::Mash.new result } unless results.nil?
end