contact_sync 1.4.6 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +24 -22
  3. data/lib/contact_sync.rb +0 -1
  4. data/lib/contact_sync/engine.rb +7 -0
  5. data/lib/contact_sync/syncable.rb +10 -0
  6. data/lib/contact_sync/version.rb +1 -1
  7. data/lib/generators/install_contact_sync/templates/contact.rb +0 -64
  8. data/lib/generators/install_contact_sync/templates/phone.rb +18 -8
  9. data/{test → spec}/dummy/README.rdoc +0 -0
  10. data/{test → spec}/dummy/Rakefile +0 -0
  11. data/{test → spec}/dummy/app/assets/javascripts/application.js +0 -0
  12. data/{test → spec}/dummy/app/assets/stylesheets/application.css +0 -0
  13. data/{test → spec}/dummy/app/controllers/application_controller.rb +0 -0
  14. data/{test → spec}/dummy/app/helpers/application_helper.rb +0 -0
  15. data/spec/dummy/app/models/address.rb +5 -0
  16. data/spec/dummy/app/models/contact.rb +10 -0
  17. data/spec/dummy/app/models/email.rb +14 -0
  18. data/spec/dummy/app/models/phone.rb +41 -0
  19. data/spec/dummy/app/models/routes.rb +9 -0
  20. data/spec/dummy/app/models/user.rb +4 -0
  21. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  22. data/{test → spec}/dummy/bin/bundle +0 -0
  23. data/{test → spec}/dummy/bin/rails +0 -0
  24. data/{test → spec}/dummy/bin/rake +0 -0
  25. data/{test → spec}/dummy/bin/setup +0 -0
  26. data/{test → spec}/dummy/config.ru +0 -0
  27. data/{test → spec}/dummy/config/application.rb +13 -3
  28. data/{test → spec}/dummy/config/boot.rb +0 -0
  29. data/{test → spec}/dummy/config/database.yml +0 -0
  30. data/{test → spec}/dummy/config/environment.rb +0 -0
  31. data/{test → spec}/dummy/config/environments/development.rb +0 -0
  32. data/{test → spec}/dummy/config/environments/production.rb +0 -0
  33. data/{test → spec}/dummy/config/environments/test.rb +0 -0
  34. data/{test → spec}/dummy/config/initializers/assets.rb +0 -0
  35. data/{test → spec}/dummy/config/initializers/backtrace_silencers.rb +0 -0
  36. data/{test → spec}/dummy/config/initializers/cookies_serializer.rb +0 -0
  37. data/{test → spec}/dummy/config/initializers/filter_parameter_logging.rb +0 -0
  38. data/{test → spec}/dummy/config/initializers/inflections.rb +0 -0
  39. data/{test → spec}/dummy/config/initializers/mime_types.rb +0 -0
  40. data/spec/dummy/config/initializers/session_store.rb +3 -0
  41. data/{test → spec}/dummy/config/initializers/wrap_parameters.rb +0 -0
  42. data/{test → spec}/dummy/config/locales/en.yml +0 -0
  43. data/{test → spec}/dummy/config/routes.rb +0 -0
  44. data/{test → spec}/dummy/config/secrets.yml +3 -3
  45. data/spec/dummy/db/development.sqlite3 +0 -0
  46. data/spec/dummy/db/migrate/20150520065844_create_contact_sync_schema.rb +70 -0
  47. data/spec/dummy/db/migrate/20150529072537_remove_device_id_from_contacts.rb +7 -0
  48. data/spec/dummy/db/schema.rb +74 -0
  49. data/spec/dummy/db/test.sqlite3 +0 -0
  50. data/spec/dummy/log/development.log +186 -0
  51. data/spec/dummy/log/test.log +386 -0
  52. data/{test → spec}/dummy/public/404.html +0 -0
  53. data/{test → spec}/dummy/public/422.html +0 -0
  54. data/{test → spec}/dummy/public/500.html +0 -0
  55. data/{test → spec}/dummy/public/favicon.ico +0 -0
  56. data/spec/factories/contact_factory.rb +18 -0
  57. data/spec/factories/user_factory.rb +7 -0
  58. data/spec/rails_helper.rb +82 -0
  59. data/spec/spec_helper.rb +92 -0
  60. data/spec/string_phone_spec.rb +15 -0
  61. metadata +152 -82
  62. data/test/con_sync_test.rb +0 -7
  63. data/test/dummy/config/initializers/session_store.rb +0 -3
  64. data/test/dummy/db/schema.rb +0 -17
  65. data/test/integration/navigation_test.rb +0 -10
  66. data/test/lib/generators/con_sync/install_con_sync_generator_test.rb +0 -16
  67. data/test/test_helper.rb +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc9551dbfc1bc07e1292297af8f959ec5b0f9787
