Class: RForce::Wrapper::Connection
- Inherits:
-
Object
- Object
- RForce::Wrapper::Connection
- Includes:
- ApiMethods::CoreMethods, ApiMethods::DescribeMethods, ApiMethods::UtilityMethods
- Defined in:
- lib/rforce-wrapper/connection.rb
Instance Attribute Summary (collapse)
-
- (RForce::Binding) binding
readonly
The underlying
RForce::Bindingobject.
Class Method Summary (collapse)
-
+ (String) url_for_environment(type, version)
Returns the URL for the given environment type and version.
Instance Method Summary (collapse)
-
- (Connection) initialize(email, pass, options = {})
constructor
Creates a new connect to the Salesforce API using the given email and password or password+token combination and connects to the API.
-
- (Hash, ...) make_api_call(method, params = nil)
Performs a SOAP API call via the underlying
RForce::Bindingobject.
Methods included from ApiMethods::UtilityMethods
#getServerTimestamp, #getUserInfo, #resetPassword, #sendEmail, #setPassword
Methods included from ApiMethods::DescribeMethods
#describeDataCategoryGroupStructures, #describeDataCategoryGroups, #describeGlobal, #describeLayout, #describeSObject, #describeSObjects, #describeSoftphoneLayout, #describeTabs
Methods included from ApiMethods::CoreMethods
#convertLead, #create, #delete, #emptyRecycleBin, #getDeleted, #getUpdated, #invalidateSessions, #logout, #merge, #process, #query, #queryAll, #queryMore, #retrieve, #search, #undelete, #update, #upsert
Constructor Details
- (Connection) initialize(email, pass, options = {})
Creates a new connect to the Salesforce API using the given email and password or password+token combination and connects to the API. Additional options can be specified. If a version of the Salesforce API that is not supported by the gem is passed, a warning is issued.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rforce-wrapper/connection.rb', line 38 def initialize(email, pass, = {}) = { :environment => :live, :version => '21.0', :wrap_results => true }.merge() @wrap_results = [:wrap_results] unless SF_API_VERSIONS.include? [:version] = "Version #{[:version]} of the Salesforce Web " + "Services API is not supported by RForce-wrapper." Kernel.warn() end @binding = RForce::Binding.new Connection.url_for_environment([:environment], [:version]) @binding.login email, pass end |
Instance Attribute Details
- (RForce::Binding) binding (readonly)
The underlying RForce::Binding object.
19 20 21 |
# File 'lib/rforce-wrapper/connection.rb', line 19 def binding @binding end |
Class Method Details
+ (String) url_for_environment(type, version)
Returns the URL for the given environment type and version.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rforce-wrapper/connection.rb', line 61 def self.url_for_environment(type, version) case type when :test "https://test.salesforce.com/services/Soap/u/#{version}" when :live "https://www.salesforce.com/services/Soap/u/#{version}" else raise InvalidEnvironmentException.new "Invalid environment type: #{type.to_s}" end end |
Instance Method Details
- (Hash, ...) make_api_call(method, params = nil)
Performs a SOAP API call via the underlying RForce::Binding
object. Raises an exception if a Fault is detected. Returns
the data portion of the result (wrapped in an Array if
wrap_results is true; see #initialize).
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rforce-wrapper/connection.rb', line 88 def make_api_call(method, params = nil) result = @binding.send method, params # Errors will result in result[:Fault] being set if result[:Fault] raise SalesforceFaultException.new result[:Fault][:faultcode], result[:Fault][:faultstring] end # If the result was successful, there will be a key: "#{method.to_s}Response".to_sym # which will contain the key :result result_field_name = method.to_s + "Response" if result[result_field_name.to_sym] data = result[result_field_name.to_sym][:result] @wrap_results ? Utilities.ensure_array(data) : data else nil end end |