module Cas module Client class Response def initialize(uri) @request_uri = uri @response = nil end def validate_service_response @response = Net::HTTP.get(@request_uri) end def success? @response.to_s.match(//).captures.length > 0 end def all_attributes(extra_attributes) {}.merge!(get_user(@response)).merge!(get_extra_attributes(@response, extra_attributes)) end protected def xml_namespace "cas" end def get_user(res) match = res.match(/<#{xml_namespace}:user>(.*)<\/#{xml_namespace}:user>/) if match { user: match.captures.first } else # Failed login {} end end def get_extra_attributes(res, extra_attributes) attributes = {} extra_attributes.each do |ea| match = res.match(/<#{xml_namespace}:#{ea}>(.*)<\/#{xml_namespace}:#{ea}>/) if match attributes[ea] = match.captures.first end end attributes end end end end