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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6a13eab9494ce02c4ed2383fed93a19bf974750a
4
+ data.tar.gz: 784c0401f79dc6351b927d08ce2f0c869c2e4b74
5
+ SHA512:
6
+ metadata.gz: eea48734a97585d94d5b38ad0dacb569966168dfc8f2e0f0370e4cd481a368a8f394e0f9f83462800be08e56d366abc0f55ad1a5c00ff39bc92c67fc38ede75e
7
+ data.tar.gz: b9049ae00d0f73dd513f4f9b259371a75c8e64f9699aedb6a9ecaf6d6e5f6c56e6003f5d912d7ef06431be12de69249feeb08629242503419a853fe3b0789d38
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Alexandre Moraes
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ = Digitalforce
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Digitalforce'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,8 @@
1
+ require 'restforce'
2
+
3
+ # Concerns
4
+ require 'digitalforce/concerns/contact'
5
+ require 'digitalforce/concerns/account'
6
+
7
+ module Digitalforce
8
+ end
@@ -0,0 +1,9 @@
1
+ module Digitalforce
2
+ module Base
3
+ module Connection
4
+ def self.connect(*args)
5
+ Restforce.new *args
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,47 @@
1
+ require 'digitalforce/base/connection'
2
+
3
+ module Digitalforce
4
+ module Concerns
5
+ module Account
6
+
7
+ extend ActiveSupport::Concern
8
+
9
+ attr_accessor :client
10
+
11
+ included do
12
+ before_save :manage_salesforce_account_creation
13
+ before_destroy :manage_salesforce_account_destroy
14
+ end
15
+
16
+ module ClassMethods
17
+
18
+ def acts_as_account(options = {})
19
+ cattr_accessor :client
20
+ self.client = Digitalforce::Base::Connection.connect options[:connection]
21
+ end
22
+
23
+ def get_salesforce_accounts
24
+ cattr_accessor :client
25
+ self.client.query("SELECT Id, name FROM Account")
26
+ end
27
+
28
+ end
29
+
30
+ def manage_salesforce_account_creation
31
+ if self.new_record? && !self.s_id?
32
+ @accountId = self.client.create('Account', Name: self.name)
33
+ self.s_id = @accountId
34
+ else
35
+ self.client.update('Account', Id: self.s_id, Name: self.name)
36
+ end
37
+ end
38
+
39
+ def manage_salesforce_account_destroy
40
+ if self.s_id
41
+ self.client.destroy('Account', self.s_id)
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,47 @@
1
+ require 'digitalforce/base/connection'
2
+
3
+ module Digitalforce
4
+ module Concerns
5
+ module Contact
6
+
7
+ extend ActiveSupport::Concern
8
+
9
+ attr_accessor :client
10
+
11
+ included do
12
+ before_save :manage_salesforce_contact_creation
13
+ before_destroy :manage_salesforce_contact_destroy
14
+ end
15
+
16
+ module ClassMethods
17
+
18
+ def acts_as_contact(options = {})
19
+ cattr_accessor :client
20
+ self.client = Digitalforce::Base::Connection.connect options[:connection]
21
+ end
22
+
23
+ def get_salesforce_contacts
24
+ cattr_accessor :client
25
+ self.client.query("SELECT Id, firstName, email, lastName, accountId, phone FROM Contact")
26
+ end
27
+
28
+ end
29
+
30
+ def manage_salesforce_contact_creation
31
+ if self.new_record? && !self.s_id?
32
+ @userId = self.client.create('Contact', FirstName: self.name, LastName: self.last_name, AccountId: self.account_id, Email: self.email, Phone: self.phone)
33
+ self.s_id = @userId
34
+ else
35
+ self.client.update('Contact', Id: self.s_id, FirstName: self.name, LastName: self.last_name, AccountId: self.account_id, Email: self.email, Phone: self.phone)
36
+ end
37
+ end
38
+
39
+ def manage_salesforce_contact_destroy
40
+ if self.s_id?
41
+ self.client.destroy('Contact', self.s_id)
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module Digitalforce
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :digitalforce do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ class AccountsTest < ActiveSupport::TestCase
4
+
5
+ # Create/Delete an account
6
+ test "create/delete account" do
7
+
8
+ account = Account.new(name: "Doe Company")
9
+
10
+ account.save
11
+
12
+ savedAccount = Account.find_by(name: "Doe Company")
13
+
14
+ assert_not_nil savedAccount
15
+
16
+ assert savedAccount.destroy
17
+
18
+ end
19
+
20
+ # Create a contact with wrong salesforce parameters
21
+ test "create account with wrong salesforce config parameters" do
22
+
23
+ Account.acts_as_account connection: {
24
+ :username => 'dummy@force.com',
25
+ :password => 'dummy',
26
+ :security_token => 'dummy',
27
+ :client_id => 'dummy',
28
+ :client_secret => 'dummy'
29
+ }
30
+
31
+ account = Account.new()
32
+
33
+ assert_raises(Restforce::AuthenticationError) { account.save }
34
+
35
+ Account.acts_as_account connection: Dummy::Application.config.salesforce_config
36
+
37
+ end
38
+
39
+ # Get list of accounts from salesforce
40
+ test "get accounts list" do
41
+
42
+ salesforce_accounts = Account.get_salesforce_accounts
43
+
44
+ assert_not_empty salesforce_accounts.first
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ class AccountsTest < ActiveSupport::TestCase
4
+
5
+ # Create/Delete a contact
6
+ test "create/delete contact" do
7
+
8
+ user = User.new(name: "John", last_name: "Doe", account_id: "001o000000SLPXiAAP", email: "jdoe@dummy.com", phone: "555 555 555")
9
+
10
+ user.save
11
+
12
+ savedUser = User.find_by(name: "John", last_name: "Doe")
13
+
14
+ assert_not_nil savedUser
15
+
16
+ assert savedUser.destroy
17
+
18
+ end
19
+
20
+ # Create a contact with wrong salesforce parameters
21
+ test "create contact with wrong salesforce config parameters" do
22
+
23
+ User.acts_as_contact connection: {
24
+ :username => 'dummy@force.com',
25
+ :password => 'dummy',
26
+ :security_token => 'dummy',
27
+ :client_id => 'dummy',
28
+ :client_secret => 'dummy'
29
+ }
30
+
31
+ user = User.new()
32
+
33
+ assert_raises(Restforce::AuthenticationError) { user.save }
34
+
35
+ User.acts_as_contact connection: Dummy::Application.config.salesforce_config
36
+
37
+ end
38
+
39
+ # Get list of contacts from salesforce
40
+ test "get contacts list" do
41
+
42
+ salesforce_contacts = User.get_salesforce_contacts
43
+
44
+ assert_not_empty salesforce_contacts.first
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ class DigitalforceTest < ActiveSupport::TestCase
4
+
5
+ # Tries to create a contact without all required parameters in salesforce_config
6
+ test "create contact without all required parameters" do
7
+ User.acts_as_contact connection: {:username => "johndoe@gmail.com"}
8
+
9
+ user = User.new()
10
+
11
+ assert_raises(ArgumentError) { user.save }
12
+
13
+ User.acts_as_contact connection: Dummy::Application.config.salesforce_config
14
+ end
15
+
16
+ # Check if all required parameters in salesforce_config are present
17
+ test "check if salesforce have all required parameters" do
18
+ config = Dummy::Application.config.salesforce_config
19
+ assert (
20
+ config.has_key?(:username) &&
21
+ config.has_key?(:password) &&
22
+ config.has_key?(:security_token) &&
23
+ config.has_key?(:client_id) &&
24
+ config.has_key?(:client_secret)
25
+ )
26
+ end
27
+
28
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,84 @@
1
+ class AccountsController < ApplicationController
2
+ before_action :set_account, only: [:show, :edit, :update, :destroy]
3
+
4
+ def sync
5
+
6
+ Account.sync
7
+
8
+ redirect_to accounts_path
9
+
10
+ end
11
+
12
+ # GET /accounts
13
+ # GET /accounts.json
14
+ def index
15
+
16
+ @accounts = Account.all
17
+
18
+ end
19
+
20
+ # GET /accounts/1
21
+ # GET /accounts/1.json
22
+ def show
23
+ end
24
+
25
+ # GET /accounts/new
26
+ def new
27
+ @account = Account.new
28
+ end
29
+
30
+ # GET /accounts/1/edit
31
+ def edit
32
+ end
33
+
34
+ # POST /accounts
35
+ # POST /accounts.json
36
+ def create
37
+ @account = Account.new(account_params)
38
+
39
+ respond_to do |format|
40
+ if @account.save
41
+ format.html { redirect_to @account, notice: 'Account was successfully created.' }
42
+ format.json { render :show, status: :created, location: @account }
43
+ else
44
+ format.html { render :new }
45
+ format.json { render json: @account.errors, status: :unprocessable_entity }
46
+ end
47
+ end
48
+ end
49
+
50
+ # PATCH/PUT /accounts/1
51
+ # PATCH/PUT /accounts/1.json
52
+ def update
53
+ respond_to do |format|
54
+ if @account.update(account_params)
55
+ format.html { redirect_to @account, notice: 'Account was successfully updated.' }
56
+ format.json { render :show, status: :ok, location: @account }
57
+ else
58
+ format.html { render :edit }
59
+ format.json { render json: @account.errors, status: :unprocessable_entity }
60
+ end
61
+ end
62
+ end
63
+
64
+ # DELETE /accounts/1
65
+ # DELETE /accounts/1.json
66
+ def destroy
67
+ @account.destroy
68
+ respond_to do |format|
69
+ format.html { redirect_to accounts_url, notice: 'Account was successfully destroyed.' }
70
+ format.json { head :no_content }
71
+ end
72
+ end
73
+
74
+ private
75
+ # Use callbacks to share common setup or constraints between actions.
76
+ def set_account
77
+ @account = Account.find(params[:id])
78
+ end
79
+
80
+ # Never trust parameters from the scary internet, only allow the white list through.
81
+ def account_params
82
+ params.require(:account).permit(:name)
83
+ end
84
+ end