activeresource-zoho_invoice 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e869fc0ecbce0191959acf0425c34ed6b01be17
4
- data.tar.gz: cd40201f9d38b350c21598fbb4a435b583173215
3
+ metadata.gz: 7c14b2d4a27f6b0e6b41a769c1bc02c172e4ed5b
4
+ data.tar.gz: 7f084e3312c1e88dd6af54516961aefb0f062d0c
5
5
  SHA512:
6
- metadata.gz: 34f337b37e63146553557c203957693fc674681231c0fc92d89ed22d4dc2b30c68a5f03ace5d57f03d5a9b41707a927dd7b5e0c40e941764b58646a01cef5c2a
7
- data.tar.gz: b7303fdeee6cd3cfb0c9dd4adc8d92ab5e41d6e05383b8660d50553ffba6ea7ec6c03fbc46e45d597b90dd52a4a8a65a39ec677ad4746acc59b3922ec85f4c39
6
+ metadata.gz: 17826a918d136dc40c377a95013f669152a4cf9e61ad51dfbff5ab709881c7e92dc2870e383aaf81645f76b774e33e74c4d45ee4d4f0031bb84a6a088cddc0a7
7
+ data.tar.gz: 688837c1c220e90e064b7a0584fa2302ff1592000b6d3cd7bfbbcd0ca65f1c3d7777543af762f85a7088d318e15487d1e90cef3b2a035f6315e6dd355a9d47b8
@@ -36,6 +36,20 @@ module ZohoInvoiceResource
36
36
  end
37
37
  end
38
38
 
39
+ private
40
+
41
+ def remove_empty!(hash)
42
+ hash.each do |key, value|
43
+ case value
44
+ when Hash
45
+ remove_empty!(value)
46
+ when Array
47
+ value.compact!
48
+ end
49
+ hash.delete(key) if value.nil? || value == [] || value == {}
50
+ end
51
+ end
52
+
39
53
  def normalize_date(date)
40
54
  if date.match %r|\d{4}/\d{2}/\d{2}|
41
55
  date.tr('/', '-')
@@ -5,18 +5,42 @@ module ZohoInvoiceResource
5
5
  options[:root] = options[:root].try(:camelize)
6
6
  # updatable attributes restricted
7
7
  data = {
8
- 'CustomerID' => record.customer_id,
9
- 'Name' => record.name,
10
- 'PaymentsDue' => record.payments_due,
11
- 'BillingAddress' => record.billing_address,
12
- 'BillingCity' => record.billing_city,
13
- 'BillingState' => record.billing_state,
14
- 'BillingZip' => record.billing_zip,
15
- 'BillingCountry' => record.billing_country,
16
- 'Notes' => record.notes,
17
- #'CustomFields' => {}
8
+ 'CustomerID' => record.customer_id,
9
+ 'Name' => record.name,
10
+ 'PaymentsDue' => record.payments_due,
11
+ 'BillingAddress' => record.billing_address,
12
+ 'BillingCity' => record.billing_city,
13
+ 'BillingState' => record.billing_state,
14
+ 'BillingZip' => record.billing_zip,
15
+ 'BillingCountry' => record.billing_country,
16
+ 'BillingFax' => record.billing_fax,
17
+ 'ShippingAddress' => record.shipping_address,
18
+ 'ShippingCity' => record.shipping_city,
19
+ 'ShippingState' => record.shipping_state,
20
+ 'ShippingZip' => record.shipping_zip,
21
+ 'ShippingCountry' => record.shipping_country,
22
+ 'ShippingFax' => record.shipping_fax,
23
+ 'Contacts' => [],
24
+ 'Notes' => record.notes,
25
+ 'CustomFields' => {}
18
26
  }
19
- data.to_xml(options).tapp
27
+ record.contacts.each do |contact|
28
+ item = {
29
+ 'ContactID' => contact.contact_id,
30
+ 'Salutation' => contact.salutation,
31
+ 'FirstName' => contact.first_name,
32
+ 'LastName' => contact.last_name,
33
+ 'EMail' => contact.e_mail,
34
+ 'Phone' => contact.phone,
35
+ 'Mobile' => contact.mobile
36
+ }
37
+ data['Contacts'] << item
38
+ end if record.contacts
39
+ data['CustomFields']['CustomFieldValue1'] = record.custom_fields.custom_field_value1 if record.custom_fields.custom_field_label1
40
+ data['CustomFields']['CustomFieldValue2'] = record.custom_fields.custom_field_value2 if record.custom_fields.custom_field_label2
41
+ data['CustomFields']['CustomFieldValue3'] = record.custom_fields.custom_field_value3 if record.custom_fields.custom_field_label3
42
+ remove_empty!(data)
43
+ data.to_xml(options)
20
44
  end
21
45
 
22
46
  def decode(xml)
@@ -18,12 +18,11 @@ module ZohoInvoiceResource
18
18
  'Price' => invoice_item.price
19
19
  }
20
20
  data['InvoiceItems'] << item
21
- end
22
- data.delete('InvoiceItems') if data['InvoiceItems'].empty?
21
+ end if record.invoice_items
23
22
  data['CustomFields']['CustomField1'] = record.custom_fields.custom_field1 if record.custom_fields.custom_label1
24
23
  data['CustomFields']['CustomField2'] = record.custom_fields.custom_field2 if record.custom_fields.custom_label2
25
24
  data['CustomFields']['CustomField3'] = record.custom_fields.custom_field3 if record.custom_fields.custom_label3
26
- data.delete('CustomFields') if data['CustomFields'].empty?
25
+ remove_empty!(data)
27
26
  data.to_xml(options)
28
27
  end
29
28
  end
@@ -1,3 +1,3 @@
1
1
  module ZohoInvoiceResource
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeresource-zoho_invoice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toru KAWAMURA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-19 00:00:00.000000000 Z
11
+ date: 2013-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource