Sha256: dea9782d407033d65d2211891c81f3ed231e43673eb6feafdb22ca1d82228d6a

Contents?: true

Size: 1 KB

Versions: 6

Compression:

Stored size: 1 KB

Contents

require 'nori'

# Class who handles Mundipagg post notification XML
class PostNotification

  # 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.
  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

  # 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
  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
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mundipagg_api-1.3.1 lib/mundipagg/post_notification.rb
mundipagg_api-1.3.0 lib/mundipagg/post_notification.rb
mundipagg_api-1.1.1 lib/mundipagg/post_notification.rb
mundipagg_api-1.1.0 lib/mundipagg/post_notification.rb
mundipagg_api-1.0.1 lib/mundipagg/post_notification.rb
mundipagg_api-1.0.0 lib/mundipagg/post_notification.rb