module Restforce::DB

Restforce::DB exposes basic Restforce client configuration methods for use by the other classes in this library.

Constants

HASH_DICTIONARY

Internal: A String containing the valid suffix Hash values for a Salesforce ID.

TaskMapping

TaskMapping is a small data structure used to pass top-level task information through to a SynchronizationError when necessary.

VERSION

Attributes

configuration[W]
last_run[RW]

Public Class Methods

client() click to toggle source

Public: Get a Restforce client based on the currently configured settings.

Returns a Restforce::Data::Client instance.

# File lib/restforce/db.rb, line 86
def self.client
  @client ||= begin
    DB::Client.new(
      username:       configuration.username,
      password:       configuration.password,
      security_token: configuration.security_token,
      client_id:      configuration.client_id,
      client_secret:  configuration.client_secret,
      host:           configuration.host,
      api_version:    configuration.api_version,
      timeout:        configuration.timeout,
      adapter:        configuration.adapter,
    )
  end
end
configuration() click to toggle source

Public: Get the current configuration for Restforce::DB.

Returns a Restforce::DB::Configuration instance.

# File lib/restforce/db.rb, line 79
def self.configuration
  @configuration ||= Configuration.new
end
configure() { |configuration| ... } click to toggle source

Public: Configure Restforce::DB by assigning values to the current configuration.

Yields the current configuration. Returns the current configuration.

# File lib/restforce/db.rb, line 115
def self.configure
  yield(configuration)
  configuration
end
hashed_id(salesforce_id) click to toggle source

Public: Get the hashed version of the passed salesforce ID. This will converts 15-digit Salesforce IDs to their corresponding 18-digit version. Returns any passed 18-digit IDs back, untouched.

Returns a String. Raises an ArgumentError if the passed String is not 15 characters.

# File lib/restforce/db.rb, line 153
def self.hashed_id(salesforce_id)
  return salesforce_id if salesforce_id.length == 18
  raise ArgumentError, "The passed Salesforce ID must be 15 or 18 characters" unless salesforce_id.length == 15

  suffixes = salesforce_id.scan(/.{5}/).map do |chunk|
    flag = 0
    chunk.split("").each_with_index do |char, idx|
      flag += (1 << idx) if char >= "A" && char <= "Z"
    end

    HASH_DICTIONARY[flag]
  end

  salesforce_id + suffixes.join
end
reset() click to toggle source

Public: Clear all globally cached values for Restforce::DB.

NOTE: This is an “idempotent” reset; following invocation, all functions should still work as before, but globally cached values will be repopulated.

Returns nothing.

# File lib/restforce/db.rb, line 127
def self.reset
  FieldProcessor.reset
  @user_id = nil
  @client = nil
end
reset!() click to toggle source

Public: Eliminate all customizations to the current Restforce::DB configuration and client.

NOTE: This is a hard reset; following invocation, Restforce::DB will need to be reconfigured in order for functionality to be restored.

Returns nothing.

# File lib/restforce/db.rb, line 140
def self.reset!
  reset

  @configuration = nil
  @last_run = nil
end
user_id() click to toggle source

Public: Get the ID of the Salesforce user which is being used to access the Salesforce API.

Returns a String.

# File lib/restforce/db.rb, line 106
def self.user_id
  @user_id ||= client.user_info.user_id
end