Class: SAML2::Contact

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

Defined Under Namespace

Modules: Type

Instance Attribute Summary collapse

Attributes inherited from Base

#xml

Instance Method Summary collapse

Methods inherited from Base

from_xml, load_object_array, load_string_array, lookup_qname, #to_s, #to_xml

Constructor Details

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

Returns a new instance of Contact.



15
16
17
18
19
# File 'lib/saml2/contact.rb', line 15

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

Instance Method Details

#build(builder) ⇒ Object



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

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

#from_xml(node) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/saml2/contact.rb', line 21

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