class Shaman

Constants

VERSION

Attributes

body[R]

Public Class Methods

new(body) click to toggle source
# File lib/shaman.rb, line 10
def initialize(body)
  @body = body
end

Public Instance Methods

body_hash() click to toggle source
# File lib/shaman.rb, line 31
def body_hash
  return body if valid_hash?
  false
end
parsed_form() click to toggle source
# File lib/shaman.rb, line 48
def parsed_form
  Rack::Utils.parse_nested_query(body)
end
parsed_json() click to toggle source
# File lib/shaman.rb, line 36
def parsed_json
  Oj.load(body) if body
rescue Oj::ParseError
  false
end
parsed_xml() click to toggle source
# File lib/shaman.rb, line 42
def parsed_xml
  Hash.from_xml(body)
rescue REXML::ParseException
  false
end
prepped_body() click to toggle source
# File lib/shaman.rb, line 52
def prepped_body
  body_hash or parsed_json or parsed_xml or parsed_form
end
sha() click to toggle source
# File lib/shaman.rb, line 14
def sha
  Digest::MD5.hexdigest(sorted_hash(prepped_body).to_s)
end
sorted_hash(obj) click to toggle source
# File lib/shaman.rb, line 56
def sorted_hash(obj)
  return obj unless obj.is_a?(Hash)
  hash = Hash.new
  obj.each { |k, v| hash[k] = sorted_hash(v) }
  sorted = hash.sort { |a, b| a[0].to_s <=> b[0].to_s }
  Hash[sorted].stringify_keys
end
valid_hash?() click to toggle source
# File lib/shaman.rb, line 27
def valid_hash?
  body.class == Hash
end
valid_json?() click to toggle source
# File lib/shaman.rb, line 18
def valid_json?
  parsed_json.class == Hash
end
Also aliased as: valid_json_body?
valid_json_body?()
Alias for: valid_json?
valid_xml?() click to toggle source
# File lib/shaman.rb, line 23
def valid_xml?
  parsed_xml.class == Hash
end