sob-has_force 1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,2 +1,7 @@
1
+ == 1.0.1, Released 2009-02-10
2
+ * to_salesforce now returns true automatically if RAILS_ENV == 'test' [sob]
3
+ * added missing documentation to has_force methods [sob]
4
+ * added the option to include fields with the form submission (include_fields) [sob]
5
+
1
6
  == 1.0.0, Released 2009-01-26
2
7
  * Initial release
@@ -8,26 +8,50 @@ module Force
8
8
  end
9
9
 
10
10
  module ClassMethods
11
+ # This method includes the Force class and instance methods, allowing a
12
+ # model to be submitted to SalesForce.com through the Web2Lead tool.
13
+ #
14
+ # === Supported Options
15
+ #
16
+ # [:skip_fields]
17
+ # Specify attributes (as symbols) to remove before sending to salesforce.com
18
+ # [:transform_fields]
19
+ # Specify key,value pairs consisting of old_field => new_field to rename fields before sending to salesforce.com (used for custom fields)
20
+ # [:oid]
21
+ # Your organizations SalesForce.com OID
22
+ # [:include_fields]
23
+ # Additional fields to include with the submission to the Web2Lead gateway. Specified as key,value pairs
24
+ #
11
25
  def has_force(options = {})
12
26
  options = {
13
27
  :skip_fields => [ :id, :created_at, :created_by, :updated_at, :updated_by, :status ],
14
28
  :transform_fields => { },
15
- :oid => ''
29
+ :oid => '',
30
+ :include_fields => { }
16
31
  }.merge(options)
17
32
 
18
33
  cattr_accessor :force_skip_fields
19
34
  cattr_accessor :force_transform_fields
20
35
  cattr_accessor :force_oid
36
+ cattr_accessor :force_include_fields
21
37
 
22
38
  self.force_skip_fields = options[:skip_fields]
23
39
  self.force_transform_fields = options[:transform_fields]
24
40
  self.force_oid = options[:oid]
41
+ self.force_include_fields = options[:include_fields]
25
42
 
26
43
  send :include, InstanceMethods
27
44
  end
28
45
  end
29
46
 
30
47
  module InstanceMethods
48
+ # This method submits the attributes of an object to SalesForce.com using
49
+ # the Web2Lead gateway. It does not check for previous submissions so you
50
+ # should somewhere in your model before calling this function.
51
+ #
52
+ # Returns true on <tt>Net::HTTPSuccess</tt> or <tt>Net::HTTPRedirection</tt>
53
+ # otherwise returns false
54
+ #
31
55
  def to_salesforce
32
56
  url = URI.parse('https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8')
33
57
  http = Net::HTTP.new(url.host, url.port)
@@ -36,7 +60,12 @@ module Force
36
60
  request = Net::HTTP::Post.new(url.path)
37
61
  attribs = (self.attributes - self.class.force_skip_fields.stringify).stringify_values!
38
62
  attribs.transform_keys!(self.class.force_transform_fields)
63
+ attribs = attribs.merge(self.class.force_include_fields)
39
64
  request.set_form_data(attribs.merge({:oid => self.class.force_oid}))
65
+
66
+ # always return true in the test environment
67
+ # prevents massive spam from SalesForce during tests
68
+ return true if RAILS_ENV == 'test'
40
69
  begin
41
70
  response = http.request(request)
42
71
  case response
data/lib/force.rb CHANGED
@@ -1,3 +1,3 @@
1
- require 'force/has_force'
2
1
  require 'force/core_ext/array'
3
- require 'force/core_ext/hash'
2
+ require 'force/core_ext/hash'
3
+ require 'force/has_force'
@@ -16,6 +16,11 @@ class HasForceTest < Test::Unit::TestCase
16
16
  assert_equal('123', Lead.force_oid)
17
17
  end
18
18
 
19
+ def test_lead_class_sets_force_include_fields
20
+ assert_not_nil(Lead.force_include_fields)
21
+ assert_equal({}, Lead.force_include_fields)
22
+ end
23
+
19
24
  def test_lead_class_sets_force_skip_fields
20
25
  assert_not_nil(Lead.force_skip_fields)
21
26
  assert_equal([:id, :created_at, :created_by, :updated_at, :updated_by, :status], Lead.force_skip_fields)
data/test/test_helper.rb CHANGED
@@ -2,7 +2,12 @@ ENV['RAILS_ENV'] = 'test'
2
2
  ENV['RAILS_ROOT'] ||= File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..'))
3
3
 
4
4
  require 'test/unit'
5
- require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config', 'environment.rb'))
5
+ if (File.exists?(File.expand_path(File.join(ENV['RAILS_ROOT'], 'config', 'environment.rb'))))
6
+ require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config', 'environment.rb'))
7
+ else
8
+ require 'rubygems'
9
+ require 'activerecord'
10
+ end
6
11
 
7
12
  def load_schema
8
13
  config = YAML::load(IO.read(File.expand_path(File.join(File.dirname(__FILE__), 'database.yml'))))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sob-has_force
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.0"
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean O'Brien
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-26 00:00:00 -08:00
12
+ date: 2009-02-10 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15