Class: CapsuleCRM::Email
- Defined in:
- lib/capsulecrm/email.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
Attributes inherited from Contact
Attributes inherited from Child
Attributes inherited from Base
Class Method Summary collapse
-
.attributes_to_xml(attributes, root = nil) ⇒ Object
uses xml_map() to convert :attributes into an xml string.
-
.xml_map ⇒ Object
nodoc.
Instance Method Summary collapse
-
#attributes ⇒ Object
nodoc.
-
#dirty_attributes ⇒ Object
nodoc.
- #parent_type ⇒ Object
-
#save ⇒ Object
nodoc.
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
#address ⇒ Object
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_map ⇒ Object
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
#attributes ⇒ Object
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_attributes ⇒ Object
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_type ⇒ Object
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 |
#save ⇒ Object
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("/") = {:root => 'person', :path => path} attrs = new_record?? attributes : {:id => id}.merge(dirty_attributes) success = self.class.update id, attrs, changed_attributes.clear if success success end |