Method: Databasedotcom::Client#initialize

Defined in:
lib/databasedotcom/client.rb

#initialize(options = {}) ⇒ Client

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: .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



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/databasedotcom/client.rb', line 64

def initialize(options = {})
  if options.is_a?(String)
    @options = YAML.load_file(options)
    @options["verify_mode"] = @options["verify_mode"].constantize if @options["verify_mode"] && @options["verify_mode"].is_a?(String)
  else
    @options = options
  end
  @options.symbolize_keys!

  if ENV['DATABASE_COM_URL']
    url = URI.parse(ENV['DATABASE_COM_URL'])
    url_options = Hash[url.query.split("&").map{|q| q.split("=")}].symbolize_keys!
    self.host = url.host
    self.client_id = url_options[:oauth_key]
    self.client_secret = url_options[:oauth_secret]
    self.username = url_options[:user]
    self.password = url_options[:password]
  else
    self.client_id = ENV['DATABASEDOTCOM_CLIENT_ID'] || @options[:client_id]
    self.client_secret = ENV['DATABASEDOTCOM_CLIENT_SECRET'] || @options[:client_secret]
    self.host = ENV['DATABASEDOTCOM_HOST'] || @options[:host] || "login.salesforce.com"
  end

  self.debugging = ENV['DATABASEDOTCOM_DEBUGGING'] || @options[:debugging]
  self.version = ENV['DATABASEDOTCOM_VERSION'] || @options[:version]
  self.version = self.version.to_s if self.version
  self.sobject_module = ENV['DATABASEDOTCOM_SOBJECT_MODULE'] || @options[:sobject_module]
  self.ca_file = ENV['DATABASEDOTCOM_CA_FILE'] || @options[:ca_file]
  self.verify_mode = ENV['DATABASEDOTCOM_VERIFY_MODE'] || @options[:verify_mode]
  self.verify_mode = self.verify_mode.to_i if self.verify_mode
end