Class: CTA::API::Response
- Inherits:
-
Object
- Object
- CTA::API::Response
- Defined in:
- lib/cta_redux/api/api_response.rb
Direct Known Subclasses
BusTracker::DirectionsResponse, BusTracker::PatternsResponse, BusTracker::PredictionsResponse, BusTracker::RoutesResponse, BusTracker::ServiceBulletinsResponse, BusTracker::StopsResponse, BusTracker::TimeResponse, BusTracker::VehiclesResponse, CustomerAlerts::AlertsResponse, CustomerAlerts::RouteStatusResponse, TrainTracker::ArrivalsResponse, TrainTracker::FollowResponse, TrainTracker::PositionsResponse
Instance Attribute Summary collapse
-
#error ⇒ CTA::API::Error
readonly
Error information from the API.
-
#parsed_body ⇒ Hash?
readonly
Parsed XML from the API.
-
#raw_body ⇒ String?
readonly
Raw XML from the API.
-
#timestamp ⇒ DateTime
readonly
Timestamp from the API server, if available.
Instance Method Summary collapse
-
#initialize(parsed_body, raw_body, debug) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(parsed_body, raw_body, debug) ⇒ Response
Returns a new instance of Response.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cta_redux/api/api_response.rb', line 29 def initialize(parsed_body, raw_body, debug) if parsed_body["bustime_response"] = DateTime.now if parsed_body["bustime_response"].has_key?("error") @error = Error.new({ :message => parsed_body["bustime_response"]["error"]["msg"] }) else @error = Error.new end elsif parsed_body["ctatt"] = DateTime.parse(parsed_body["ctatt"]["tmst"]) @error = Error.new({ :code => parsed_body["ctatt"]["errCd"], :message => parsed_body["ctatt"]["errNm"] }) else # CustomerAlert key = parsed_body["CTARoutes"] ? "CTARoutes" : "CTAAlerts" code = Array.wrap(parsed_body[key]["ErrorCode"]).flatten.compact.uniq.first msg = Array.wrap(parsed_body[key]["ErrorMessage"]).flatten.compact.uniq.first = DateTime.parse(parsed_body[key]["TimeStamp"]) @error = Error.new({ :code => code, :message => msg }) end if debug @parsed_body = parsed_body @raw_body = raw_body end end |
Instance Attribute Details
#error ⇒ CTA::API::Error (readonly)
Returns Error information from the API.
21 22 23 |
# File 'lib/cta_redux/api/api_response.rb', line 21 def error @error end |
#parsed_body ⇒ Hash? (readonly)
Returns Parsed XML from the API. Only set when BusTracker.debug or TrainTracker.debug is true.
27 28 29 |
# File 'lib/cta_redux/api/api_response.rb', line 27 def parsed_body @parsed_body end |
#raw_body ⇒ String? (readonly)
Returns Raw XML from the API. Only set when BusTracker.debug or TrainTracker.debug is true.
24 25 26 |
# File 'lib/cta_redux/api/api_response.rb', line 24 def raw_body @raw_body end |
#timestamp ⇒ DateTime (readonly)
Returns Timestamp from the API server, if available. Defaults to DateTime.now if unavailable.
18 19 20 |
# File 'lib/cta_redux/api/api_response.rb', line 18 def end |