<commit_before>require 'castanet'

require 'uri'

module Castanet
  class ProxyTicket < ServiceTicket
    ##
    # The URL of the CAS server's proxy ticket granting service.
    #
    # @return [String]
    attr_accessor :proxy_url

    ##
    # The URL of the CAS server's proxy ticket validation service.
    #
    # @return [String]
    attr_accessor :proxy_validate_url

    ##
    # The `/proxy` response from the CAS server.
    #
    # This is set by {#reify!}, but can be set manually for testing purposes.
    #
    # @return [#ticket]
    attr_accessor :proxy_response

    def_delegator :proxy_response, :ok?, :issued?

    def_delegators :proxy_response, :failure_code, :failure_reason

    ##
    # Initializes an instance of ProxyTicket.
    #
    # Instantiation guide
    # ===================
    #
    # 1. If requesting a proxy ticket, set `pt` to nil, `service` to the
    #    service URL, and `pgt` to the proxy granting ticket.
    # 2. If checking a proxy ticket, set `pt` to the proxy ticket, `service` to
    #    the service URL, and `pgt` to nil.
    #
    # @param [String, nil] pt the proxy ticket
    # @param [String, nil] pgt the proxy granting ticket
    # @param [String] service the service URL
    def initialize(pt, pgt, service)
      super(pt, service)

      self.pgt = pgt
    end

    ##
    # The proxy ticket wrapped by this object.  This can come either from a
    # proxy ticket issuance via {#reify!} or be set at instantiation.  Tickets
    # issued via {#reify!} have higher precedence.
    #
    # If a proxy ticket was neither supplied at instantiation nor requested via
    # {#reify!}, then `ticket` will return nil.
    #
    # @return [String, nil] the proxy ticket
    def ticket
      proxy_response ? proxy_response.ticket : super
    end

    ##
    # Returns the string representation of {#ticket}.
    #
    # If {#ticket} is not nil, then the return value of this method is
    # {#ticket}; otherwise, it is `""`.
    #
    # @return [String] the ticket or empty string
    def to_s
     ticket.to_s
    end

    ##
    # Requests a proxy ticket from {#proxy_url} and stores it in {#ticket}.
    #
    # If a proxy ticket cannot be issued for any reason, this method raises a
    # {ProxyTicketError} containing the failure code and reason returned by the
    # CAS server.
    #
    # This method should only be run once per `ProxyTicket` instance.  It can be
    # run multiple times, but each invocation will overwrite {#ticket} with a
    # new ticket.
    #
    # This method is automatically called by {Client#issue_proxy_ticket}, and
    # as such should never need to be called by users of Castanet; however, in
    # the interest of program organization, the method is public and located
    # here.  Also, if you're managing `ProxyTicket` instances manually for some
    # reason, you may find this method useful.
    #
    # @raise [ProxyTicketError] if a proxy ticket cannot be issued
    # @return [ProxyTicket] void<commit_msg>Fixed return value in documentation for `Castanet::ProxyTicket#reify!`.  See castanet-5.<commit_after>require 'castanet'

require 'uri'

module Castanet
  class ProxyTicket < ServiceTicket
    ##
    # The URL of the CAS server's proxy ticket granting service.
    #
    # @return [String]
    attr_accessor :proxy_url

    ##
    # The URL of the CAS server's proxy ticket validation service.
    #
    # @return [String]
    attr_accessor :proxy_validate_url

    ##
    # The `/proxy` response from the CAS server.
    #
    # This is set by {#reify!}, but can be set manually for testing purposes.
    #
    # @return [#ticket]
    attr_accessor :proxy_response

    def_delegator :proxy_response, :ok?, :issued?

    def_delegators :proxy_response, :failure_code, :failure_reason

    ##
    # Initializes an instance of ProxyTicket.
    #
    # Instantiation guide
    # ===================
    #
    # 1. If requesting a proxy ticket, set `pt` to nil, `service` to the
    #    service URL, and `pgt` to the proxy granting ticket.
    # 2. If checking a proxy ticket, set `pt` to the proxy ticket, `service` to
    #    the service URL, and `pgt` to nil.
    #
    # @param [String, nil] pt the proxy ticket
    # @param [String, nil] pgt the proxy granting ticket
    # @param [String] service the service URL
    def initialize(pt, pgt, service)
      super(pt, service)

      self.pgt = pgt
    end

    ##
    # The proxy ticket wrapped by this object.  This can come either from a
    # proxy ticket issuance via {#reify!} or be set at instantiation.  Tickets
    # issued via {#reify!} have higher precedence.
    #
    # If a proxy ticket was neither supplied at instantiation nor requested via
    # {#reify!}, then `ticket` will return nil.
    #
    # @return [String, nil] the proxy ticket
    def ticket
      proxy_response ? proxy_response.ticket : super
    end

    ##
    # Returns the string representation of {#ticket}.
    #
    # If {#ticket} is not nil, then the return value of this method is
    # {#ticket}; otherwise, it is `""`.
    #
    # @return [String] the ticket or empty string
    def to_s
     ticket.to_s
    end

    ##
    # Requests a proxy ticket from {#proxy_url} and stores it in {#ticket}.
    #
    # If a proxy ticket cannot be issued for any reason, this method raises a
    # {ProxyTicketError} containing the failure code and reason returned by the
    # CAS server.
    #
    # This method should only be run once per `ProxyTicket` instance.  It can be
    # run multiple times, but each invocation will overwrite {#ticket} with a
    # new ticket.
    #
    # This method is automatically called by {Client#issue_proxy_ticket}, and
    # as such should never need to be called by users of Castanet; however, in
    # the interest of program organization, the method is public and located
    # here.  Also, if you're managing `ProxyTicket` instances manually for some
    # reason, you may find this method useful.
    #
    # @raise [ProxyTicketError] if a proxy ticket cannot be issued
    # @return void
{'fraction_non_alphanumeric': 0.08881199538638986, 'fraction_numerical': 0.0008238589553468446, 'mean_word_length': 2.7515451174289245, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7030905', 'n_tokens_mistral': 1833, 'n_tokens_neox': 1732, 'n_words': 746}