class Supercamp::Response

Attributes

count[R]
entries[R]
results[R]

Public Class Methods

new(response) click to toggle source
# File lib/supercamp/response.rb, line 13
def initialize(response)
  p = parse_response(response.body)

  set_results_count(p)
  set_entries(p)
end

Private Instance Methods

parse_response(xml) click to toggle source
# File lib/supercamp/response.rb, line 23
def parse_response(xml)
  xml.gsub!("\n", "")
  Oga.parse_xml(xml).xpath("resultset").first
end
set_entries(parsed) click to toggle source
# File lib/supercamp/response.rb, line 32
def set_entries(parsed)
  @entries = parsed.children.map do |child|
    child.attributes.inject(Hashr.new) do |h, attr|
      key = attr.name.gsub(/(.)([A-Z])/,'\1_\2').downcase
      h[key] = attr.value; h
    end
  end
end
set_results_count(parsed) click to toggle source
# File lib/supercamp/response.rb, line 28
def set_results_count(parsed)
  @count = parsed.attribute("count").value.to_i
end