Class: Ppl::Service::PostalAddress

Inherits:
Object
  • Object
show all
Defined in:
lib/ppl/service/postal_address.rb

Instance Method Summary collapse

Instance Method Details

#add(contact, address_id, options) ⇒ Object



3
4
5
6
7
8
# File 'lib/ppl/service/postal_address.rb', line 3

def add(contact, address_id, options)
  address = Ppl::Entity::PostalAddress.new
  address.id = address_id
  update_postal_address(contact, address, options)
  contact.postal_addresses << address
end

#move(contact, address_id, new_address_id) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/ppl/service/postal_address.rb', line 23

def move(contact, address_id, new_address_id)
  address = require_address(contact, address_id)
  id_okay = contact.postal_addresses.select { |pa| pa.id == new_address_id }.empty?
  if id_okay
    address.id = new_address_id
  else
    raise "Address '#{new_address_id}' is already in use"
  end
end

#remove(contact, address_id) ⇒ Object



18
19
20
21
# File 'lib/ppl/service/postal_address.rb', line 18

def remove(contact, address_id)
  require_address(contact, address_id)
  contact.postal_addresses.reject! { |pa| pa.id == address_id }
end

#update(contact, address_id, options) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/ppl/service/postal_address.rb', line 10

def update(contact, address_id, options)
  address = contact.postal_addresses.find { |p| p.id == address_id }
  update_postal_address(contact, address, options)
  if options[:new_id]
    move(contact, address_id, options[:new_id])
  end
end