4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/zoho_invoice_resource/formats/customer.rb', line 4
def encode(record, options={})
options[:root] = options[:root].try(:camelize)
data = {
'CustomerID' => record.customer_id,
'Name' => record.name,
'PaymentsDue' => record.payments_due,
'BillingAddress' => record.billing_address,
'BillingCity' => record.billing_city,
'BillingState' => record.billing_state,
'BillingZip' => record.billing_zip,
'BillingCountry' => record.billing_country,
'BillingFax' => record.billing_fax,
'ShippingAddress' => record.shipping_address,
'ShippingCity' => record.shipping_city,
'ShippingState' => record.shipping_state,
'ShippingZip' => record.shipping_zip,
'ShippingCountry' => record.shipping_country,
'ShippingFax' => record.shipping_fax,
'Contacts' => [],
'Notes' => record.notes,
'CustomFields' => {}
}
record.contacts.each do |contact|
item = {
'ContactID' => contact.contact_id,
'Salutation' => contact.salutation,
'FirstName' => contact.first_name,
'LastName' => contact.last_name,
'EMail' => contact.e_mail,
'Phone' => contact.phone,
'Mobile' => contact.mobile
}
data['Contacts'] << item
end if record.contacts
if record.custom_fields.custom_field_label1
data['CustomFields']['CustomFieldLabel1'] = record.custom_fields.custom_field_label1
data['CustomFields']['CustomFieldValue1'] = record.custom_fields.custom_field_value1
end
if record.custom_fields.custom_field_label2
data['CustomFields']['CustomFieldLabel2'] = record.custom_fields.custom_field_label2
data['CustomFields']['CustomFieldValue2'] = record.custom_fields.custom_field_value2
end
if record.custom_fields.custom_field_label3
data['CustomFields']['CustomFieldLabel3'] = record.custom_fields.custom_field_label3
data['CustomFields']['CustomFieldValue3'] = record.custom_fields.custom_field_value3
end
remove_empty!(data)
data.to_xml(options)
end
|