class PostNotification

Class who handles Mundipagg post notification XML

Public Class Methods

ParseNotification(xml) click to toggle source

This method parse the Xml sent by Mundipagg when notify a change in a transaction.

@param request [String] XML received in the Mundipagg POST request. @return [Hash<Symbol, String>] A hash collection containing the XML data parsed.

# File lib/mundipagg/post_notification.rb, line 10
def self.ParseNotification(xml)

  nori = Nori.new(:convert_tags_to => lambda { |tag| PostNotification.to_underscore(tag).to_sym })
  xml_hash  = nori.parse(CGI::unescapeHTML(xml))

  return xml_hash
end
to_underscore(camel_case_string) click to toggle source

Converts a string in Camel Case format to lower case with underscore.

@param Example: 'StatusNotification' outputs 'status_notification' @returns [String] lower case string separated with underscore

# File lib/mundipagg/post_notification.rb, line 22
def self.to_underscore(camel_case_string)
  return camel_case_string.gsub(/::/, '/').
      gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
      gsub(/([a-z\d])([A-Z])/,'\1_\2').
      tr("-", "_").
      downcase
end