4
- data.tar.gz: ba61bff7f392f4b4083a450e7ffaba57cc6b36fe
3
+ metadata.gz: 2929c9d455765385b5821e644c0ffab4dffeca62
4
+ data.tar.gz: 8148f5288906d279c7111e5f708a16494cc6fc25
5
5
  SHA512:
6
- metadata.gz: 7d302fe48e68023d8ab08e906f06c3f50410c63c68a26d3f22a3cc2a32a58bd1f5bad619bcc91528b6343e1bcc8eff4614e3c7821f4c23eb0053e3dbcbe7f775
7
- data.tar.gz: 9156b43b574e7ec4a8b2f1bef21913041d4f3bb01a13220f8aa1d72d292d625b0d53ca3dae7169a5795f457aef6513be321dd9411f6d775dc0c8dda7cac0e044
6
+ metadata.gz: 24c507f52f602d35f982cff0ffa2354e22e497b445c148fdaf24141009f510f56044e27ef2466589775418ef9f8599ad854c0d5c3511b531a8421b253e718629
7
+ data.tar.gz: c077c847af5039e6d04d949ecdd6331169f356bf5af5cc22933b8e3e40eb4c6cbc9348dbb22b719665afc683ba30d08f587b227c7145ae0bd5cefbe831670368
data/Rakefile CHANGED
@@ -1,37 +1,39 @@
1
+ #!/usr/bin/env rake
1
2
  begin
2
3
  require 'bundler/setup'
3
4
  rescue LoadError
4
5
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
6
  end
6
-
7
- require 'rdoc/task'
8
-
9
- RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'ContactSync'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.rdoc')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
15
- end
16
-
17
- APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
7
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
8
  load 'rails/tasks/engine.rake'
19
9
 
20
10
 
21
- load 'rails/tasks/statistics.rake'
22
-
11
+ Bundler::GemHelper.install_tasks
12
+ Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
13
+ require 'bundler/gem_tasks'
23
14
 
15
+ require 'rspec/core'
16
+ require 'rspec/core/rake_task'
24
17
 
25
- Bundler::GemHelper.install_tasks
18
+ load 'rails/tasks/statistics.rake' #what is this?
26
19
 
27
- require 'rake/testtask'
20
+ desc "Run all specs in spec directory (excluding plugin specs)"
21
+ RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
22
+ task :default => :spec
28
23
 
29
- Rake::TestTask.new(:test) do |t|
30
- t.libs << 'lib'
31
- t.libs << 'test'
32
- t.pattern = 'test/**/*_test.rb'
33
- t.verbose = false
24
+ # Default directory to look in is `/specs`
25
+ # Run with `rake spec`
26
+ RSpec::Core::RakeTask.new(:spec) do |task|
27
+ task.rspec_opts = ['--color', '--format', 'documentation']
34
28
  end
35
29
 
30
+ task :default => :spec
36
31
 
37
- task default: :test
32
+ require 'rdoc/task'
33
+ RDoc::Task.new(:rdoc) do |rdoc|
34
+ rdoc.rdoc_dir = 'rdoc'
35
+ rdoc.title = 'ContactSync'
36
+ rdoc.options << '--line-numbers'
37
+ rdoc.rdoc_files.include('README.rdoc')
38
+ rdoc.rdoc_files.include('lib/**/*.rb')
39
+ end
@@ -5,7 +5,6 @@ require 'contact_sync/util/global_phone'
5
5
  require 'contact_sync/acts_as_syncable'
6
6
  require 'contact_sync/syncable'
7
7
  require 'encrypted_strings'
8
- require 'pry-rails'
9
8
 
10
9
  module ContactSync
11
10
  end
@@ -1,5 +1,12 @@
1
1
  module ContactSync
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace ContactSync
4
+
5
+ config.generators do |g|
6
+ g.test_framework :rspec
7
+ g.fixture_replacement :factory_girl, :dir => 'spec/factories'
8
+ g.assets false
9
+ g.helper false
10
+ end
4
11
  end
5
12
  end
@@ -68,6 +68,16 @@ module ContactSync
68
68
  modified_contacts.each do |con|
69
69
  theContact = self.contacts.find_by_record_id(con[:record_id])
70
70
  if ! theContact.blank?
71
+ #lets create phone_numbers that have been added in this contact.
72
+ phones = con[:phones]
73
+ phones.each do |ph|
74
+ found_phone = theContact.phones.where(encrypted_number: ph[:number].extract_country_code[-1].encrypt(:symmetric)).limit(1).first
75
+ if !found_phone
76
+ theContact.phones.create(phone_params(ph))
77
+ else
78
+ puts 'modified phone_number is already present. Ignoring situation.'
79
+ end
80
+ end
71
81
  if !theContact.update_attributes(contact_params(con))
72
82
  result[:modified][:failed] << theContact.record_id
73
83
  else
