activeforce 1.10.5 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: fcd408693ad607e9ac81bdde9a3349e54600cc55613103ecab38ddaaecdbe4b7
4
- data.tar.gz: a564ac2c82582660bf8d2a34cc239efec7728f1fa9dba7779564c431d17a0982
2
+ SHA1:
3
+ metadata.gz: 5e9ce8aeb41b2acdb5c8de782383b1dfa226e190
4
+ data.tar.gz: 73b5bfd375f25c902c9a47cd2c841f1f303f5d7c
5
5
  SHA512:
6
- metadata.gz: e27e2ecea57c3a08e31dd845d8d28d99b1aa5f01853c25f2d9e11b07318ccd4ecd596df56fb0e3ece7271a25566e5850a4aa5abc2d91b60108847d59ebd3620d
7
- data.tar.gz: 8f91ab47ac2e667bfb5b36be97cb6a7eb14bfbacc4e36507234089f3e3b727e0240575520ee9fe94066b6a10adebb72234d6ca83d20c95c141ef10ac4a1c4220
6
+ metadata.gz: 2f1bbcf0db4e8c373b6295785915be2223766717a91ef5207e82fe22ebbd1ea9635d568c3e2500141d32d0700b7687178a2e4f2d459696076c0ea9468e67fb8b
7
+ data.tar.gz: 179f8521cd7f1d9343eda55b3c95110bf53889441b36bbe5a1aafb1b48ad7160eaad35c241277b10f7c8b34b59425f346df11a06d17d41d3a64f0946d81e6208
data/.gitignore CHANGED
@@ -18,4 +18,3 @@ _yardoc
18
18
  doc/
19
19
 
20
20
  Gemfile.lock
21
- gemfiles/*.lock
data/.travis.yml CHANGED
@@ -1,7 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.6.3
4
- - 2.3.3
3
+ - 2.3.1
4
+ - 2.2.3
5
+ - 2.1.4
6
+ - 2.0.0
5
7
  - ruby-head
6
8
 
7
9
  sudo: false
@@ -9,11 +11,8 @@ sudo: false
9
11
  matrix:
10
12
  allow_failures:
11
13
  - rvm: ruby-head
12
- exclude:
13
- - rvm: 2.3.3
14
- gemfile: gemfiles/6.0.gemfile
15
14
 
16
15
  gemfile:
17
- - gemfiles/5.0.gemfile
18
- - gemfiles/5.2.gemfile
19
- - gemfiles/6.0.gemfile
16
+ - gemfiles/4.0.gemfile
17
+ - gemfiles/4.1.gemfile
18
+ - gemfiles/4.2.gemfile
data/Appraisals CHANGED
@@ -1,11 +1,11 @@
1
- appraise "5.0" do
2
- gem "rails", "~> 5.0.0"
1
+ appraise "4.0" do
2
+ gem "rails", "~> 4.0.0"
3
3
  end
4
4
 
5
- appraise "5.2" do
6
- gem "rails", "~> 5.2.0"
5
+ appraise "4.1" do
6
+ gem "rails", "~> 4.1.0"
7
7
  end
8
8
 
9
- appraise "6.0" do
10
- gem "rails", "~> 6.0.0.rc1"
9
+ appraise "4.2" do
10
+ gem "rails", "~> 4.2"
11
11
  end
data/Rakefile CHANGED
@@ -20,7 +20,6 @@ Rake::TestTask.new(:test) do |test|
20
20
  test.libs << 'lib' << 'test'
21
21
  test.pattern = 'test/**/*_test.rb'
22
22
  test.verbose = true
23
- test.warning = false
24
23
  end
25
24
 
26
25
  task :default => :test
data/activeforce.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Tushar Ranka", "Andrew Mutz"]
10
10
  s.date = "2013-08-27"
11
11
  s.description = " Activeforce provides a simple to use and extend interface to Salesforce using the REST API"
