Class: DineroMailIpn::NotificationParser

Inherits:
Object
  • Object
show all
Defined in:
lib/dinero_mail_ipn/notification_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_file, options = {}) ⇒ NotificationParser

Returns a new instance of NotificationParser.

Parameters:

  • XML (String)

    file containing DM IPNv2 operations.

  • a (Hash)

    Hash of optional parameters.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
# File 'lib/dinero_mail_ipn/notification_parser.rb', line 7

def initialize(xml_file, options = {})
  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

#docObject (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

#parseDineroMailIpn::Notification

Parses the XML notification POSTed by DineroMail IPNv2 notification system.

Returns:



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.

Returns:

  • (Boolean)


36
37
38
# File 'lib/dinero_mail_ipn/notification_parser.rb', line 36

def valid?
  @xsd.valid?(@doc)
end

#validateArray

Retrieves an [Array] of [Nokogiri::XML::Schema::SyntaxError] with the XML document errors.

Returns:

  • (Array)

    list of errors found on the XML document



44
45
46
# File 'lib/dinero_mail_ipn/notification_parser.rb', line 44

def validate
  @xsd.validate(@doc)
end