@@ -1,3 +1,3 @@
1
1
  module ContactSync
2
- VERSION = "1.4.6"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -2,73 +2,9 @@ class Contact < ActiveRecord::Base
2
2
 
3
3
  has_many :phones, dependent: :delete_all
4
4
  has_many :emails, :dependent => :delete_all
5
- # has_many :addresses, :dependent => :delete_all
6
- # has_many :instant_messengers, :dependent => :delete_all
7
- # has_many :social_profiles, :dependent => :delete_all
8
5
 
9
6
  belongs_to :user
10
7
  validates_presence_of :user
11
8
  validates :record_id, presence: true, numericality: {:greater_than => 0}
12
9
 
13
- # def jsonNotation
14
- #
15
- # phonesJSON = Array.new
16
- # self.phones.each do |aPhone|
17
- # hh =
18
- # {
19
- # lable: aPhone.label,
20
- # phone_number: aPhone.number
21
- # }
22
- # phonesJSON << hh
23
- # end
24
- #
25
- # emailsJSON = Array.new
26
- #
27
- # self.emails.each do |anEmail|
28
- # hh = {
29
- # label: anEmail.label,
30
- # email: anEmail.email
31
- # }
32
- # emailsJSON << hh
33
- # end
34
- #
35
- # profilesJSON = Array.new
36
- # self.social_profiles.each do |aProfile|
37
- # hh = {
38
- # label: aProfile.label,
39
- # username: aProfile.username
40
- # }
41
- # profilesJSON << hh
42
- # end
43
- #
44
- # messengersJSON = Array.new
45
- # self.instant_messengers.each do |aMessenger|
46
- # hh = {
47
- # label: aMessenger.label,
48
- # username: aMessenger.username
49
- # }
50
- # messengersJSON << hh
51
- # end
52
- #
53
- # contact = {
54
- # first_name: first_name,
55
- # middle_name: middle_name,
56
- # last_name: last_name,
57
- # composite_name: composite_name,
58
- # prefix: prefix,
59
- # suffix: suffix,
60
- # nickname: nickname,
61
- # job_title: job_title,
62
- # department: department,
63
- # birthdate: birthdate,
64
- # note: note,
65
- # creation_date: creation_date,
66
- # modification_date: modification_date,
67
- # phones: phonesJSON,
68
- # emails: emailsJSON,
69
- # social_profiles: profilesJSON,
70
- # instant_messengers: messengersJSON
71
- # }
72
- # return contact
73
- # end
74
10
  end
@@ -1,20 +1,14 @@
1
1
  class Phone < ActiveRecord::Base
2
2
  attr_accessor :number
3
3
  belongs_to :contact
4
+ validate :check_validity
4
5
 
5
6
  def number
6
7
  return self.encrypted_number.try(:decrypt,:symmetric) || ""
7
8
  end
8
9
 
9
- def complete_phone_number
10
- if self.cc_prefix.blank?
11
- "0#{self.number}"
12
- else
13
- "+#{self.cc_prefix}#{self.number}"
14
- end
15
- end
16
-
17
10
  def number=(string)
11
+ puts "Phone Number Received: #{string}"
18
12
  self.cc_prefix, num = string.extract_country_code
19
13
  if num.blank? or num.length < 4
20
14
  self.errors[:phone_number] << "Phone number is not valid"
@@ -24,8 +18,24 @@ class Phone < ActiveRecord::Base
24
18
  self.encrypted_number
25
19
  end
26
20
 
21
+ def complete_phone_number
22
+ if self.cc_prefix.blank?
23
+ "00#{self.phone_number}"
24
+ elsif self.cc_prefix == "0"
25
+ "#{self.cc_prefix}#{self.phone_number}"
26
+ else
27
+ "+#{self.cc_prefix}#{self.phone_number}"
28
+ end
29
+ end
30
+
27
31
  def save_with_format!
28
32
  save_with_format
29
33
  save
30
34
  end
