Class: CTA::BusTracker
Constant Summary collapse
- @@key =
nil
Class Method Summary collapse
- .bulletins(options = {}) ⇒ Object
- .directions(options = {}) ⇒ Object
- .key ⇒ Object
- .key=(key) ⇒ Object
- .patterns(options = {}) ⇒ Object
- .predictions(options = {}) ⇒ Object
- .routes(options = {}) ⇒ Object
- .stops(options = {}) ⇒ Object
- .time(options = {}) ⇒ Object
- .vehicles(options = {}) ⇒ Object
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(={}) .merge!({ :key => @@key }) ['rt'] = ['rt'].join(',') if ['rt'].kind_of?(Array) ['stpid'] = ['stpid'].join(',') if ['stpid'].kind_of?(Array) response = get("/getservicebulletins", :query => )['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(={}) .merge!({ :key => @@key }) response = get("/getdirections", :query => )['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 |
.key ⇒ Object
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(={}) .merge!({ :key => @@key }) ['pid'] = ['pid'].join(',') if ['pid'].kind_of?(Array) response = get("/getpatterns", :query => )['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(={}) .merge!({ :key => @@key }) ['stpid'] = ['stpid'].join(',') if ['stpid'].kind_of?(Array) ['rt'] = ['rt'].join(',') if ['rt'].kind_of?(Array) ['vid'] = ['vid'].join(',') if ['vid'].kind_of?(Array) response = get("/getpredictions", :query => )['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(={}) .merge!({ :key => @@key }) response = get("/getroutes", :query => )['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(={}) .merge!({ :key => @@key }) [:dir] = "#{[:dir]} bound" if [:dir].kind_of?(Symbol) response = get("/getstops", :query => )['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(={}) .merge!({ :key => @@key }) response = get("/gettime", :query => )['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(={}) .merge!({ :key => @@key }) [:vid] = [:vid].join(',') if [:vid].kind_of?(Array) [:rt] = [:rt].join(',') if [:rt].kind_of?(Array) response = get("/getvehicles", :query => )['bustime_response'] check_for_errors response['error'] results = Array.wrap response['vehicle'] results.map { |result| Hashie::Mash.new result } unless results.nil? end |