Sha256: 9821dcb2a61b50ccbf943b2b337b142768c2651fe3ad85675c1f79d5062ad992

Contents?: true

Size: 1.64 KB

Versions: 9

Compression:

Stored size: 1.64 KB

Contents

require 'saml2/base'

module SAML2
  class Contact
    module Type
      ADMINISTRATIVE = 'administrative'.freeze
      BILLING        = 'billing'.freeze
      OTHER          = 'other'.freeze
      SUPPORT        = 'support'.freeze
      TECHNICAL      = 'technical'.freeze
    end

    attr_accessor :type, :company, :given_name, :surname, :email_addresses, :telephone_numbers

    def self.from_xml(node)
      return nil unless node

      result = new(node['contactType'])
      company = node.at_xpath('md:Company', Namespaces::ALL)
      result.company = company && company.content && company.content.strip
      given_name = node.at_xpath('md:GivenName', Namespaces::ALL)
      result.given_name = given_name && given_name.content && given_name.content.strip
      surname = node.at_xpath('md:SurName', Namespaces::ALL)
      result.surname = surname && surname.content && surname.content.strip
      result.email_addresses = Base.load_string_array(node, 'md:EmailAddress')
      result.telephone_numbers = Base.load_string_array(node, 'md:TelephoneNumber')
      result
    end

    def initialize(type = Type::OTHER)
      @type = type
      @email_addresses = []
      @telephone_numbers = []
    end

    def build(builder)
      builder['md'].ContactPerson('contactType' => type) do |builder|
        builder['md'].Company(company) if company
        builder['md'].GivenName(given_name) if given_name
        builder['md'].SurName(surname) if surname
        email_addresses.each do |email|
          builder['md'].EmailAddress(email)
        end
        telephone_numbers.each do |tel|
          builder['md'].TelephoneNumber(tel)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
saml2-1.0.8 lib/saml2/contact.rb
saml2-1.0.7 lib/saml2/contact.rb
saml2-1.0.6 lib/saml2/contact.rb
saml2-1.0.5 lib/saml2/contact.rb
saml2-1.0.4 lib/saml2/contact.rb
saml2-1.0.3 lib/saml2/contact.rb
saml2-1.0.2 lib/saml2/contact.rb
saml2-1.0.1 lib/saml2/contact.rb
saml2-1.0.0 lib/saml2/contact.rb