class Restforce::Client
def initialize(opts = {})
:instance_url => 'https://na1.salesforce.com'
Restforce::Client.new :oauth_token => 'access token',
# Initialize a new client without using any authentication middleware:
:client_secret => 'client secret'
:client_id => 'client id',
:instance_url => 'https://na1.salesforce.com',
:refresh_token => 'refresh token',
Restforce::Client.new :oauth_token => 'access token',
# Initialize a new client using oauth authentication:
:client_secret => 'client secret'
:client_id => 'client id',
:security_token => 'security token',
:password => 'pass',
Restforce::Client.new :username => 'user',
# Initialize a new client using password authentication:
Examples
:proxy_uri - Proxy URI: 'http://proxy.example.com:port' or 'http://user@pass:proxy.example.com:port'
:timeout - Faraday connection request read/open timeout. (default: nil).
:compress - Set to true to have Salesforce compress the response (default: false).
before raising an exception (default: 3).
should attempt to reauthenticate
:authentication_retries - The number of times that client
:api_version - The String REST api version to use (default: '24.0')
authentication requests (default: 'login.salesforce.com').
:host - The String hostname to use during
:client_secret - The oauth client secret to use.
password and oauth authentication
:client_id - The oauth client id to use. Needed for both
(required if oauth authentication is used).
:instance_url - The String base url for all api requests
authentication is used).
oauth access tokens (required if oauth
:refresh_token - The String refresh token to obtain fresh
authentication is used).
calls (required unless password
:oauth_token - The String oauth access token to authenticate api
:security_token - The String security token to use (required for password authentication).
:password - The String password to use (required for password authentication).
:username - The String username to use (required for password authentication).
opts - A hash of options to be passed in (default: {}).
Public: Creates a new client instance
def initialize(opts = {}) raise 'Please specify a hash of options' unless opts.is_a?(Hash) @options = Hash[Restforce.configuration.options.map { |option| [option, Restforce.configuration.send(option)] }] @options.merge! opts end
def inspect
def inspect "#<#{self.class} @options=#{@options.inspect}>" end
def instance_url
def instance_url authenticate! unless @options[:instance_url] @options[:instance_url] end
def url(resource)
resource - A record that responds to to_sparam or a String/Fixnum.
Public: Returns a url to the resource.
def url(resource) "#{instance_url}/#{(resource.respond_to?(:to_sparam) ? resource.to_sparam : resource)}" end