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

Parameters:

  • opts (Hash)

    Kinetic Integrator properties

Options Hash (opts):

  • :config_file (String)

    optional - path to the YAML configuration file

    • Ex: /opt/config/integrator-configuration1.yaml
  • :app_server_url (String)

    the URL to the integrator server

  • :space_server_url (String)

    the URL to the Kinetic Request CE web space

  • :space_slug (String)

    the slug that identifies the Space

  • :username (String)

    the username for the user

  • :password (String)

    the password for the user

  • :options (Hash<Symbol, Object>) — default: {}

    optional settings

    • :export_directory (String) (_example: /opt/exports/integrator) directory to write files when exporting,
    • :gateway_retry_limit (FixNum) (defaults to: 5) max number of times to retry a bad gateway
    • :gateway_retry_delay (Float) (defaults to: 1.0) number of seconds to delay before retrying a bad gateway
    • :log_level (String) (defaults to: off) level of logging - off | error | warn | info | debug
    • :log_output (String) (defaults to: STDOUT) where to send output - STDOUT | STDERR
    • :max_redirects (Fixnum) (defaults to: 5) maximum number of redirects to follow
    • :oauth_client_id (String) id of the Kinetic Core oauth client
    • :oauth_client_secret (String) secret of the Kinetic Core oauth client
    • :ssl_ca_file (String) full path to PEM certificate used to verify the server
    • :ssl_verify_mode (String) (defaults to: none) - none | peer


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
  options = {}

  # process the configuration file if it was provided
  unless opts[:config_file].nil?
    options.merge!(YAML::load_file opts[:config_file])
  end

  # process the configuration hash if it was provided
  options.merge!(opts)

  # allow one of :app_server_url, :space_server_url, or :integrator_server_url
  # but not more than one
  if options[:app_server_url] && options[:space_server_url]
    raise StandardError.new "Expecting either :app_server_url or :space_server_url, but not both."
  end

  if options[:app_server_url].nil? && options[:space_server_url].nil?
    raise StandardError.new "Expecting either :app_server_url or :space_server_url."
  end

  # process any individual options
  @options = options[:options] || {}
  # setup logging
  log_level = @options[:log_level] || @options["log_level"]
  log_output = @options[:log_output] || @options["log_output"]
  @logger = KineticSdk::Utils::KLogger.new(log_level, log_output)

  @username = options[:username]
  @space_slug = options[:space_slug]

  if options[:app_server_url]
    @server = options[: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 = options[:space_server_url].chomp("/")
    @api_url = "#{@server}/app/integrator/api"
  end
  @jwt = @space_slug.nil? ? nil : generate_jwt(options)
  @version = 1
end