12
- s.email = ["andrew.mutz@appfolio.com"]
12
+ s.email = ["tusharranka@gmail.com", "andrew.mutz@appfolio.com"]
13
13
  s.extra_rdoc_files = [
14
14
  "LICENSE.txt",
15
15
  "README.md"
@@ -19,12 +19,13 @@ Gem::Specification.new do |s|
19
19
  s.licenses = ["MIT"]
20
20
  s.require_paths = ["lib"]
21
21
  s.rubygems_version = "2.0.3"
22
- s.required_ruby_version = ">= 2.3"
22
+ s.required_ruby_version = ">= 2.0"
23
23
  s.summary = "A Simple gem to interact with the Salesforce REST API"
24
24
 
25
- s.add_dependency(%q<rails>, [">= 4.2", "< 6.1"])
26
- s.add_dependency(%q<savon>, ["~> 1.0"])
25
+ s.add_dependency(%q<rails>, [">= 4.0", "< 5.0"])
26
+ s.add_dependency(%q<savon>, ["~> 2.11"])
27
27
  s.add_dependency(%q<blockenspiel>, [">= 0"])
28
- s.add_dependency(%q<rest-client>, ["~> 2.0"])
28
+ s.add_dependency(%q<rest-client>, [">= 0", '< 2.0'])
29
29
  s.add_dependency(%q<fastercsv>, [">= 0"])
30
30
  end
31
+
@@ -3,7 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
- gem "mocha", "0.14.0", require: false
7
- gem "rails", "~> 5.2.0"
6
+ gem "mocha", "0.14.0", :require => false
7
+ gem "rails", "~> 4.0.0"
8
8
 
9
- gemspec path: "../"
9
+ gemspec :path => "../"
@@ -3,7 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
- gem "mocha", "0.14.0", require: false
7
- gem "rails", "~> 6.0.0.rc1"
6
+ gem "mocha", "0.14.0", :require => false
7
+ gem "rails", "~> 4.1.0"
8
8
 
9
- gemspec path: "../"
9
+ gemspec :path => "../"
@@ -3,7 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
- gem "mocha", "0.14.0", require: false
7
- gem "rails", "~> 5.0.0"
6
+ gem "mocha", "0.14.0", :require => false
7
+ gem "rails", "~> 4.2"
8
8
 
9
- gemspec path: "../"
9
+ gemspec :path => "../"
@@ -1,3 +1,3 @@
1
1
  module Activeforce
2
- VERSION = '1.10.5'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
@@ -12,12 +12,7 @@ module Salesforce
12
12
  result = Connection.login
13
13
  Config.instance.soap_endpoint_url result[:server_url]
14
14
  Config.instance.session_id result[:session_id]
15
-
16
- host = URI.parse(result[:server_url]).host
17
- host_match = host.match(/(?<instance>[a-z0-9\-]+(?:\.[a-z]+\d+)?)\.(?<domain>(?:my\.)?salesforce\.com)/)
18
-
19
- Config.instance.server_instance host_match[:instance]
20
- Config.instance.server_domain host_match[:domain]
15
+ Config.instance.server_instance URI.parse(result[:server_url]).host[/(na|cs)\d+/]
21
16
  Config.instance.user_id result[:user_id]
22
17
  Config.session_id
23
18
  end
@@ -7,18 +7,18 @@ module Salesforce
7
7
  class Batch
8
8
  Result = Struct.new :id, :success, :created, :error
9
9
  include ::Salesforce::Attributes
10
-
10
+
11
11
  attr_accessor :id, :job, :number_records_failed, :number_records_processed, :state, :state_message, :total_time_processed, :filename, :csv
12
12
 
13
13
  include Blockenspiel::DSL
14
-
14
+
15
15
  def initialize(job)
16
16
  self.job = job
17
17
  self.filename = temporary_csv_file
18
18
  self.csv = CSVLib.open(self.filename, 'w+')
19
19
  self.csv << csv_header
20
20
  end
21
-
21
+
22
22
  def record(record)
23
23
  if record.is_a?(Hash)
24
24
  self.csv << ordered_values(record)
@@ -26,56 +26,56 @@ module Salesforce
26
26
  self.csv << ordered_values(record.attributes)
27
27
  end
28
28
  end
29
-
29
+
30
30
  def ordered_values(record)
31
31
  job.csv_columns.map do |col|
32
32
  raw_value = record[col.name.to_sym]
33
33
  Column.to_csv_value Column.typecast(col.type, raw_value)
34
34
  end
35
35
  end
36
-
36
+
37
37
  def create!
38
38
  self.csv.close
39
39
  response = ::Salesforce.connection.async_post("job/#{job.id}/batch", File.read(self.filename), :format => :xml, :content_type => 'text/csv')
40
40
  assign_attributes!(response)
41
41
  end
42
-
42
+
43
43
  def update_status
44
44
  return state if completed?
45
45
  response = ::Salesforce.connection.async_get("job/#{job.id}/batch/#{id}", :format => :xml)
46
46
  self.state = response[:state]
47
47
  end
48
-
48
+
49
49
  def results
50
50
  parse_csv_results ::Salesforce.connection.async_get("job/#{job.id}/batch/#{id}/result")
51
51
  end
52
-
52
+
53
53
  [ :queued, :in_progress, :completed, :failed, :not_processed ].each do |status|
54
54
  define_method "#{status}?" do
55
55
  self.state == status.to_s.titleize
56
56
  end
57
57
  end
58
-
58
+
59
59
  def temporary_csv_file
60
- if Object.const_defined?(:Rails) && Rails.respond_to?(:root) && Rails.root.present?
60
+ if Object.const_defined?(:Rails) && Rails.root.present?
61
61
  Rails.root.join('tmp', 'files', "#{ Time.now.to_i}#{rand(10000)}.csv")
62
62
  else
63
63
  File.join("/tmp/#{ Time.now.to_i}#{rand(10000)}.csv")
64
64
  end
65
65
  end
66
-
66
+
67
67
  private
68
-
68
+
69
69
  def parse_csv_results(results)
70
70
  parsed_results = CSVLib.parse(results)
71
71
  parsed_results[1..-1].map { |row| Result.new(*row) }
72
72
  end
73
-
73
+
74
74
  def csv_header
75
75
  self.job.csv_columns.map(&:original_name)
76
76
  end
77
-
78
-
77
+
78
+
79
79
  end
80
80
  end
81
81
  end
@@ -1,7 +1,7 @@
1
1
  module Salesforce
2
2
  class Column
3
3
  attr_accessor :name, :original_name, :createable, :updateable, :type
4
-
4
+
5
5
  SUPPORTED_DATE_RANGE = Date.parse("1700-01-01")..Date.parse("4000-12-31")
6
6
  SUPPORTED_TIME_RANGE = Time.parse("1902-01-01 00:00:00 UTC")..Time.parse("2037-12-31 00:00:00 UTC")
7
7
 
@@ -100,7 +100,7 @@ module Salesforce
100
100
  end
101
101
  when :double
102
102
  begin
103
- value.to_s.to_d
103
+ BigDecimal(value.to_s)
104
104
  rescue
105
105
  value if value.is_a?(Numeric)
106
106
  end
@@ -6,11 +6,11 @@ module Salesforce
6
6
  include Blockenspiel::DSL
7
7
  include Blockenspiel::DSLSetupMethods
8
8
 
9
- dsl_attr_accessor :session_id, :server_instance, :server_domain, :user_id, :soap_endpoint_url
9
+ dsl_attr_accessor :session_id, :server_instance, :user_id, :soap_endpoint_url
10
10
 
11
11
  [
12
12
  :username, :password, :api_version, :use_sandbox?, :use_full_length_ids?,
13
- :login_url, :session_id, :server_instance, :server_domain, :soap_endpoint_url, :soap_enterprise_namespace,
13
+ :login_url, :session_id, :server_instance, :soap_endpoint_url, :soap_enterprise_namespace,
14
14
  :user_id, :server_url, :server_host, :async_url, :configured?, :on_login_failure ].each do |method_name|
15
15
  eval <<-RUBY
16
16
  def self.#{method_name}
@@ -88,15 +88,15 @@ module Salesforce
88
88
  end
89
89
 
90
90
  def server_url
91
- "https://#{server_instance}.#{server_domain}/services/data/v#{api_version}"
91
+ "https://#{server_instance}.salesforce.com/services/data/v#{api_version}"
92
92
  end
93
93
 
94
94
  def server_host
95
- "https://#{server_instance}.#{server_domain}"
95
+ "https://#{server_instance}.salesforce.com"
96
96
  end
97
97
 
98
98
  def async_url
99
- "https://#{server_instance}.#{server_domain}/services/async/#{api_version}"
99
+ "https://#{server_instance}.salesforce.com/services/async/#{api_version}"
100
100
  end
101
101
 
102
102
  def login_url
@@ -11,13 +11,13 @@ module Salesforce
11
11
  include HttpMethods
12
12
  include Conversion
13
13
  include Async
14
-
14
+
15
15
  def self.as_logged_in_user(&block)
16
- count = 0
16
+ count = 0
17
17
  begin
18
18
  Salesforce::Authentication.session_id
19
19
  block.call
20
- rescue RestClient::Unauthorized, Savon::SOAP::Fault => e
20
+ rescue RestClient::Request::Unauthorized, Savon::SOAPFault => e
21
21
  if count < 1 && (e.message.downcase.include?("unauthorized") || e.message.downcase.include?("invalid_login"))
22
22
  count += 1
23
23
  Salesforce::Config.on_login_failure
@@ -27,7 +27,7 @@ module Salesforce
27
27
  raise e
28
28
  end
29
29
  end
30
-
30
+
31
31
  end
32
32
  end
33
- end
33
+ end
@@ -31,19 +31,26 @@ module Salesforce
31
31
  protected
32
32
 
33
33
  def invoke_soap(method_name, options)
34
- options[:namespace] ||= Config.soap_enterprise_namespace
35
- options[:endpoint_url] ||= Config.soap_endpoint_url
36
-
37
- result = soap_client(options).request :wsdl, method_name do |soap|
38
- soap.body = options[:body]
34
+ client_options = {
35
+ namespace: options[:namespace] ||= Config.soap_enterprise_namespace,
36
+ endpoint: options[:endpoint_url] ||= Config.soap_endpoint_url
37
+ }
39
38
 
40
- unless method_name.to_sym == :login
41
- soap.namespaces["xmlns:ns1"] = Config.soap_enterprise_namespace
42
- soap.header = { "ns1:SessionHeader" => { "ns1:sessionId" => Config.session_id }}
43
- end
39
+ additional_call_options = {}
40
+ unless method_name.to_sym == :login
41
+ additional_call_options[:soap_header] = {
42
+ "ns1:SessionHeader" => { "ns1:sessionId" => Config.session_id }
43
+ }
44
+
45
+ client_options[:namespaces] = {
46
+ "xmlns:ns1" => Config.soap_enterprise_namespace,
47
+ }
44
48
  end
49
+
50
+ client = soap_client(client_options)
51
+ result = client.call(method_name.to_sym, { message: options[:body] }.merge(additional_call_options))
45
52
 
46
- result.to_hash[:"#{method_name.to_s.underscore}_response"][:result].tap do |result|
53
+ result.body[:"#{method_name.to_s.underscore}_response"][:result].tap do |result|
47
54
  unless result[:success] || method_name.to_sym == :login
48
55
  raise_error(method_name, options, result[:errors])
49
56
  end
@@ -51,10 +58,7 @@ module Salesforce
51
58
  end
52
59
 
53
60
  def soap_client(options)
54
- Savon::Client.new do
55
- wsdl.namespace = options[:namespace]
56
- wsdl.endpoint = options[:endpoint_url]
57
- end
61
+ Savon.client(options.merge(log: false))
58
62
  end
59
63
 
60
64
  def raise_error(method_name, options, errors)
@@ -71,4 +75,4 @@ MSG
71
75
 
72
76
  end
73
77
  end
74
- end
78
+ end
@@ -10,7 +10,7 @@ class Salesforce::AuthenticationTest < ActiveSupport::TestCase
10
10
  Salesforce::Config.instance.session_id "existingsessionid"
11
11
  assert_equal "existingsessionid", Salesforce::Authentication.session_id
12
12
  end
13
-
13
+
14
14
  def test_session_id__doesnotexist
15
15
  Salesforce.configure do
16
16
  username "username"
@@ -19,20 +19,20 @@ class Salesforce::AuthenticationTest < ActiveSupport::TestCase
19
19
  Salesforce::Authentication.expects(:generate_new_session_id).returns("new_session_id")
20
20
  assert_equal "new_session_id", Salesforce::Authentication.session_id
21
21
  end
22
-
22
+
23
23
  def test_session_id__credentials_missing
24
24
  Salesforce::Authentication.expects(:generate_new_session_id).never
25
25
  assert_raises Salesforce::InvalidCredentials do
26
26
  Salesforce::Authentication.session_id
27
27
  end
28
28
  end
29
-
29
+
30
30
  def test_logout
31
31
  Salesforce::Config.instance.session_id = "session_id"
32
32
  Salesforce::Authentication.logout
33
- assert_nil Salesforce::Config.session_id
33
+ assert_equal nil, Salesforce::Config.session_id
34
34
  end
35
-
35
+
36
36
  def test_generate_new_session_id__calls_connection_login
37
37
  result = {
38
38
  :session_id => "session_id",
@@ -46,42 +46,7 @@ class Salesforce::AuthenticationTest < ActiveSupport::TestCase
46
46
  assert_equal "https://cs99.salesforce.com/services/Soap/c/22.0/00DQ00000001LRX", Salesforce::Config.soap_endpoint_url
47
47
  assert_equal "session_id", Salesforce::Config.session_id
48
48
  assert_equal "cs99", Salesforce::Config.server_instance
49
- assert_equal "salesforce.com", Salesforce::Config.server_domain
50
49
  assert_equal "user_id", Salesforce::Config.user_id
51
50
  end
52
-
53
- def test_generate_new_session_id__calls_connection_login__my_domain
54
- result = {
55
- :session_id => "session_id",
56
- :server_url => "https://awesome-2000.my.salesforce.com/services/Soap/c/22.0/00DQ00000001LRX",
57
- :user_id => "user_id"
58
- }
59
-
60
- Salesforce.connection.expects(:login).returns(result)
61
-
62
- assert_equal "session_id", Salesforce::Authentication.generate_new_session_id
63
- assert_equal "https://awesome-2000.my.salesforce.com/services/Soap/c/22.0/00DQ00000001LRX", Salesforce::Config.soap_endpoint_url
64
- assert_equal "session_id", Salesforce::Config.session_id
65
- assert_equal "awesome-2000", Salesforce::Config.server_instance
66
- assert_equal "my.salesforce.com", Salesforce::Config.server_domain
67
- assert_equal "user_id", Salesforce::Config.user_id
68
- end
69
-
70
- def test_generate_new_session_id__calls_connection_login__my_domain__sandbox
71
- result = {
72
- :session_id => "session_id",
73
- :server_url => "https://awesome-2000--some-sandbox.na2001.my.salesforce.com/services/Soap/c/22.0/00DQ00000001LRX",
74
- :user_id => "user_id"
75
- }
76
-
77
- Salesforce.connection.expects(:login).returns(result)
78
-
79
- assert_equal "session_id", Salesforce::Authentication.generate_new_session_id
80
- assert_equal "https://awesome-2000--some-sandbox.na2001.my.salesforce.com/services/Soap/c/22.0/00DQ00000001LRX", Salesforce::Config.soap_endpoint_url
81
- assert_equal "session_id", Salesforce::Config.session_id
82
- assert_equal "awesome-2000--some-sandbox.na2001", Salesforce::Config.server_instance
83
- assert_equal "my.salesforce.com", Salesforce::Config.server_domain
84
- assert_equal "user_id", Salesforce::Config.user_id
85
- end
86
-
87
- end
51
+
52
+ end