Class: GoogleAppsApi::ContactEntity

Inherits:
Entity
  • Object
show all
Defined in:
lib/google_apps_api/contacts.rb

Constant Summary

Constants inherited from Entity

Entity::VALID_ENTITY_TYPES

Instance Attribute Summary collapse

Attributes inherited from Entity

#domain, #id, #kind

Instance Method Summary collapse

Methods inherited from Entity

#full_id, #full_id_escaped, #id_escaped, #qualified_id, #qualified_id_escaped

Constructor Details

#initialize(*args) ⇒ ContactEntity

Returns a new instance of ContactEntity.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/google_apps_api/contacts.rb', line 55

def initialize(*args)
  @emails = {}

  options = args.extract_options!
  if (_xml = options[:xml])
    xml = _xml.at_css("entry") || _xml
    @kind = "contact"
    @id = xml.at_css("id").content.gsub(/^.+\/base\//,"")
    @domain = xml.at_css("id").content.gsub(/^.+\/contacts\/([^\/]+)\/.+$/,"\\1")
    @name = xml.at_css("title").content
    
    xml.css("gd|email").each do |email_node|
      loc = email_node.attribute("rel").content.gsub(/^.+\#/,"").to_sym
      email = email_node.attribute("address").content
      primary = email_node.attribute("primary") && email_node.attribute("primary").content == "true"
      
      @primary_email = loc if primary
      @emails[loc] = email
      
    end
  else
    if args.first.kind_of?(String)
      super(:contact => args.first)
    else
      @name = options.delete(:name)
      @emails = options.delete(:emails) || {}
      
      super(options.merge(:kind => "contact"))
    end
  end
end

Instance Attribute Details

#emailsObject (readonly)

Returns the value of attribute emails.



53
54
55
# File 'lib/google_apps_api/contacts.rb', line 53

def emails
  @emails
end

#nameObject (readonly)

Returns the value of attribute name.



53
54
55
# File 'lib/google_apps_api/contacts.rb', line 53

def name
  @name
end

#primary_emailObject (readonly)

Returns the value of attribute primary_email.



53
54
55
# File 'lib/google_apps_api/contacts.rb', line 53

def primary_email
  @primary_email
end

Instance Method Details

#==(other) ⇒ Object



87
88
89
# File 'lib/google_apps_api/contacts.rb', line 87

def ==(other)
  super(other)
end