Class: CTA::API::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/cta_redux/api/api_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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"]
    @timestamp = 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"]
    @timestamp = 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
    @timestamp = 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

#errorCTA::API::Error (readonly)

Returns Error information from the API.

Returns:



21
22
23
# File 'lib/cta_redux/api/api_response.rb', line 21

def error
  @error
end

#parsed_bodyHash? (readonly)

Returns Parsed XML from the API. Only set when BusTracker.debug or TrainTracker.debug is true.

Returns:



27
28
29
# File 'lib/cta_redux/api/api_response.rb', line 27

def parsed_body
  @parsed_body
end

#raw_bodyString? (readonly)

Returns Raw XML from the API. Only set when BusTracker.debug or TrainTracker.debug is true.

Returns:



24
25
26
# File 'lib/cta_redux/api/api_response.rb', line 24

def raw_body
  @raw_body
end

#timestampDateTime (readonly)

Returns Timestamp from the API server, if available. Defaults to DateTime.now if unavailable.

Returns:

  • (DateTime)

    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 timestamp
  @timestamp
end