Class: SAML2::Contact

Inherits:
Object
  • Object
show all
Defined in:
lib/saml2/contact.rb

Defined Under Namespace

Modules: Type

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type = Type::OTHER) ⇒ Contact

Returns a new instance of Contact.



30
31
32
33
34
# File 'lib/saml2/contact.rb', line 30

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

Instance Attribute Details

#companyObject

Returns the value of attribute company.



13
14
15
# File 'lib/saml2/contact.rb', line 13

def company
  @company
end

#email_addressesObject

Returns the value of attribute email_addresses.



13
14
15
# File 'lib/saml2/contact.rb', line 13

def email_addresses
  @email_addresses
end

#given_nameObject

Returns the value of attribute given_name.



13
14
15
# File 'lib/saml2/contact.rb', line 13

def given_name
  @given_name
end

#surnameObject

Returns the value of attribute surname.



13
14
15
# File 'lib/saml2/contact.rb', line 13

def surname
  @surname
end

#telephone_numbersObject

Returns the value of attribute telephone_numbers.



13
14
15
# File 'lib/saml2/contact.rb', line 13

def telephone_numbers
  @telephone_numbers
end

#typeObject

Returns the value of attribute type.



13
14
15
# File 'lib/saml2/contact.rb', line 13

def type
  @type
end

Class Method Details

.from_xml(node) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/saml2/contact.rb', line 15

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

Instance Method Details

#build(builder) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/saml2/contact.rb', line 36

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