Module: HighriseMapper::Person::InstanceMethods

Defined in:
lib/highrise_mapper/person.rb

Instance Method Summary collapse

Instance Method Details

#build_highrise_hashObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/highrise_mapper/person.rb', line 32

def build_highrise_hash
  new_hash = {}
  config = HighriseMapper.config
  config['person'].each do |k,v|
    if v!=nil && v!=''
      case k
      when 'email_address'
        new_hash['contact_data']={'email_addresses'=>[{'address'=> self.send(v),'location'=>''}]}
      else
        new_hash[k]=self.send(v)
      end
    end
  end
  return new_hash
end

#delete_from_highrise(force_id = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/highrise_mapper/person.rb', line 21

def delete_from_highrise(force_id=nil)
  if force_id!=nil
    highrise_id = force_id
  else
    highrise_id = self.highrise_id
  end
  self.highrise_context.setup_highrise
  highrise_person = Highrise::Person.find(highrise_id)
  highrise_person.destroy
end

#save_to_highriseObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/highrise_mapper/person.rb', line 5

def save_to_highrise
  unless HighriseMapper.config['person'].is_a? Hash
    raise 'Your highrise_mapper.yml does not contain the "person" configuration key.'  
  end
  self.highrise_context.setup_highrise
  highrise_person = Highrise::Person.new(build_highrise_hash)

  begin
    highrise_person.save!
  rescue Exception => e
    #shoud get rails logger if available
    puts highrise_person.errors
  end
  return highrise_person.attributes['id']
end