Class: CTA::CustomerAlerts
- Inherits:
-
Object
- Object
- CTA::CustomerAlerts
- Defined in:
- lib/cta_redux/customer_alerts.rb,
lib/cta_redux/api/customer_alerts.rb,
lib/cta_redux/faraday_middleware/customer_alerts_parser.rb
Defined Under Namespace
Classes: Alert, AlertsResponse, Parser, RouteStatus, RouteStatusResponse
Class Method Summary collapse
-
.alerts!(options = {}) ⇒ CTA::CustomerAlerts::AlertsResponse
Returns alerts for given routes or stations.
-
.cache ⇒ Object
Returns the underlying cache object caching responses (if we’re actually caching responses).
-
.cache=(cache) ⇒ Object
Sets the underlying cache object caching responses.
-
.cache_responses ⇒ true, false
Returns whether or not cta_redux is caching responses.
-
.cache_responses=(should_cache) ⇒ Object
Sets whether or not cta_redux is caching responses.
-
.connection ⇒ Object
Returns the connection object we use to talk to the CustomerAlerts API.
-
.debug ⇒ Object
Returns the debug status of the API.
-
.debug=(debug) ⇒ Object
Sets the debug status of the API.
-
.status!(options = {}) ⇒ CTA::CustomerAlerts::RouteStatusResponse
Returns an overview of system status.
Class Method Details
.alerts!(options = {}) ⇒ CTA::CustomerAlerts::AlertsResponse
Returns alerts for given routes or stations
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/cta_redux/customer_alerts.rb', line 52 def self.alerts!( = {}) allowed_keys = [:active, :accessibility, :planned, :routes, :station, :recent_days, :before] if .keys.any? { |k| !allowed_keys.include?(k) } raise "Illegal argument!" end params = {} params.merge!({ :activeonly => [:active] }) if [:active] params.merge!({ :accessibility => [:accessiblity] }) if [:accessibility] params.merge!({ :planned => [:planned] }) if [:planned] routes = Array.wrap([:routes]).flatten.compact.uniq stations = Array.wrap([:station]).flatten.compact.uniq if stations.size > 1 raise "Can only specify one station!" end if routes.any? && stations.any? raise "Cannot use route and station together!" end if [:recent_days] && [:before] raise "Cannot use recent_days and before together!" end params.merge!({ :stationid => stations.first }) if stations.any? params.merge!({ :routeid => routes.join(',') }) if routes.any? params.merge!({ :recentdays => [:recent_days] }) if [:recent_days] params.merge!({ :bystartdate => [:before] }) if [:before] connection.get('alerts.aspx', params) end |
.cache ⇒ Object
Returns the underlying cache object caching responses (if we’re actually caching responses)
115 116 117 118 119 120 121 122 |
# File 'lib/cta_redux/customer_alerts.rb', line 115 def self.cache if self.cache_responses # This is ugly @cache || self.connection.builder.handlers.find { |x| x == FaradayMiddleware::Caching }.instance_variable_get(:@args).first else nil end end |
.cache=(cache) ⇒ Object
Setting the cache object resets the connection. If you’re using the default SimpleCache strategy (built-in 60 second caching), then it will also clear the cache.
Sets the underlying cache object caching responses. Any object can be used that responds to #read, #write, and #fetch
128 129 130 131 |
# File 'lib/cta_redux/customer_alerts.rb', line 128 def self.cache=(cache) @cache = cache @connection = nil end |
.cache_responses ⇒ true, false
Returns whether or not cta_redux is caching responses
102 103 104 |
# File 'lib/cta_redux/customer_alerts.rb', line 102 def self.cache_responses @cache_responses end |
.cache_responses=(should_cache) ⇒ Object
Sets whether or not cta_redux is caching responses
108 109 110 111 |
# File 'lib/cta_redux/customer_alerts.rb', line 108 def self.cache_responses=(should_cache) @cache_responses = should_cache @connection = nil end |
.connection ⇒ Object
Returns the connection object we use to talk to the CustomerAlerts API
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/cta_redux/customer_alerts.rb', line 6 def self.connection @connection ||= Faraday.new do |faraday| faraday.url_prefix = 'http://www.transitchicago.com/api/1.0/' faraday.use CTA::CustomerAlerts::Parser, !!@debug if @cache_responses faraday.response :caching, (@cache || SimpleCache.new(Hash.new)) end faraday.adapter Faraday.default_adapter end end |
.debug ⇒ Object
Returns the debug status of the API. When in debug mode, all API responses will additionally return the parsed XML tree, and the original XML for inspection
88 89 90 |
# File 'lib/cta_redux/customer_alerts.rb', line 88 def self.debug !!@debug end |
.debug=(debug) ⇒ Object
Sets the debug status of the API. When in debug mode, all API responses will additionally return the parsed XML tree, and the original XML for inspection
95 96 97 98 |
# File 'lib/cta_redux/customer_alerts.rb', line 95 def self.debug=(debug) @debug = debug @connection = nil end |
.status!(options = {}) ⇒ CTA::CustomerAlerts::RouteStatusResponse
Returns an overview of system status.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cta_redux/customer_alerts.rb', line 24 def self.status!( = {}) allowed_keys = [:routes, :station] if .keys.any? { |k| !allowed_keys.include?(k) } raise "Illegal argument!" end routes = Array.wrap([:routes]).flatten.compact.uniq.join(',') stations = Array.wrap([:station]).flatten.compact.uniq if stations.size > 1 raise "Can only specify one station!" end connection.get('routes.aspx', { :type => [:type], :routeid => routes, :stationid => stations.first }) end |