Class: HotelBeds::Parser::Errors
- Inherits:
-
Object
- Object
- HotelBeds::Parser::Errors
- Defined in:
- lib/hotel_beds/parser/errors.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(response) ⇒ Errors
constructor
A new instance of Errors.
- #to_model(object) ⇒ Object
Constructor Details
#initialize(response) ⇒ Errors
Returns a new instance of Errors.
9 10 11 12 |
# File 'lib/hotel_beds/parser/errors.rb', line 9 def initialize(response) self.response = response freeze end |
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
6 7 8 |
# File 'lib/hotel_beds/parser/errors.rb', line 6 def response @response end |
Instance Method Details
#to_model(object) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/hotel_beds/parser/errors.rb', line 14 def to_model(object) ActiveModel::Errors.new(object).tap do |errors| if response.http_error? errors.add(:base, "HTTP error") elsif response.soap_fault? errors.add(:base, "SOAP error") elsif !response.success? errors.add(:base, "Request failed") end body.css("ErrorList Error").each do |error| errors.add(:base, [ (sm = error.at_css("Message")) && sm.content, (dm = error.at_css("DetailedMessage")) && dm.content ].compact.join("\n")) end end end |