contact_sync 1.2.1 → 1.2.2

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: 3d0781f453be7d54f3779c149d146a8a879c1e98
4
- data.tar.gz: b4239cab5b7cae346308696aaec17cc7a40651c9
3
+ metadata.gz: 26d68d12a21bf1a35d0c0e9f7992b93555b86af8
4
+ data.tar.gz: e43cd2f1ceecce72e477a2c03d97735a12e6a674
5
5
  SHA512:
6
- metadata.gz: dd436dc6f4dd4ae9e6aff18c4da45446ef75b944c6f6732f262fc3bf74cc03501ce1ce43976681b26cd1756f434626ba8b6069e0a5cf6f57daf3d0242cd0934c
7
- data.tar.gz: fd2c45e3b28ccfcb816aa6105ede29021339f58dd85e4d7b11de32e60ca53a0abe1f91ce57994cf97faf3e5f023d3af3076bbe0bada0f2e7d368c62fca6145ec
6
+ metadata.gz: b2b09f6a4d89b9040fb4fadcb86139e31b82741ae116aed519453822486ffe8b968c8af37f9a92684d70f86ab88cfa3c741ba97e30ff9033ea503f4445f3581b
7
+ data.tar.gz: 272d6f5dbdc9a3e0b3963cf06f818b1f8c5dcff5212a6077134c5cca5ee50af9aa4897866fff7948c3d8a807d88b1a8ba040eae43ff463d06cbc0dba9c551334
@@ -18,9 +18,9 @@ module ContactSync
18
18
  end
19
19
  end
20
20
  def sync_contacts(contact_hash = {})
21
- result = {:new => {success:[], failed:[]}, modified: {success:[], failed:[]}, deleted: {success:[], failed:[]}}
21
+ result = {:new => {success:[], failed:[], duplicate: []}, modified: {success:[], failed:[]}, deleted: {success:[], failed:[]}}
22
22
  raise ArgumentError, "You need to provide contacts hash." if contact_hash.blank?
23
-
23
+ raise ArgumentError, "You need to provide Device Identifier as deviceID" if contact_hash[:device_id].blank?
24
24
  ##########################################################################
25
25
  #########################Create new Contacts##############################
26
26
  if !contact_hash[:new].blank?
@@ -31,23 +31,28 @@ module ContactSync
31
31
 
32
32
  aContact.delete :phones
33
33
  aContact.delete :emails
34
-
35
- newContact = Contact.new(contact_params(aContact))
36
- if phones
37
- phones.each do |aPhone|
38
- newContact.phones.build(phone_params(aPhone))
34
+ begin
35
+ newContact = Contact.new(contact_params(aContact))
36
+ newContact.device_id = contact_hash[:device_id]
37
+ if phones
38
+ phones.each do |aPhone|
39
+ newContact.phones.build(phone_params(aPhone))
40
+ end
39
41
  end
40
- end
41
- if emails
42
- emails.each do |anEmail|
43
- newContact.emails.build(email_params(anEmail))
42
+ if emails
43
+ emails.each do |anEmail|
44
+ newContact.emails.build(email_params(anEmail))
45
+ end
44
46
  end
45
- end
46
- if newContact.save
47
- # result[:new][:success] << newContact.record_id
48
- self.contacts << newContact
49
- else
50
- result[:new][:failed] << newContact.record_id
47
+ if newContact.save
48
+ # result[:new][:success] << newContact.record_id
49
+ self.contacts << newContact
50
+ else
51
+ result[:new][:failed] << newContact.record_id
52
+ end
53
+ rescue ActiveRecord::RecordNotUnique => e
54
+ puts "Rescuing Duplicate Record"
55
+ result[:new][:duplicate] << newContact.record_id
51
56
  end
52
57
  end
53
58
  end
@@ -139,11 +144,11 @@ module ContactSync
139
144
  end
140
145
 
141
146
  def phone_params aPhone
142
- aPhone.permit(:label, :number)
147
+ aPhone.permit(:label, :number, :encrypted_number, :cc_prefix)
143
148
  end
144
149
 
145
150
  def email_params anEmail
146
- anEmail.permit(:label, :email)
151
+ anEmail.permit(:label, :email, :encrypted_email)
147
152
  end
148
153
 
149
154
  def after_contact_sync
@@ -1,3 +1,3 @@
1
1
  module ContactSync
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contact_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saad Masood