Class: Gillbus::BaseResponse
- Inherits:
-
Object
- Object
- Gillbus::BaseResponse
- Extended by:
- Fields
- Includes:
- UpdateAttrs
- Defined in:
- lib/gillbus/base_response.rb
Direct Known Subclasses
Gillbus::BuyBooking::Response, Gillbus::BuyTickets::Response, CancelOrder::Response, FindOrder::Response, GetAllCities::Response, GetBusImage::Response, GetCarriers::Response, GetCities::Response, GetCountries::Response, GetDatesNew::Response, GetOrderStatus::Response, GetOrderTicket::Response, GetRequiredFields::Response, GetTimeTable::Response, GetTripSeats::Response, GetTripSegments::Response, LockSeats::Response, Logout::Response, ReturnPosition::Response, SearchTripNearbyCities::Response, SearchTrips::Response, SessionLogin::Response, TicketsBooking::Response, UnlockSeats::Response
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#error_code ⇒ Object
Returns the value of attribute error_code.
-
#error_message ⇒ Object
Returns the value of attribute error_message.
-
#external_error_message ⇒ Object
Returns the value of attribute external_error_message.
-
#raw_xml ⇒ Object
make accessible for logging and debuging.
-
#request_time ⇒ Object
Returns the value of attribute request_time.
-
#session_id ⇒ Object
Returns the value of attribute session_id.
Class Method Summary collapse
Instance Method Summary collapse
Methods included from Fields
Methods included from UpdateAttrs
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/gillbus/base_response.rb', line 8 def data @data end |
#error_code ⇒ Object
Returns the value of attribute error_code.
11 12 13 |
# File 'lib/gillbus/base_response.rb', line 11 def error_code @error_code end |
#error_message ⇒ Object
Returns the value of attribute error_message.
12 13 14 |
# File 'lib/gillbus/base_response.rb', line 12 def @error_message end |
#external_error_message ⇒ Object
Returns the value of attribute external_error_message.
13 14 15 |
# File 'lib/gillbus/base_response.rb', line 13 def @external_error_message end |
#raw_xml ⇒ Object
make accessible for logging and debuging
16 17 18 |
# File 'lib/gillbus/base_response.rb', line 16 def raw_xml @raw_xml end |
#request_time ⇒ Object
Returns the value of attribute request_time.
14 15 16 |
# File 'lib/gillbus/base_response.rb', line 14 def request_time @request_time end |
#session_id ⇒ Object
Returns the value of attribute session_id.
9 10 11 |
# File 'lib/gillbus/base_response.rb', line 9 def session_id @session_id end |
Class Method Details
.parse(data, instance: new, options: {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gillbus/base_response.rb', line 22 def self.parse(data, instance: new, options: {}) instance.raw_xml = [:raw_xml] if [:raw_xml] # ugly if data['MESSAGE'] instance.error_code = data['MESSAGE']['CODE'].to_i instance. = data['MESSAGE']['TEXT'] instance. = data['MESSAGE']['EXT_TEXT'] else super(data, instance: instance, options: ) end # for debugging? instance.data = data instance end |
.parse_string(xml_string, **options) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/gillbus/base_response.rb', line 38 def self.parse_string(xml_string, **) xml = Ox.load(xml_string, mode: :hash, symbolize_keys: false) # <DATA/> is a valid response return ParseError.new(xml_string, 'DATA attribute missing') unless xml.key?('DATA') data = xml['DATA'] || {} parse(data, instance: new, options: .merge(raw_xml: xml_string)) rescue Ox::ParseError, ArgumentError => e ParseError.new(xml_string, e.) end |
Instance Method Details
#error? ⇒ Boolean
18 19 20 |
# File 'lib/gillbus/base_response.rb', line 18 def error? !error_code.nil? end |