Sha256: 6f82f33995dcfe1738984d0cfa4543a28e10cb4da695346aed3b1533aff2334c

Contents?: true

Size: 1.63 KB

Versions: 9

Compression:

Stored size: 1.63 KB

Contents

require 'saml2/base'

module SAML2
  class Contact < Base
    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 initialize(type = Type::OTHER)
      @type = type
      @email_addresses = []
      @telephone_numbers = []
    end

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

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
saml2-2.0.2 lib/saml2/contact.rb
saml2-2.0.1 lib/saml2/contact.rb
saml2-2.0.0 lib/saml2/contact.rb
saml2-1.1.5 lib/saml2/contact.rb
saml2-1.1.4 lib/saml2/contact.rb
saml2-1.1.3 lib/saml2/contact.rb
saml2-1.1.2 lib/saml2/contact.rb
saml2-1.1.1 lib/saml2/contact.rb
saml2-1.1.0 lib/saml2/contact.rb