Class: Restforce::Client

Inherits:
Object
  • Object
show all
Includes:
API, Authentication, Caching, Canvas, Connection, Picklists, Streaming
Defined in:
lib/restforce/client.rb,
lib/restforce/client/api.rb,
lib/restforce/client/verbs.rb,
lib/restforce/client/canvas.rb,
lib/restforce/client/caching.rb,
lib/restforce/client/picklists.rb,
lib/restforce/client/streaming.rb,
lib/restforce/client/connection.rb,
lib/restforce/client/authentication.rb

Defined Under Namespace

Modules: API, Authentication, Caching, Canvas, Connection, Picklists, Streaming, Verbs

Instance Method Summary collapse

Methods included from API

#create, #create!, #describe, #destroy, #destroy!, #find, #list_sobjects, #org_id, #query, #search, #update, #update!, #upsert, #upsert!

Methods included from Verbs

#define_api_verb, #define_verb, #define_verbs

Methods included from Canvas

#decode_signed_request

Methods included from Caching

#without_caching

Methods included from Picklists

#picklist_values

Methods included from Streaming

#faye, #subscribe

Methods included from Authentication

#authenticate!, #authentication_middleware, #oauth_refresh?, #username_password?

Methods included from Connection

#middleware

Constructor Details

#initialize(opts = {}) ⇒ Client

Public: Creates a new client instance

opts - A hash of options to be passed in (default: {}).

:username               - The String username to use (required for password authentication).
:password               - The String password to use (required for password authentication).
:security_token         - The String security token to use (required for password authentication).

:oauth_token            - The String oauth access token to authenticate api
                          calls (required unless password
                          authentication is used).
:refresh_token          - The String refresh token to obtain fresh
                          oauth access tokens (required if oauth
                          authentication is used).
:instance_url           - The String base url for all api requests
                          (required if oauth authentication is used).

:client_id              - The oauth client id to use. Needed for both
                          password and oauth authentication
:client_secret          - The oauth client secret to use.

:host                   - The String hostname to use during
                          authentication requests (default: 'login.salesforce.com').

:api_version            - The String REST api version to use (default: '24.0')

:authentication_retries - The number of times that client
                          should attempt to reauthenticate
                          before raising an exception (default: 3).

:compress               - Set to true to have Salesforce compress the response (default: false).
:timeout                - Faraday connection request read/open timeout. (default: nil).

:proxy_uri              - Proxy URI: 'http://proxy.example.com:port' or 'http://user@pass:proxy.example.com:port'

Examples

# Initialize a new client using password authentication:
Restforce::Client.new :username => 'user',
  :password => 'pass',
  :security_token => 'security token',
  :client_id => 'client id',
  :client_secret => 'client secret'

# Initialize a new client using oauth authentication:
Restforce::Client.new :oauth_token => 'access token',
  :refresh_token => 'refresh token',
  :instance_url => 'https://na1.salesforce.com',
  :client_id => 'client id',
  :client_secret => 'client secret'

# Initialize a new client without using any authentication middleware:
Restforce::Client.new :oauth_token => 'access token',
  :instance_url => 'https://na1.salesforce.com'


73
74
75
76
77
# File 'lib/restforce/client.rb', line 73

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

Instance Method Details

#inspectObject



93
94
95
# File 'lib/restforce/client.rb', line 93

def inspect
  "#<#{self.class} @options=#{@options.inspect}>"
end

#instance_urlObject



79
80
81
82
# File 'lib/restforce/client.rb', line 79

def instance_url
  authenticate! unless @options[:instance_url]
  @options[:instance_url]
end

#url(resource) ⇒ Object

Public: Returns a url to the resource.

resource - A record that responds to to_sparam or a String/Fixnum.

Returns the url to the resource.



89
90
91
# File 'lib/restforce/client.rb', line 89

def url(resource)
  "#{instance_url}/#{(resource.respond_to?(:to_sparam) ? resource.to_sparam : resource)}"
end