Sha256: b405201b96b6175e68697cf21e5e186d143c12f30306e8a30a30e8ac3e1a9190

Contents?: true

Size: 649 Bytes

Versions: 3

Compression:

Stored size: 649 Bytes

Contents

require 'faraday_middleware/response_middleware'

module FaradayMiddleware
  class ParseOpenfireXml < FaradayMiddleware::ResponseMiddleware

    dependency 'multi_xml'

    define_parser do |body|
      parsed = ::MultiXml.parse(body)
      root = parsed.keys.first
      if parsed[root].nil?
        parsed[root] = []
      else
        parsed[root] = parsed[root].values.first
        if parsed.keys.length == 1
          parsed[root.to_s.pluralize] = parsed.delete(root)
        end
      end
      if root == "error"
        { errors: [parsed["errors"]], data: {} }
      else
        { data: parsed.symbolize_keys }
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
openfire-ruby-0.1.2 lib/faraday_middleware/parse_openfire_xml.rb
openfire-ruby-0.1.1 lib/faraday_middleware/parse_openfire_xml.rb
openfire-ruby-0.1.0 lib/faraday_middleware/parse_openfire_xml.rb