lib/cas/client/response.rb in cas-client-0.1.3 vs lib/cas/client/response.rb in cas-client-0.2.0

- old
+ new

@@ -9,40 +9,43 @@ def validate_service_response @response = Net::HTTP.get(@request_uri) end def success? - @response.to_s.match(/<cas:authenticationSuccess>/).captures.length > 0 + @response.to_s.match(/<#{xml_namespace}:authenticationSuccess>/) end - def all_attributes(extra_attributes) - {}.merge!(get_user(@response)).merge!(get_extra_attributes(@response, extra_attributes)) + def all_attributes + get_user.merge!(get_extra_attributes) end protected def xml_namespace - "cas" + Cas::Client.configuration.cas_namespace end - def get_user(res) - match = res.match(/<#{xml_namespace}:user>(.*)<\/#{xml_namespace}:user>/) + def get_user + match = @response.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 + def get_extra_attributes + {}.tap do |attributes| + Cas::Client.configuration.extra_attributes.each do |ea| + match = @response.match(/<#{xml_namespace}:#{ea}>(.*)<\/#{xml_namespace}:#{ea}>/) + + if match + attributes[ea] = match.captures.first + else + attributes + end end end - attributes end end end end