digitalforce 0.0.1

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 (55) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +34 -0
  5. data/lib/digitalforce.rb +8 -0
  6. data/lib/digitalforce/base/connection.rb +9 -0
  7. data/lib/digitalforce/concerns/account.rb +47 -0
  8. data/lib/digitalforce/concerns/contact.rb +47 -0
  9. data/lib/digitalforce/version.rb +3 -0
  10. data/lib/tasks/digitalforce_tasks.rake +4 -0
  11. data/test/accounts_test.rb +48 -0
  12. data/test/contacts_test.rb +48 -0
  13. data/test/digitalforce_test.rb +28 -0
  14. data/test/dummy/README.rdoc +28 -0
  15. data/test/dummy/Rakefile +6 -0
  16. data/test/dummy/app/assets/javascripts/application.js +13 -0
  17. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  18. data/test/dummy/app/controllers/accounts_controller.rb +84 -0
  19. data/test/dummy/app/controllers/application_controller.rb +5 -0
  20. data/test/dummy/app/controllers/users_controller.rb +82 -0
  21. data/test/dummy/app/helpers/application_helper.rb +2 -0
  22. data/test/dummy/app/models/account.rb +41 -0
  23. data/test/dummy/app/models/user.rb +41 -0
  24. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  25. data/test/dummy/bin/bundle +3 -0
  26. data/test/dummy/bin/rails +4 -0
  27. data/test/dummy/bin/rake +4 -0
  28. data/test/dummy/bin/setup +29 -0
  29. data/test/dummy/config.ru +4 -0
  30. data/test/dummy/config/application.rb +34 -0
  31. data/test/dummy/config/boot.rb +5 -0
  32. data/test/dummy/config/database.yml +84 -0
  33. data/test/dummy/config/environment.rb +5 -0
  34. data/test/dummy/config/environments/development.rb +41 -0
  35. data/test/dummy/config/environments/production.rb +79 -0
  36. data/test/dummy/config/environments/test.rb +42 -0
  37. data/test/dummy/config/initializers/assets.rb +11 -0
  38. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  39. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  40. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  41. data/test/dummy/config/initializers/inflections.rb +16 -0
  42. data/test/dummy/config/initializers/mime_types.rb +4 -0
  43. data/test/dummy/config/initializers/session_store.rb +3 -0
  44. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  45. data/test/dummy/config/locales/en.yml +23 -0
  46. data/test/dummy/config/routes.rb +56 -0
  47. data/test/dummy/config/secrets.yml +22 -0
  48. data/test/dummy/db/migrate/20150328200612_create_tables.rb +27 -0
  49. data/test/dummy/db/schema.rb +40 -0
  50. data/test/dummy/public/404.html +67 -0
  51. data/test/dummy/public/422.html +67 -0
  52. data/test/dummy/public/500.html +66 -0
  53. data/test/dummy/public/favicon.ico +0 -0
  54. data/test/test_helper.rb +19 -0
  55. metadata +183 -0
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,82 @@
1
+ class UsersController < ApplicationController
2
+ before_action :set_user, only: [:show, :edit, :update, :destroy]
3
+
4
+ def sync
5
+
6
+ User.sync
7
+
8
+ redirect_to users_path
9
+
10
+ end
11
+
12
+ # GET /users
13
+ # GET /users.json
14
+ def index
15
+ @users = User.all
16
+ end
17
+
18
+ # GET /users/1
19
+ # GET /users/1.json
20
+ def show
21
+ end
22
+
23
+ # GET /users/new
24
+ def new
25
+ @user = User.new
26
+ end
27
+
28
+ # GET /users/1/edit
29
+ def edit
30
+ end
31
+
32
+ # POST /users
33
+ # POST /users.json
34
+ def create
35
+ @user = User.new(user_params)
36
+
37
+ respond_to do |format|
38
+ if @user.save
39
+ format.html { redirect_to @user, notice: 'User was successfully created.' }
40
+ format.json { render :show, status: :created, location: @user }
41
+ else
42
+ format.html { render :new }
43
+ format.json { render json: @user.errors, status: :unprocessable_entity }
44
+ end
45
+ end
46
+ end
47
+
48
+ # PATCH/PUT /users/1
49
+ # PATCH/PUT /users/1.json
50
+ def update
51
+ respond_to do |format|
52
+ if @user.update(user_params)
53
+ format.html { redirect_to @user, notice: 'User was successfully updated.' }
54
+ format.json { render :show, status: :ok, location: @user }
55
+ else
56
+ format.html { render :edit }
57
+ format.json { render json: @user.errors, status: :unprocessable_entity }
58
+ end
59
+ end
60
+ end
61
+
62
+ # DELETE /users/1
63
+ # DELETE /users/1.json
64
+ def destroy
65
+ @user.destroy
66
+ respond_to do |format|
67
+ format.html { redirect_to users_url, notice: 'User was successfully destroyed.' }
68
+ format.json { head :no_content }
69
+ end
70
+ end
71
+
72
+ private
73
+ # Use callbacks to share common setup or constraints between actions.
74
+ def set_user
75
+ @user = User.find(params[:id])
76
+ end
77
+
78
+ # Never trust parameters from the scary internet, only allow the white list through.
79
+ def user_params
80
+ params.require(:user).permit(:name, :last_name, :email, :company, :job_title, :phone, :website, :account_id)
81
+ end
82
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,41 @@
1
+ class Account < ActiveRecord::Base
2
+
3
+ include Digitalforce::Concerns::Account
4
+
5
+ has_many :users, foreign_key: :account_id, primary_key: :s_id, dependent: :destroy
6
+
7
+ acts_as_account connection: Dummy::Application.config.salesforce_config
8
+
9
+ def self.sync
10
+
11
+ if !Account.isSynced
12
+
13
+ get_salesforce_accounts.each do |account|
14
+ acc_params = {:s_id => account.Id, :name => account.Name}
15
+ if Account.exists?(:s_id => account.Id)
16
+ acc = Account.find(account.Id)
17
+ acc.update(acc_params)
18
+ else
19
+ acc = Account.new(acc_params)
20
+ acc.save
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ def self.isSynced
29
+
30
+ salesforceAccounts = get_salesforce_accounts
31
+ databaseCount = Account.count
32
+
33
+ if salesforceAccounts.count != databaseCount
34
+ false
35
+ else
36
+ true
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,41 @@
1
+ class User < ActiveRecord::Base
2
+
3
+ include Digitalforce::Concerns::Contact
4
+
5
+ belongs_to :User, foreign_key: :User_id, primary_key: :s_id
6
+
7
+ acts_as_contact connection: Dummy::Application.config.salesforce_config
8
+
9
+ def self.sync
10
+
11
+ if !User.isSynced
12
+
13
+ get_salesforce_contacts.each do |contact|
14
+ ctc_params = {:s_id => contact.Id, :name => contact.FirstName, :last_name => contact.LastName, :phone => contact.Phone, :account_id => contact.AccountId}
15
+ if User.exists?(:s_id => contact.Id)
16
+ ctc = User.find(contact.Id)
17
+ ctc.update(ctc_params)
18
+ else
19
+ ctc = User.new(ctc_params)
20
+ ctc.save
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ def self.isSynced
29
+
30
+ salesforceContacts = get_salesforce_contacts
31
+ databaseCount = User.count
32
+
33
+ if salesforceContacts.count != databaseCount
34
+ false
35
+ else
36
+ true
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</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>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby.exe
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby.exe
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby.exe
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby.exe
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts "== Installing dependencies =="
12
+ system "gem install bundler --conservative"
13
+ system "bundle check || bundle install"
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system "bin/rake db:setup"
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system "rm -f log/*"
25
+ system "rm -rf tmp/cache"
26
+
27
+ puts "\n== Restarting application server =="
28
+ system "touch tmp/restart.txt"
29
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,34 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(*Rails.groups)
6
+ require "digitalforce"
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
15
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
16
+ # config.time_zone = 'Central Time (US & Canada)'
17
+
18
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
+ # config.i18n.default_locale = :de
21
+
22
+ # Do not swallow errors in after_commit/after_rollback callbacks.
23
+ config.active_record.raise_in_transactional_callbacks = true
24
+
25
+ config.salesforce_config = {
26
+ :username => '',
27
+ :password => '',
28
+ :security_token => '',
29
+ :client_id => '',
30
+ :client_secret => ''
31
+ }
32
+
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,84 @@
1
+ # PostgreSQL. Versions 8.2 and up are supported.
2
+ #
3
+ # Install the pg driver:
4
+ # gem install pg
5
+ # On OS X with Homebrew:
6
+ # gem install pg -- --with-pg-config=/usr/local/bin/pg_config
7
+ # On OS X with MacPorts:
8
+ # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
9
+ # On Windows:
10
+ # gem install pg
11
+ # Choose the win32 build.
12
+ # Install PostgreSQL and put its /bin directory on your path.
13
+ #
14
+ # Configure Using Gemfile
15
+ # gem 'pg'
16
+ #
17
+ default: &default
18
+ adapter: postgresql
19
+ encoding: unicode
20
+ # For details on connection pooling, see rails configuration guide
21
+ # http://guides.rubyonrails.org/configuring.html#database-pooling
22
+ pool: 5
23
+ database: dummy
24
+ user: dummy
25
+ password: dummy
26
+ host: localhost
27
+
28
+ development:
29
+ <<: *default
30
+
31
+ # The specified database role being used to connect to postgres.
32
+ # To create additional roles in postgres see `$ createuser --help`.
33
+ # When left blank, postgres will use the default role. This is
34
+ # the same name as the operating system user that initialized the database.
35
+ #username: dummy
36
+
37
+ # The password associated with the postgres role (username).
38
+ #password:
39
+
40
+ # Connect on a TCP socket. Omitted by default since the client uses a
41
+ # domain socket that doesn't need configuration. Windows does not have
42
+ # domain sockets, so uncomment these lines.
43
+ #host: localhost
44
+
45
+ # The TCP port the server listens on. Defaults to 5432.
46
+ # If your server runs on a different port number, change accordingly.
47
+ #port: 5432
48
+
49
+ # Schema search path. The server defaults to $user,public
50
+ #schema_search_path: myapp,sharedapp,public
51
+
52
+ # Minimum log levels, in increasing order:
53
+ # debug5, debug4, debug3, debug2, debug1,
54
+ # log, notice, warning, error, fatal, and panic
55
+ # Defaults to warning.
56
+ #min_messages: notice
57
+
58
+ # Warning: The database defined as "test" will be erased and
59
+ # re-generated from your development database when you run "rake".
60
+ # Do not set this db to the same as development or production.
61
+ test:
62
+ <<: *default
63
+
64
+ # As with config/secrets.yml, you never want to store sensitive information,
65
+ # like your database password, in your source code. If your source code is
66
+ # ever seen by anyone, they now have access to your database.
67
+ #
68
+ # Instead, provide the password as a unix environment variable when you boot
69
+ # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
70
+ # for a full rundown on how to provide these environment variables in a
71
+ # production deployment.
72
+ #
73
+ # On Heroku and other platform providers, you may have a full connection URL
74
+ # available as an environment variable. For example:
75
+ #
76
+ # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
77
+ #
78
+ # You can use this database configuration with:
79
+ #
80
+ # production:
81
+ # url: <%= ENV['DATABASE_URL'] %>
82
+ #
83
+ production:
84
+ <<: *default
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,41 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
+
12
+ # Show full error reports and disable caching.
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send.
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger.
20
+ config.active_support.deprecation = :log
21
+
22
+ # Raise an error on page load if there are pending migrations.
23
+ config.active_record.migration_error = :page_load
24
+
25
+ # Debug mode disables concatenation and preprocessing of assets.
26
+ # This option may cause significant delays in view rendering with a large
27
+ # number of complex assets.
28
+ config.assets.debug = true
29
+
30
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
31
+ # yet still be able to expire them through the digest params.
32
+ config.assets.digest = true
33
+
34
+ # Adds additional error checking when serving assets at runtime.
35
+ # Checks for improperly declared sprockets dependencies.
36
+ # Raises helpful error messages.
37
+ config.assets.raise_runtime_errors = true
38
+
39
+ # Raises error for missing translations
40
+ # config.action_view.raise_on_missing_translations = true
41
+ end
@@ -0,0 +1,79 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # Code is not reloaded between requests.
5
+ config.cache_classes = true
6
+
7
+ # Eager load code on boot. This eager loads most of Rails and
8
+ # your application in memory, allowing both threaded web servers
9
+ # and those relying on copy on write to perform better.
10
+ # Rake tasks automatically ignore this option for performance.
11
+ config.eager_load = true
12
+
13
+ # Full error reports are disabled and caching is turned on.
14
+ config.consider_all_requests_local = false
15
+ config.action_controller.perform_caching = true
16
+
17
+ # Enable Rack::Cache to put a simple HTTP cache in front of your application
18
+ # Add `rack-cache` to your Gemfile before enabling this.
19
+ # For large-scale production use, consider using a caching reverse proxy like
20
+ # NGINX, varnish or squid.
21
+ # config.action_dispatch.rack_cache = true
22
+
23
+ # Disable serving static files from the `/public` folder by default since
24
+ # Apache or NGINX already handles this.
25
+ config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
26
+
27
+ # Compress JavaScripts and CSS.
28
+ config.assets.js_compressor = :uglifier
29
+ # config.assets.css_compressor = :sass
30
+
31
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
32
+ config.assets.compile = false
33
+
34
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
35
+ # yet still be able to expire them through the digest params.
36
+ config.assets.digest = true
37
+
38
+ # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
39
+
40
+ # Specifies the header that your server uses for sending files.
41
+ # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
42
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
43
+
44
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
45
+ # config.force_ssl = true
46
+
47
+ # Use the lowest log level to ensure availability of diagnostic information
48
+ # when problems arise.
49
+ config.log_level = :debug
50
+
51
+ # Prepend all log lines with the following tags.
52
+ # config.log_tags = [ :subdomain, :uuid ]
53
+
54
+ # Use a different logger for distributed setups.
55
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
56
+
57
+ # Use a different cache store in production.
58
+ # config.cache_store = :mem_cache_store
59
+
60
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
61
+ # config.action_controller.asset_host = 'http://assets.example.com'
62
+
63
+ # Ignore bad email addresses and do not raise email delivery errors.
64
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
65
+ # config.action_mailer.raise_delivery_errors = false
66
+
67
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
68
+ # the I18n.default_locale when a translation cannot be found).
69
+ config.i18n.fallbacks = true
70
+
71
+ # Send deprecation notices to registered listeners.
72
+ config.active_support.deprecation = :notify
73
+
74
+ # Use default logging formatter so that PID and timestamp are not suppressed.
75
+ config.log_formatter = ::Logger::Formatter.new
76
+
77
+ # Do not dump schema after migrations.
78
+ config.active_record.dump_schema_after_migration = false
79
+ end