Method: KineticSdk::Integrator#initialize
- Defined in:
- lib/kinetic_sdk/integrator/integrator-sdk.rb
#initialize(opts) ⇒ Integrator
Initalize the Integrator SDK with the web server URL and configuration user credentials, along with any custom option values.
Example: using a configuration file
KineticSdk::Integrator.new({
config_file: "/opt/config1.yaml"
})
Example: space user properties hash
KineticSdk::Integrator.new({
space_server_url: "https://my-space.domain",
space_slug: "my-space",
username: "admin",
password: "password",
options: {
log_level: "debug",
oauth_client_id: "my-oauth-user-id",
oauth_client_secret: "my-oauth-user-secret",
ssl_verify_mode: "peer",
ssl_ca_file: "/usr/local/self_signing_ca.pem"
}
})
If the +config_file+ option is present, it will be loaded first, and any additional options will overwrite any values in the config file
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/kinetic_sdk/integrator/integrator-sdk.rb', line 71 def initialize(opts) # initialize any variables = {} # process the configuration file if it was provided unless opts[:config_file].nil? .merge!(YAML::load_file opts[:config_file]) end # process the configuration hash if it was provided .merge!(opts) # allow one of :app_server_url, :space_server_url, or :integrator_server_url # but not more than one if [:app_server_url] && [:space_server_url] raise StandardError.new "Expecting either :app_server_url or :space_server_url, but not both." end if [:app_server_url].nil? && [:space_server_url].nil? raise StandardError.new "Expecting either :app_server_url or :space_server_url." end # process any individual options = [:options] || {} # setup logging log_level = [:log_level] || ["log_level"] log_output = [:log_output] || ["log_output"] @logger = KineticSdk::Utils::KLogger.new(log_level, log_output) @username = [:username] @space_slug = [:space_slug] if [:app_server_url] @server = [:app_server_url].chomp("/") @api_url = "#{@server}/api" else raise StandardError.new "The :space_slug option is required when using the :space_server_url option" if @space_slug.nil? @server = [:space_server_url].chomp("/") @api_url = "#{@server}/app/integrator/api" end @jwt = @space_slug.nil? ? nil : generate_jwt() @version = 1 end |