Class: CASino::TicketValidationResponseBuilder

Inherits:
Object
  • Object
show all
Defined in:
app/builders/casino/ticket_validation_response_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(success, options) ⇒ TicketValidationResponseBuilder

Returns a new instance of TicketValidationResponseBuilder.


6
7
8
9
# File 'app/builders/casino/ticket_validation_response_builder.rb', line 6

def initialize(success, options)
  @success = success
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options


4
5
6
# File 'app/builders/casino/ticket_validation_response_builder.rb', line 4

def options
  @options
end

#successObject (readonly)

Returns the value of attribute success


4
5
6
# File 'app/builders/casino/ticket_validation_response_builder.rb', line 4

def success
  @success
end

Instance Method Details

#buildObject


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/builders/casino/ticket_validation_response_builder.rb', line 11

def build
  xml = Builder::XmlMarkup.new(indent: 2)
  xml.cas :serviceResponse, 'xmlns:cas' => 'http://www.yale.edu/tp/cas' do |service_response|
    if success
      ticket = options[:ticket]
      if ticket.is_a?(CASino::ProxyTicket)
        proxies = []
        service_ticket = ticket
        while service_ticket.is_a?(CASino::ProxyTicket)
          proxy_granting_ticket = ticket.proxy_granting_ticket
          proxies << proxy_granting_ticket.pgt_url
          service_ticket = proxy_granting_ticket.granter
        end
        ticket_granting_ticket = service_ticket.ticket_granting_ticket
      else
        service_ticket = ticket
        ticket_granting_ticket = ticket.ticket_granting_ticket
      end

      build_success_xml(service_response, ticket, service_ticket, ticket_granting_ticket, proxies)
    else
      build_failure_xml(service_response)
    end
  end
  xml.target!
end