class RoyalMailApi::Response

Constants

Shipment

Attributes

body[RW]
errors[RW]
http[RW]
parser[RW]
shipments[RW]
warnings[RW]

Public Class Methods

new(response) click to toggle source
# File lib/royal_mail_api/response.rb, line 16
def initialize(response)
  @parser = RoyalMailApi::XmlParser.new
  set_attrs(response)
end

Private Instance Methods

parse(xml, attr) click to toggle source
# File lib/royal_mail_api/response.rb, line 23
def parse(xml, attr)
  parser.parse(xml, attr)
end
parse_all(xml, attr) click to toggle source
# File lib/royal_mail_api/response.rb, line 27
def parse_all(xml, attr)
  parser.parse_all(xml, attr)
end
parse_text(xml, attr) click to toggle source
# File lib/royal_mail_api/response.rb, line 31
def parse_text(xml, attr)
  parser.parse_text(xml, attr)
end
set_attrs(response) click to toggle source
# File lib/royal_mail_api/response.rb, line 35
def set_attrs(response)
  @body = response.xml
  @http = response.http

  set_errors
  set_warnings
  set_shipments
end
set_errors() click to toggle source
# File lib/royal_mail_api/response.rb, line 44
def set_errors
  @errors = parse_all(body, "error").map do |error|
    RoyalMailApi::RoyalMailError.new({
      error_code:         parse_text(error, "errorCode"),
      error_description:  parse_text(error, "errorDescription")
    })
  end
end
set_shipments() click to toggle source
# File lib/royal_mail_api/response.rb, line 62
def set_shipments
  @shipments = parse_all(body, "shipment").map do |shipment|
    Shipment.new(
      parse_text(shipment, "itemId"),
      parse_text(shipment, "shipmentNumber"),
      parse_text(shipment, "validFrom")
    )
  end
end
set_warnings() click to toggle source
# File lib/royal_mail_api/response.rb, line 53
def set_warnings
  @warnings = parse_all(body, "warning").map do |warning|
    RoyalMailApi::Warning.new({
      warning_code:         parse_text(warning, "warningCode"),
      warning_description:  parse_text(warning, "warningDescription")
    })
  end
end