salesforce-rails 1.0.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 (34) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +28 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +10 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +48 -0
  8. data/Rakefile +8 -0
  9. data/app/assets/javascripts/salesforce-calendar.js +3 -0
  10. data/app/assets/javascripts/salesforce/fullcalendar.min.js +7 -0
  11. data/app/assets/javascripts/salesforce/jquery.browser.min.js +14 -0
  12. data/app/assets/javascripts/salesforce/qtip.min.js +21 -0
  13. data/app/assets/stylesheets/salesforce-calendar.css +4 -0
  14. data/app/assets/stylesheets/salesforce/calendar.css +35 -0
  15. data/app/assets/stylesheets/salesforce/fullcalendar.css +589 -0
  16. data/app/assets/stylesheets/salesforce/fullcalendar.print.css +32 -0
  17. data/lib/generators/salesforce/calendar/install/install_generator.rb +50 -0
  18. data/lib/generators/salesforce/calendar/install/templates/calendar.html.erb +53 -0
  19. data/lib/generators/salesforce/calendar/install/templates/salesforce_controller.rb.erb +10 -0
  20. data/lib/generators/salesforce/config/config_generator.rb +12 -0
  21. data/lib/generators/salesforce/config/templates/salesforce.yml +32 -0
  22. data/lib/salesforce-rails.rb +1 -0
  23. data/lib/salesforce/rails.rb +10 -0
  24. data/lib/salesforce/rails/api/calendar_event.rb +25 -0
  25. data/lib/salesforce/rails/api/client.rb +32 -0
  26. data/lib/salesforce/rails/engine.rb +6 -0
  27. data/lib/salesforce/rails/version.rb +5 -0
  28. data/salesforce-rails.gemspec +33 -0
  29. data/spec/fixtures/salesforce.yml +20 -0
  30. data/spec/lib/salesforce/rails/api/calendar_event_spec.rb +30 -0
  31. data/spec/lib/salesforce/rails/api/client_spec.rb +58 -0
  32. data/spec/rails_mocks.rb +5 -0
  33. data/spec/spec_helper.rb +16 -0
  34. metadata +219 -0
