def authenticate(options = nil)
      if user_and_pass?(options)
        req = https_request(self.host)
        user = self.username || options[:username]
        pass = self.password || options[:password]
        path = encode_path_with_params('/services/oauth2/token', :grant_type => 'password', :client_id => self.client_id, :client_secret => self.client_secret, :username => user, :password => pass)
        log_request("https://#{self.host}/#{path}")
        result = req.post(path, "")
        log_response(result)
        raise SalesForceError.new(result) unless result.is_a?(Net::HTTPOK)
        self.username = user
        self.password = pass
        parse_auth_response(result.body)
      elsif options.is_a?(Hash)
        if options.has_key?("provider")
          parse_user_id_and_org_id_from_identity_url(options["uid"])
          self.instance_url = options["credentials"]["instance_url"]
          self.oauth_token = options["credentials"]["token"]
          self.refresh_token = options["credentials"]["refresh_token"]
        else
          raise ArgumentError unless options.has_key?(:token) && options.has_key?(:instance_url)
          self.instance_url = options[:instance_url]
          self.oauth_token = options[:token]
          self.refresh_token = options[:refresh_token]
        end
      end

      self.version = "22.0" unless self.version

      self.oauth_token
    end
def authenticate(options = nil)
      if user_and_pass?(options)
        req = https_request(self.host)
        user = self.username || options[:username]
        pass = self.password || options[:password]
        path = encode_path_with_params('/services/oauth2/token', :grant_type => 'password', :client_id => self.client_id, :client_secret => self.client_secret, :username => user, :password => pass)
        log_request("https://#{self.host}/#{path}")
        result = req.post(path, "")
        log_response(result)
        raise SalesForceError.new(result) unless result.is_a?(Net::HTTPOK)
        self.username = user
        self.password = pass
        parse_auth_response(result.body)
      elsif options.is_a?(Hash)
        if options.has_key?("provider")
          parse_user_id_and_org_id_from_identity_url(options["uid"])
          self.instance_url = options["credentials"]["instance_url"]
          self.oauth_token = options["credentials"]["token"]
          self.refresh_token = options["credentials"]["refresh_token"]
        else
          raise ArgumentError unless options.has_key?(:token) && options.has_key?(:instance_url)
          self.instance_url = options[:instance_url]
          self.oauth_token = options[:token]
          self.refresh_token = options[:refresh_token]
        end
      end

      self.version = "22.0" unless self.version

      self.oauth_token
    end
Returns a new client object. _options_ can be one of the following

 * A String containing the name of a YAML file formatted like:
    ---
    client_id: <your_salesforce_client_id>
    client_secret: <your_salesforce_client_secret>
    host: login.salesforce.com
    debugging: true
    version: 23.0
    sobject_module: My::Module
    ca_file: some/ca/file.cert
    verify_mode: OpenSSL::SSL::VERIFY_PEER
 * A Hash containing the following keys:
    client_id
    client_secret
    host
    debugging
    version
    sobject_module
    ca_file
    verify_mode
 If the environment variables DATABASEDOTCOM_CLIENT_ID, DATABASEDOTCOM_CLIENT_SECRET, DATABASEDOTCOM_HOST,
 DATABASEDOTCOM_DEBUGGING, DATABASEDOTCOM_VERSION, DATABASEDOTCOM_SOBJECT_MODULE, DATABASEDOTCOM_CA_FILE, and/or
 DATABASEDOTCOM_VERIFY_MODE are present, they override any other values provided
 Authenticate to the Force.com API.  _options_ is a Hash, interpreted as follows:

 * If _options_ contains the keys <tt>:username</tt> and <tt>:password</tt>, those credentials are used to authenticate. In this case, the value of <tt>:password</tt> may need to include a concatenated security token, if required by your Salesforce org
 * If _options_ contains the key <tt>:provider</tt>, it is assumed to be the hash returned by Omniauth from a successful web-based OAuth2 authentication
 * If _options_ contains the keys <tt>:token</tt> and <tt>:instance_url</tt>, those are assumed to be a valid OAuth2 token and instance URL for a Salesforce account, obtained from an external source. _options_ may also optionally contain the key <tt>:refresh_token</tt>

 Raises SalesForceError if an error occurs