Class: DineroMailIpn::NotificationParser
- Inherits:
-
Object
- Object
- DineroMailIpn::NotificationParser
- Defined in:
- lib/dinero_mail_ipn/notification_parser.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
Instance Method Summary collapse
-
#initialize(xml_file, options = {}) ⇒ NotificationParser
constructor
A new instance of NotificationParser.
-
#parse ⇒ DineroMailIpn::Notification
Parses the XML notification POSTed by DineroMail IPNv2 notification system.
-
#valid? ⇒ Boolean
Checks that the XML document is valid.
-
#validate ⇒ Array
Retrieves an [Array] of [Nokogiri::XML::Schema::SyntaxError] with the XML document errors.
Constructor Details
#initialize(xml_file, options = {}) ⇒ NotificationParser
Returns a new instance of NotificationParser.
7 8 9 10 11 12 |
# File 'lib/dinero_mail_ipn/notification_parser.rb', line 7 def initialize(xml_file, = {}) raise ArgumentError, "No XML provided" if xml_file.nil? @xsd = Nokogiri::XML::Schema(xsd_file('notifications.xsd')) @doc = Nokogiri::XML(xml_file.downcase) end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
3 4 5 |
# File 'lib/dinero_mail_ipn/notification_parser.rb', line 3 def doc @doc end |
Instance Method Details
#parse ⇒ DineroMailIpn::Notification
Parses the XML notification POSTed by DineroMail IPNv2 notification system.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dinero_mail_ipn/notification_parser.rb', line 18 def parse return unless valid? type = @doc.xpath("//tiponotificacion").text operations = @doc.xpath("//operacion").inject([]) do |result, operation| result << [operation.xpath('tipo').text, operation.xpath('id').text] result end notification = Notification.new(type, operations) notification end |
#valid? ⇒ Boolean
Checks that the XML document is valid.
36 37 38 |
# File 'lib/dinero_mail_ipn/notification_parser.rb', line 36 def valid? @xsd.valid?(@doc) end |
#validate ⇒ Array
Retrieves an [Array] of [Nokogiri::XML::Schema::SyntaxError] with the XML document errors.
44 45 46 |
# File 'lib/dinero_mail_ipn/notification_parser.rb', line 44 def validate @xsd.validate(@doc) end |