dm-salesforce

A gem that provides a Salesforce Adapter for DataMapper 0.10.x. There are older versions of dm-salesforce specifically for 0.9.x.

The wsdl is automatically converted into Ruby classes upon the first invocation of the dm-salesforce adapter. The classes in turn get cached locally in one of the following locations, in order of precedence:

:repositories:salesforce:apidir (see included database.yml-example)
ENV["SALESFORCE_DIR"]
~/.salesforce/

It just works if you have the wsdl, directions for getting going are outlined below.

An example of using the adapter:

class Account
  include DataMapper::Resource

  def self.default_repository_name
    :salesforce
  end

  # One way to define which properties are SalesForce-style.
  def self.salesforce_id_properties
    :id
  end

  property :id,          String, :key => true
  property :name,        String
  property :description, String
  property :fax,         String
  property :phone,       String
  property :type,        String
  property :website,     String

  has 0..n, :contacts
end

class Contact
  include DataMapper::Resource

  def self.default_repository_name
    :salesforce
  end

  # Alternatively, specify the :salesforce_id option.
  property :id,         String, :serial => true, :salesforce_id => true
  property :first_name, String
  property :last_name,  String
  property :email,      String
  property :account_id, String, :salesforce_id => true

  belongs_to :account
end

To get a test environment going with the free development tools you'll need to follow these steps.

  • Get a developer account from http://force.salesforce.com
  • Hit up https://login.salesforce.com, and login with the password they provided in your signup email
  • Remember the password they force you to reset
  • Grab the following from Salesforce's web UI
  • Copy the WSDL file you downloaded to config/wsdl.xml
  • Copy and modify config/database.rb-example to use your info. In this case my password is 'skateboards' and my API key is 'f938915c9cdc36ff5498881b':

    DataMapper.setup(:salesforce, {:adapter  => 'salesforce',
                                   :username => '[email protected]',
                                   :password => 'skateboardsf938915c9cdc36ff5498881b',
                                   :path     => File.expand_path(File.dirname(__FILE__)+'/wsdl.xml'),
                                   :host     => ''})
    
    VALID_USER = DataMapperSalesforce::UserDetails.new('[email protected]', 'skateboardsf938915c9cdc36ff5498881b')
    VALID_SELF_SERVICE_USER = DataMapperSalesforce::UserDetails.new("[email protected]", "foo")
    
  • Run 'bin/irb' and you should have access to the Account and Contact models

Special Thanks to those who helped

  • Yehuda Katz
  • Corey Donohoe
  • Tim Carey-Smith
  • Andy Delcambre
  • Ben Burkert
  • Larry Diehl
  • Jordan Ritter
  • Martin Emde