Method: Cassette::Http::TicketResponse#initialize

Defined in:
lib/cassette/http/ticket_response.rb

#initialize(response) ⇒ TicketResponse

Returns a new instance of TicketResponse.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cassette/http/ticket_response.rb', line 9

def initialize(response)
  namespaces = { "cas" => "http://www.yale.edu/tp/cas" }
  query = "//cas:serviceResponse/cas:authenticationSuccess/cas:user"

  document = REXML::Document.new(response)
  element = REXML::XPath.first(document, query, namespaces)
  @login = element.try(:text)

  if @login
    attributes_query =
      "//cas:serviceResponse/cas:authenticationSuccess/cas:attributes"
    attributes = Hash[REXML::XPath.
      first(document, attributes_query, namespaces).
      elements.
      map { |e| [e.name, e.text] }]

    @name = attributes['cn']
    @authorities = attributes['authorities']
  end
end