Class: Transactionable::RemoteCustomer
- Inherits:
-
RemoteEntity
- Object
- ActiveRecord::Base
- RemoteEntity
- Transactionable::RemoteCustomer
show all
- Defined in:
- app/models/transactionable/remote_customer.rb
Instance Method Summary
collapse
#destroy_remote, #fetch, #remote_entity_type, #service_name, #synced?
Instance Method Details
#build_or_update_remote ⇒ Object
5
6
7
8
|
# File 'app/models/transactionable/remote_customer.rb', line 5
def build_or_update_remote
build_remote unless synced?
update_remote
end
|
#build_remote ⇒ Object
10
11
12
13
14
|
# File 'app/models/transactionable/remote_customer.rb', line 10
def build_remote
balanced_customer = Balanced::Customer.new.save
self.uri = balanced_customer.uri
self.synced_at = Time.now
end
|
#update_remote ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/models/transactionable/remote_customer.rb', line 16
def update_remote
balanced_customer = fetch
if self.local_entity.respond_to?(:sync_attributes)
balanced_customer_attributes = local_entity.sync_attributes
non_address_keys = [:name, :email, :phone]
new_customer_attributes = balanced_customer_attributes.reject { |k,v| v.blank? }
address = new_customer_attributes.slice!(*non_address_keys)
new_customer_attributes.merge!(address: address)
new_customer_attributes.each { |k,v| balanced_customer.send("#{k}=", v) }
balanced_customer.save
else
balanced_customer = fetch
balanced_customer.name = "#{self.local_entity_type} #{self.local_entity_id}"
balanced_customer.meta = {
entity: self.local_entity_type,
entity_id: self.local_entity_id
}
balanced_customer.save
end
update_attribute(:synced_at, Time.now) unless new_record?
balanced_customer
end
|