Class: CapsuleCRM::Email

Inherits:
Contact show all
Defined in:
lib/capsulecrm/email.rb

Instance Attribute Summary collapse

Attributes inherited from Contact

#type

Attributes inherited from Child

#parent

Attributes inherited from Base

#id, #raw_data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Child

init_many, init_one, #initialize

Methods inherited from Base

#==, #errors, find, #initialize, last_response, #new_record?

Constructor Details

This class inherits a constructor from CapsuleCRM::Child

Instance Attribute Details

#addressObject

Returns the value of attribute address.



3
4
5
# File 'lib/capsulecrm/email.rb', line 3

def address
  @address
end

Class Method Details

.attributes_to_xml(attributes, root = nil) ⇒ Object

uses xml_map() to convert :attributes into an xml string



45
46
47
48
49
50
51
52
53
# File 'lib/capsulecrm/email.rb', line 45

def self.attributes_to_xml(attributes, root=nil)
  xml = {"contacts" => {"email" => {}}}
  map = xml_map.invert
  attributes.each do |k,v|
    key = map[k.to_s]
    xml["contacts"]["email"][key] = v
  end
  xml.to_xml :root => root
end

.xml_mapObject

nodoc



56
57
58
59
60
61
# File 'lib/capsulecrm/email.rb', line 56

def self.xml_map
  map = {
    'emailAddress' => 'address'
  }
  super.merge map
end

Instance Method Details

#attributesObject

nodoc



8
9
10
11
12
13
14
15
# File 'lib/capsulecrm/email.rb', line 8

def attributes
  attrs = {}
  arr = [:address, :type]
  arr.each do |key|
    attrs[key] = self.send(key)
  end
  attrs
end

#dirty_attributesObject

nodoc



24
25
26
# File 'lib/capsulecrm/email.rb', line 24

def dirty_attributes
  Hash[attributes.select { |k,v| changed.include? k.to_s }]
end

#parent_typeObject



28
29
30
31
32
# File 'lib/capsulecrm/email.rb', line 28

def parent_type
  return "person" if self.parent.class == CapsuleCRM::Person
  return "organisation" if self.parent.class == CapsuleCRM::Organisation
  raise "Unknown Parent Type"
end

#saveObject

nodoc



35
36
37
38
39
40
41
42
# File 'lib/capsulecrm/email.rb', line 35

def save
  path = ["", "api", parent_type, self.parent.id].join("/")
  options = {:root => 'person', :path => path}
  attrs = new_record?? attributes : {:id => id}.merge(dirty_attributes)
  success = self.class.update id, attrs, options
  changed_attributes.clear if success
  success   
end