Class: CTA::BusTracker

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/cta-api.rb

Constant Summary collapse

@@key =
nil

Class Method Summary collapse

Class Method Details

.bulletins(options = {}) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/cta-api.rb', line 116

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



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/cta-api.rb', line 63

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].downcase.to_sym } unless results.nil?
end

.keyObject



130
131
132
# File 'lib/cta-api.rb', line 130

def self.key
  @@key
end

.key=(key) ⇒ Object



134
135
136
# File 'lib/cta-api.rb', line 134

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

.patterns(options = {}) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/cta-api.rb', line 88

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



101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/cta-api.rb', line 101

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



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cta-api.rb', line 51

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



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/cta-api.rb', line 75

def self.stops(options={})
  options.merge!({
    :key => @@key
  })
  options[:dir] = "#{options[:dir]} bound" if options[:dir].kind_of?(Symbol)

  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



26
27
28
29
30
31
32
33
34
35
# File 'lib/cta-api.rb', line 26

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



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cta-api.rb', line 37

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