35
+ private
36
+ def check_validity
37
+ if encrypted_number.blank? or number.size < 5
38
+ errors[:number] << "Phone number is invalid"
39
+ end
40
+ end
31
41
  end
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ class Address < ActiveRecord::Base
2
+
3
+ belongs_to :contact
4
+
5
+ end
@@ -0,0 +1,10 @@
1
+ class Contact < ActiveRecord::Base
2
+
3
+ has_many :phones, dependent: :delete_all
4
+ has_many :emails, :dependent => :delete_all
5
+
6
+ belongs_to :user
7
+ validates_presence_of :user
8
+ validates :record_id, presence: true, numericality: {:greater_than => 0}
9
+
10
+ end
@@ -0,0 +1,14 @@
1
+ class Email < ActiveRecord::Base
2
+
3
+ belongs_to :contact
4
+
5
+ def email
6
+ return self.encrypted_email.decrypt(:symmetric)
7
+ end
8
+
9
+ def email=(string)
10
+ self.encrypted_email = string.encrypt(:symmetric)
11
+ self.encrypted_email
12
+ end
13
+
14
+ end
@@ -0,0 +1,41 @@
1
+ class Phone < ActiveRecord::Base
2
+ attr_accessor :number
3
+ belongs_to :contact
4
+ validate :check_validity
5
+
6
+ def number
7
+ return self.encrypted_number.try(:decrypt,:symmetric) || ""
8
+ end
9
+
10
+ def number=(string)
11
+ puts "Phone Number Received: #{string}"
12
+ self.cc_prefix, num = string.extract_country_code
13
+ if num.blank? or num.length < 4
14
+ self.errors[:phone_number] << "Phone number is not valid"
15
+ return
16
+ end
17
+ self.encrypted_number = num.encrypt(:symmetric)
18
+ self.encrypted_number
19
+ end
20
+
21
+ def complete_phone_number
22
+ if self.cc_prefix.blank?
23
+ "00#{self.phone_number}"
24
+ elsif self.cc_prefix == "0"
25
+ "#{self.cc_prefix}#{self.phone_number}"
26
+ else
27
+ "+#{self.cc_prefix}#{self.phone_number}"
28
+ end
29
+ end
30
+
31
+ def save_with_format!
32
+ save_with_format
33
+ save
34
+ end
35
+ private
36
+ def check_validity
37
+ if encrypted_number.blank? or number.size < 5
38
+ errors[:number] << "Phone number is invalid"
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,9 @@
1
+
2
+ namespace :api do
3
+ scope module: :v1, constraints: ApiConstraints.new(version: 1, default: :true) do
4
+ resources :users, only: [] do
5
+ post :sync_contacts
6
+ get :match_contacts
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ class User < ActiveRecord::Base
2
+ acts_as_syncable
3
+ has_many :contacts
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>TestApp</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,11 +1,17 @@
1
1
  require File.expand_path('../boot', __FILE__)
2
2
 
3
- require 'rails/all'
3
+ # Pick the frameworks you want:
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_mailer/railtie"
7
+ require "action_view/railtie"
8
+ require "sprockets/railtie"
9
+ # require "rails/test_unit/railtie"
4
10
 
5
11
  Bundler.require(*Rails.groups)
6
12
  require "contact_sync"
7
13
 
8
- module Dummy
14
+ module TestApp
9
15
  class Application < Rails::Application
10
16
  # Settings in config/environments/* take precedence over those specified here.
11
17
  # Application configuration should go into files in config/initializers
@@ -21,6 +27,10 @@ module Dummy
21
27
 
22
28
  # Do not swallow errors in after_commit/after_rollback callbacks.
23
29
  config.active_record.raise_in_transactional_callbacks = true
30
+
31
+
32
+ EncryptedStrings::SymmetricCipher.default_algorithm = 'aes-256-cbc'
33
+ EncryptedStrings::SymmetricCipher.default_password = 'dkljf84fklj09wfkj09rj0cnwjer09c2u3hf9w8nfiojesdpsfpcndsfjs'
34
+
24
35
  end
25
36
  end
26
-
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Rails.application.config.session_store :cookie_store, key: '_test_app_session'
File without changes
@@ -11,12 +11,12 @@
11
11
  # if you're sharing your code publicly.
12
12
 
13
13
  development:
14
- secret_key_base: f458b4bc886ef02ad5f76a1c5495fc6d5b14479e000d1054ab0f289e29c46a8de1ce93192ca08d3fca6437df51276eb5635e8a4a08d27b19950c2ed7e60c1e55
14
+ secret_key_base: d55e5b24d007be0f96e6bd46ef59dc022b1244e86a424ba85430009d77be0aa97bc77c0284b69012bba89a781cebba1be8dcf72c514376206d6b9760e5e4a7f2
15
15
 
16
16
  test:
17
- secret_key_base: 1329b6d0e19167547b93702b51e468196fd0af4e56415e38a8ef5aa17f19b4613f53878b08b6b0ffb2875356537e095d14d3673b793e8fc717f046caf65c5e30
17
+ secret_key_base: 725a51723ba99807a2b6474d8c7f8cc5b753a7f3ca3f2e678a37592d2ac6d3bfe8e3e779104c45bb03075fcfa4a484aaafc94121bae81258c772a16a0858e2aa
18
18
 
19
19
  # Do not keep production secrets in the repository,
20
20
  # instead read values from the environment.
21
21
  production:
22
- secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
22
+ secret_key_base: 725a51723ba99807a2b6474d8c7f8cc5b753a7f3ca3f2e678a37592d2ac6d3bfe8e3e779104c45bb03075fcfa4a484aaafc94121bae81258c772a16a0858e2dd