@@ -0,0 +1,32 @@
1
+ /*!
2
+ * FullCalendar v1.6.4 Print Stylesheet
3
+ * Docs & License: http://arshaw.com/fullcalendar/
4
+ * (c) 2013 Adam Shaw
5
+ */
6
+
7
+ /*
8
+ * Include this stylesheet on your page to get a more printer-friendly calendar.
9
+ * When including this stylesheet, use the media='print' attribute of the <link> tag.
10
+ * Make sure to include this stylesheet IN ADDITION to the regular fullcalendar.css.
11
+ */
12
+
13
+
14
+ /* Events
15
+ -----------------------------------------------------*/
16
+
17
+ .fc-event {
18
+ background: #fff !important;
19
+ color: #000 !important;
20
+ }
21
+
22
+ /* for vertical events */
23
+
24
+ .fc-event-bg {
25
+ display: none !important;
26
+ }
27
+
28
+ .fc-event .ui-resizable-handle {
29
+ display: none !important;
30
+ }
31
+
32
+
@@ -0,0 +1,50 @@
1
+ module Salesforce
2
+ module Calendar
3
+ module Generators
4
+ class InstallGenerator < ::Rails::Generators::Base
5
+ desc "This generator installs jQuery Fullcalendar"
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def install
9
+ cleanup!
10
+ append_asset_pipeline!
11
+ setup_routes
12
+ copy_files
13
+ end
14
+
15
+ protected
16
+
17
+ def cleanup!
18
+ # Remove old requires (if any) that included salesforce-calendar directly:
19
+ gsub_file("app/assets/stylesheets/application.css", %r|\s*\*=\s*salesforce-calendar\s*\n|, "")
20
+ gsub_file("app/assets/javascripts/application.js", %r|\s*\//=\s*salesforce-calendar\s*\n|, "")
21
+ gsub_file("app/assets/javascripts/application.js", %r|\s*\//=\s*jquery.browser.min\s*\n|, "")
22
+ gsub_file("app/assets/javascripts/application.js", %r|\s*\//=\s*jquery.browser\s*\n|, "")
23
+ end
24
+
25
+ def append_asset_pipeline!
26
+ application_css = 'app/assets/stylesheets/application.css'
27
+ if File.file?(application_css)
28
+ insert_into_file application_css, "*= require salesforce-calendar\n", :before => " *= require_self"
29
+ end
30
+
31
+ application_js = 'app/assets/javascripts/application.js'
32
+ if File.file?(application_js)
33
+ insert_into_file application_js, "//= require salesforce-calendar\n", :after => "//= require jquery_ujs\n"
34
+ end
35
+ end
36
+
37
+ def setup_routes
38
+ route "get 'calendar', :to => 'salesforce#calendar', :as => :salesforce_calendar"
39
+ route "get 'calendar/json-data', :to => 'salesforce#calendar_json_data', :as => :salesforce_calendar_json_data"
40
+ end
41
+
42
+ def copy_files
43
+ copy_file 'salesforce_controller.rb.erb', File.join('app/controllers', 'salesforce_controller.rb')
44
+ FileUtils.mkdir_p(File.join('app/views', 'salesforce'))
45
+ copy_file 'calendar.html.erb', File.join('app/views', 'salesforce/calendar.html.erb')
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,53 @@
1
+ <% content_for :stylesheets do %>
2
+ <%= stylesheet_link_tag "salesforce/fullcalendar.print", :media => "print" %>
3
+ <% end %>
4
+
5
+ <% content_for :javascripts do %>
6
+ <script type="text/javascript">
7
+ $(document).ready(function() {
8
+ $('#calendar').fullCalendar({
9
+ header: {
10
+ left: 'prev,next today',
11
+ center: 'title',
12
+ right: 'month,basicWeek,basicDay'
13
+ },
14
+ editable: false,
15
+ ignoreTimezone: false,
16
+ events: {
17
+ url: '/calendar/json-data',
18
+ type: 'GET',
19
+ cache: true
20
+ },
21
+ eventRender: function(event, element){
22
+ event.allDay ? $(element).find('.fc-event-title').html('<span style="font-size:0.75em;">'+event.title+'</span><br/>'+event.subject) : $(element).find('.fc-event-title').html('<span style="font-size:0.75em;">'+$.fullCalendar.formatDate(event.start, 'HH:mm')+' - '+$.fullCalendar.formatDate(event.end, 'HH:mm')+'</span><br/>'+event.subject);
23
+
24
+ $(element).qtip({
25
+ content: '<div class="hoverOuter"><div><table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td class="pbTitle"><h2 class="mainTitle">Event Detail</h2></td><td></td></tr></tbody></table></div><div class="sub-section"><table cellspacing="0" cellpadding="0" border="0" style="width:100%;"><tbody><tr><td class="labelCol">Assigned To</td><td class="dataCol">'+event.assign_to+'</td></tr><tr><td class="labelCol">Subject</td><td class="dataCol">'+event.subject+'</td></tr><tr><td class="labelCol">Start</td><td class="dataCol">'+$.fullCalendar.formatDate(new Date(event.start_date), (event.allDay ? "dd/MM/yyyy" : "dd/MM/yyyy HH:mm"))+'</td></tr><tr><td class="labelCol">End</td><td class="dataCol">'+$.fullCalendar.formatDate(new Date(event.end_date), (event.allDay ? "dd/MM/yyyy" : "dd/MM/yyyy HH:mm"))+'</td></tr><tr><td class="labelCol last">Description</td><td class="dataCol last">'+event.description+'</td></tr></tbody></table></div></div>',
26
+ position: {
27
+ corner: {
28
+ target: 'topMiddle',
29
+ tooltip: 'bottomLeft'
30
+ }
31
+ },
32
+ style: {
33
+ width: 350,
34
+ padding: 5,
35
+ background: '#FFFFFF',
36
+ color: 'black',
37
+ textAlign: 'center',
38
+ border: {
39
+ width: 1,
40
+ radius: 5,
41
+ color: '#DDDDDD'
42
+ },
43
+ tip: 'bottomLeft',
44
+ name: 'light' // Inherit the rest of the attributes from the preset dark style
45
+ }
46
+ });
47
+ }
48
+ });
49
+ });
50
+ </script>
51
+ <% end %>
52
+
53
+ <div id="calendar"></div>
@@ -0,0 +1,10 @@
1
+ class SalesforceController < ::ApplicationController
2
+
3
+ def calendar_json_data
4
+ events = Salesforce::Rails::API::CalendarEvent.query("StartDateTime >= #{Time.at(params[:start].to_i).strftime("%Y-%m-%dT%H:%M:%SZ")} and StartDateTime <= #{Time.at(params[:end].to_i).strftime("%Y-%m-%dT%H:%M:%SZ")}")
5
+
6
+ respond_to do |format|
7
+ format.json { render json: events ? events.map { |e| { :id => e.Id, :title => (e.IsAllDayEvent ? "All Day Event" : e.Subject), :allDay => e.IsAllDayEvent, :start => e.StartDateTime, :end => e.EndDateTime, :start_date => e.StartDateTime, :end_date => e.EndDateTime, :color => (e.ShowAs == "Busy" ? "#6777cc" : "#b64b32"), :backgroundColor => (e.ShowAs == "Busy" ? "#6777cc" : "#b64b32"), :subject => e.Subject, :assign_to => e.Owner.Name, :description => e.Description, :show_as => e.ShowAs } } : nil }
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ module Salesforce
2
+ module Generators
3
+ class ConfigGenerator < ::Rails::Generators::Base
4
+ desc 'This generator generate a Salesforce-Rails gem configuration file at config/salesforce.yml'
5
+ source_root File.expand_path("../templates", __FILE__)
6
+
7
+ def create_config_file
8
+ copy_file 'salesforce.yml', File.join('config', 'salesforce.yml')
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,32 @@
1
+ #
2
+ # For authentication purpose needed either :username and :password
3
+ # OR :token and :instance_url pair
4
+ #
5
+ development:
6
+ host: <your_salesforce_host>
7
+ client_secret: <your_salesforce_client_secret>
8
+ client_id: <your_salesforce_client_id>
9
+ username: <your_salesforce_username>
10
+ password: <your_salesforce_password>
11
+ token: <your_salesforce_token>
12
+ instance_url: <your_salesforce_instance_url>
13
+ debugging: true
14
+
15
+ test:
16
+ host: <your_salesforce_host>
17
+ client_secret: <your_salesforce_client_secret>
18
+ client_id: <your_salesforce_client_id>
19
+ username: <your_salesforce_username>
20
+ password: <your_salesforce_password>
21
+ token: <your_salesforce_token>
22
+ instance_url: <your_salesforce_instance_url>
23
+ debugging: true
24
+
25
+ production:
26
+ host: <your_salesforce_host>
27
+ client_secret: <your_salesforce_client_secret>
28
+ client_id: <your_salesforce_client_id>
29
+ username: <your_salesforce_username>
30
+ password: <your_salesforce_password>
31
+ token: <your_salesforce_token>
32
+ instance_url: <your_salesforce_instance_url>
@@ -0,0 +1 @@
1
+ require 'salesforce/rails'
@@ -0,0 +1,10 @@
1
+ require 'yaml' unless defined?(YAML)
2
+ require 'databasedotcom'
3
+ require 'rails'
4
+ require 'salesforce/rails/engine' if ::Rails.version >= '3.1'
5
+ require 'salesforce/rails/version'
6
+
7
+ require 'salesforce/rails/api/client.rb'
8
+ Dir[File.join(File.dirname(__FILE__), 'rails', 'api', '**', '*.rb').to_s].each do |file|
9
+ require file
10
+ end
@@ -0,0 +1,25 @@
1
+ module Salesforce
2
+ module Rails
3
+ module API
4
+ class CalendarEvent
5
+ include Salesforce::Rails::API::Client
6
+
7
+ class << self
8
+ # Returns all calendar events.
9
+ #
10
+ # Salesforce::Rails::API::Calendar::Event.all #=> [#<Event @Id="1", ...>, #<Event @Id="2", ...>, #<Event @Id="3", ...>, ...]
11
+ def all
12
+ client.query("SELECT Id, Subject, IsAllDayEvent, StartDateTime, EndDateTime, Description, Owner.Name, ShowAs FROM Event")
13
+ end
14
+
15
+ # Returns a collection of events of self that match the conditional +where_expr+, which is the WHERE part of a SOQL query.
16
+ #
17
+ # Salesforce::Rails::API::Calendar::Event.query("Name = 'test'") #=> [#<Event @Id="1", @Name="test", ...>, #<Event @Id="2", @Name="test", ...>, #<Event @Id="3", @Name="test", ...>, ...]
18
+ def query(where_expr)
19
+ client.query("SELECT Id, Subject, IsAllDayEvent, StartDateTime, EndDateTime, Description, Owner.Name, ShowAs FROM Event WHERE #{where_expr}")
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,32 @@
1
+ module Salesforce
2
+ module Rails
3
+ module API
4
+ module Client
5
+ module ClassMethods
6
+ def client
7
+ unless @client
8
+ config = YAML.load_file(File.join(::Rails.root, 'config', 'salesforce.yml'))
9
+ config = config.has_key?(::Rails.env) ? config[::Rails.env] : config
10
+ username = config["username"]
11
+ password = config["password"]
12
+ token = config["token"]
13
+ instance_url = config["instance_url"]
14
+ @client = Databasedotcom::Client.new(config)
15
+ username && password ? @client.authenticate(:username => username, :password => password) : @client.authenticate(:token => token, :instance_url => instance_url)
16
+ end
17
+
18
+ @client
19
+ end
20
+
21
+ def client=(client)
22
+ @client = client
23
+ end
24
+ end
25
+
26
+ def self.included(base)
27
+ base.send(:extend, ClassMethods)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,6 @@
1
+ module Salesforce
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Salesforce
2
+ module Rails
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'salesforce/rails/version'
5
+
6
+ rails_version = ['>= 3.1.0', '< 4.0']
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "salesforce-rails"
9
+ spec.version = Salesforce::Rails::VERSION
10
+ spec.platform = Gem::Platform::RUBY
11
+ spec.authors = ["Diganta Mandal"]
12
+ spec.email = ["diganta@emerchantpay.com"]
13
+ spec.summary = %q{Convenience classes to make using the salesforce calender events with Rails apps even easier.}
14
+ spec.description = %q{Convenience classes to make using the salesforce calender events with Rails apps even easier.}
15
+ spec.homepage = "https://github.com/dark-prince/salesforce-rails"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "databasedotcom"
24
+ spec.add_dependency "railties", rails_version
25
+ spec.add_dependency "actionpack", rails_version
26
+ spec.add_dependency "thor", ">= 0.14", "< 2.0"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.6"
29
+ spec.add_development_dependency "rake"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+
32
+ spec.add_runtime_dependency "rails", rails_version
33
+ end
@@ -0,0 +1,20 @@
1
+ development:
2
+ client_secret: client_secret
3
+ client_id: client_id
4
+ token: foo
5
+ instance_url: https://na9.salesforce.com
6
+ debugging: true
7
+
8
+ test:
9
+ client_secret: test_client_secret
10
+ client_id: test_client_secret
11
+ username: test_user
12
+ password: test_password
13
+ debugging: true
14
+
15
+ production:
16
+ client_secret: production_client_secret
17
+ client_id: production_client_secret
18
+ username: production_user
19
+ password: production_password
20
+ debugging: true
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Salesforce::Rails::API::CalendarEvent do
4
+ class TestClass < Salesforce::Rails::API::CalendarEvent
5
+ end
6
+
7
+ before do
8
+ config = YAML.load_file(File.join(::Rails.root, 'fixtures/salesforce.yml'))
9
+ config = config.has_key?(::Rails.env) ? config[::Rails.env] : config
10
+ token = config["token"]
11
+ instance_url = config["instance_url"]
12
+ @client = Databasedotcom::Client.new(config)
13
+ @client.authenticate(:token => token, :instance_url => instance_url)
14
+ TestClass.client = @client
15
+ end
16
+
17
+ context ".all" do
18
+ it "returns all records of events as instances" do
19
+ expect(@client).to receive(:query).with("SELECT Id, Subject, IsAllDayEvent, StartDateTime, EndDateTime, Description, Owner.Name, ShowAs FROM Event").and_return("foo")
20
+ expect(TestClass.all).to eq("foo")
21
+ end
22
+ end
23
+
24
+ context ".query" do
25
+ it "constructs and submits a SOQL query" do
26
+ expect(@client).to receive(:query).with("SELECT Id, Subject, IsAllDayEvent, StartDateTime, EndDateTime, Description, Owner.Name, ShowAs FROM Event WHERE Subject = 'foo'").and_return("bar")
27
+ expect(TestClass.query("Subject = 'foo'")).to eq("bar")
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe Salesforce::Rails::API::Client do
4
+ class TestClass
5
+ include Salesforce::Rails::API::Client
6
+ end
7
+
8
+ context ".client" do
9
+ before(:each) do
10
+ TestClass.client = nil
11
+ end
12
+
13
+ describe "if the config has an entry that matches Rails.env" do
14
+ it "should use the related entry" do
15
+ config_hash = {
16
+ :development => { "client_id" => "development_client_id", "client_secret" => "development_client_secret", "username" => "development_user", "password" => "development_password" },
17
+ :test => { "client_id" => "test_client_id", "client_secret" => "test_client_secret", "username" => "test_user", "password" => "test_password" },
18
+ :production => { "client_id" => "production_client_id", "client_secret" => "production_client_secret", "username" => "production_user", "password" => "production_password" }
19
+ }
20
+
21
+ expect(YAML).to receive(:load_file).and_return(config_hash)
22
+ ::Rails.stub(:env).and_return(:production)
23
+
24
+ expect_any_instance_of(Databasedotcom::Client).to receive(:authenticate).with(:username => "production_user", :password => "production_password")
25
+ TestClass.client
26
+ end
27
+ end
28
+
29
+ describe "if the config does not have an entry that matches Rails.env" do
30
+ it "should use the top level config" do
31
+ conf_hash = { "client_id" => "client_id", "client_secret" => "client_secret", "username" => "production_user", "password" => "production_password" }
32
+ ::Rails.stub(:env).and_return(:production)
33
+ expect(YAML).to receive(:load_file).and_return(conf_hash)
34
+ expect_any_instance_of(Databasedotcom::Client).to receive(:authenticate).with(:username => "production_user", :password => "production_password")
35
+ TestClass.client
36
+ end
37
+ end
38
+
39
+ describe "test_user" do
40
+ before(:each) do
41
+ config_hash = { "client_id" => "client_id", "client_secret" => "client_secret", "username" => "test_user", "password" => "test_password" }
42
+ expect(YAML).to receive(:load_file).and_return(config_hash)
43
+ ::Rails.stub(:env).and_return(:test)
44
+ end
45
+
46
+ it "constructs and authenticates a Databasedotcom::Client" do
47
+ expect_any_instance_of(Databasedotcom::Client).to receive(:authenticate).with(:username => "test_user", :password => "test_password")
48
+ TestClass.client
49
+ end
50
+
51
+ it "is memoized" do
52
+ expect_any_instance_of(Databasedotcom::Client).to receive(:authenticate).exactly(1).times.with(:username => "test_user", :password => "test_password")
53
+ TestClass.client
54
+ TestClass.client
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ module ::Rails
2
+ def self.root
3
+ File.dirname(__FILE__)
4
+ end
5
+ end