Module: Restforce::Concerns::Base

Included in:
AbstractClient
Defined in:
lib/restforce/concerns/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/restforce/concerns/base.rb', line 6

def options
  @options
end

Instance Method Details

#initialize(opts = {}) {|builder| ... } ⇒ Object

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.

   :jwt_key                 - The private key for JWT authentication

   :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).
   :mashify                 - Set to false to skip the conversion of
                              Salesforce responses to Restforce::Sobjects and
                              Restforce::Collections. (default: nil).
   :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'

   :authentication_callback - A Proc that is called with the response body
                              after a successful authentication.

   :request_headers         - A hash containing custom headers that will be
                              appended to each request

:clear_authorization_header - A boolean that when set to true will cause
                              the Faraday::FollowRedirects middleware to
                              omit the auth header when following
                              redirects (default: false)

Yields:

  • (builder)

Raises:

  • (ArgumentError)


66
67
68
69
70
71
72
73
74
75
# File 'lib/restforce/concerns/base.rb', line 66

def initialize(opts = {})
  raise ArgumentError, 'Please specify a hash of options' unless opts.is_a?(Hash)

  @options = Restforce.configuration.options.to_h do |option|
    [option, Restforce.configuration.send(option)]
  end

  @options.merge! opts
  yield builder if block_given?
end

#inspectObject



82
83
84
# File 'lib/restforce/concerns/base.rb', line 82

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

#instance_urlObject



77
78
79
80
# File 'lib/restforce/concerns/base.rb', line 77

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