Class: KineticSdk::Integrator
- Inherits:
-
Object
- Object
- KineticSdk::Integrator
- Includes:
- Utils::KineticHttpUtils
- Defined in:
- lib/kinetic_sdk/integrator/integrator-sdk.rb,
lib/kinetic_sdk/integrator/lib/metadata.rb,
lib/kinetic_sdk/integrator/lib/operations.rb,
lib/kinetic_sdk/integrator/lib/connections.rb
Overview
Integrator is a Ruby class that acts as a wrapper for the Kinetic Integrator REST API without having to make explicit HTTP requests.
Instance Attribute Summary collapse
-
#api_url ⇒ Object
readonly
Returns the value of attribute api_url.
-
#jwt ⇒ Object
readonly
Returns the value of attribute jwt.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#space_slug ⇒ Object
readonly
Returns the value of attribute space_slug.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#add_connection(properties = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Add a Connection.
-
#add_operation(connection_id, properties = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Add an Operation.
-
#app_version(headers = header_accept_json) ⇒ KineticSdk::Utils::KineticHttpResponse
Retrieve Integrator application version.
-
#delete_connection(connection_id, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Delete a connection.
-
#delete_operation(connection_id, operation_id, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Delete an operation.
-
#execute_operation(connection_id, operation_id, parameters = {}, debug = false, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Execute an Operation.
-
#find_connection(connection_id, params = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Find a Connection.
-
#find_connections(params = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Find Connections.
-
#find_operation(connection_id, operation_id, params = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Find an Operation.
-
#find_operations(connection_id, params = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Find Operations for a Connection.
-
#generate_jwt(options = {}) ⇒ Object
Generate a JWT for bearer authentication based on the user credentials, and oauth client configuration.
-
#health(headers = header_accept_json) ⇒ KineticSdk::Utils::KineticHttpResponse
Check Integrator health.
-
#initialize(opts) ⇒ Integrator
constructor
Initalize the Integrator SDK with the web server URL and configuration user credentials, along with any custom option values.
-
#inspect_operation(operation_id, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Inspect an Operation.
-
#kinetic_core_sdk(options) ⇒ Object
Creates a reference to the Kinetic Request CE SDK.
-
#oas(headers = header_accept_json) ⇒ KineticSdk::Utils::KineticHttpResponse
OpenApi Specification.
-
#test_saved_connection(connection_id, properties = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Test a saved Connection.
-
#test_unsaved_connection(properties = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Test an unsaved Connection.
-
#update_connection(connection_id, properties = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Update a Connection.
-
#update_operation(connection_id, operation_id, properties = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Update an Operation.
Methods included from Utils::KineticHttpUtils
#default_headers, default_headers, #default_jwt_headers, default_jwt_headers, #delete, #encode, #gateway_retry_delay, #gateway_retry_limit, #get, #head, #header_accept_json, header_accept_json, #header_basic_auth, header_basic_auth, header_bearer_auth, #header_bearer_auth, #header_content_json, header_content_json, header_user_agent, #header_user_agent, #max_redirects, #mimetype, #patch, #post, #post_multipart, #put, #redirect_url, #stream_download_to_file
Constructor Details
#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 = [: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 = [: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 |
Instance Attribute Details
#api_url ⇒ Object (readonly)
Returns the value of attribute api_url.
13 14 15 |
# File 'lib/kinetic_sdk/integrator/integrator-sdk.rb', line 13 def api_url @api_url end |
#jwt ⇒ Object (readonly)
Returns the value of attribute jwt.
13 14 15 |
# File 'lib/kinetic_sdk/integrator/integrator-sdk.rb', line 13 def jwt @jwt end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
13 14 15 |
# File 'lib/kinetic_sdk/integrator/integrator-sdk.rb', line 13 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/kinetic_sdk/integrator/integrator-sdk.rb', line 13 def @options end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
13 14 15 |
# File 'lib/kinetic_sdk/integrator/integrator-sdk.rb', line 13 def server @server end |
#space_slug ⇒ Object (readonly)
Returns the value of attribute space_slug.
13 14 15 |
# File 'lib/kinetic_sdk/integrator/integrator-sdk.rb', line 13 def space_slug @space_slug end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
13 14 15 |
# File 'lib/kinetic_sdk/integrator/integrator-sdk.rb', line 13 def username @username end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
13 14 15 |
# File 'lib/kinetic_sdk/integrator/integrator-sdk.rb', line 13 def version @version end |
Instance Method Details
#add_connection(properties = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Add a Connection
13 14 15 16 |
# File 'lib/kinetic_sdk/integrator/lib/connections.rb', line 13 def add_connection(properties={}, headers=default_jwt_headers) @logger.info("Adding the #{properties['type']} connection named #{properties['name']}") post("#{@api_url}/connections", properties, headers) end |
#add_operation(connection_id, properties = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Add an Operation
15 16 17 18 19 |
# File 'lib/kinetic_sdk/integrator/lib/operations.rb', line 15 def add_operation(connection_id, properties={}, headers=default_jwt_headers) @logger.info("Adding the #{properties['name']} operation") @logger.info("Operation properties: #{properties.inspect}") post("#{@api_url}/connections/#{connection_id}/operations", properties, headers) end |
#app_version(headers = header_accept_json) ⇒ KineticSdk::Utils::KineticHttpResponse
Retrieve Integrator application version
8 9 10 11 |
# File 'lib/kinetic_sdk/integrator/lib/metadata.rb', line 8 def app_version(headers=header_accept_json) @logger.info("Retrieving Integrator version.") get("#{@api_url}/version", {}, headers) end |
#delete_connection(connection_id, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Delete a connection
23 24 25 26 |
# File 'lib/kinetic_sdk/integrator/lib/connections.rb', line 23 def delete_connection(connection_id, headers=default_jwt_headers) @logger.info("Deleting Connection \"#{connection_id}\"") delete("#{@api_url}/connections/#{connection_id}", headers) end |
#delete_operation(connection_id, operation_id, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Delete an operation
27 28 29 30 |
# File 'lib/kinetic_sdk/integrator/lib/operations.rb', line 27 def delete_operation(connection_id, operation_id, headers=default_jwt_headers) @logger.info("Deleting Operation \"#{operation_id}\"") delete("#{@api_url}/connections/#{connection_id}/operations/#{operation_id}", headers) end |
#execute_operation(connection_id, operation_id, parameters = {}, debug = false, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Execute an Operation
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/kinetic_sdk/integrator/lib/operations.rb', line 76 def execute_operation(connection_id, operation_id, parameters={}, debug=false, headers=default_jwt_headers) @logger.info("Executing operation #{operation_id}") payload = { "connectionId" => connection_id, "operationId" => operation_id, "parameters" => parameters } url = "#{@api_url}/execute" url = "#{url}?debug=true" if debug post(url, payload, headers) end |
#find_connection(connection_id, params = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Find a Connection
44 45 46 47 |
# File 'lib/kinetic_sdk/integrator/lib/connections.rb', line 44 def find_connection(connection_id, params={}, headers=default_jwt_headers) @logger.info("Finding Connection \"#{connection_id}\"") get("#{@api_url}/connections/#{connection_id}", params, headers) end |
#find_connections(params = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Find Connections
33 34 35 36 |
# File 'lib/kinetic_sdk/integrator/lib/connections.rb', line 33 def find_connections(params={}, headers=default_jwt_headers) @logger.info("Finding Connections") get("#{@api_url}/connections", params, headers) end |
#find_operation(connection_id, operation_id, params = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Find an Operation
50 51 52 53 |
# File 'lib/kinetic_sdk/integrator/lib/operations.rb', line 50 def find_operation(connection_id, operation_id, params={}, headers=default_jwt_headers) @logger.info("Finding Operation \"#{operation_id}\"") get("#{@api_url}/connections/#{connection_id}/operations/#{operation_id}", params, headers) end |
#find_operations(connection_id, params = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Find Operations for a Connection
38 39 40 41 |
# File 'lib/kinetic_sdk/integrator/lib/operations.rb', line 38 def find_operations(connection_id, params={}, headers=default_jwt_headers) @logger.info("Finding Operations") get("#{@api_url}/connections/#{connection_id}/operations", params, headers) end |
#generate_jwt(options = {}) ⇒ Object
Generate a JWT for bearer authentication based on the user credentials, and oauth client configuration.
117 118 119 120 121 122 |
# File 'lib/kinetic_sdk/integrator/integrator-sdk.rb', line 117 def generate_jwt( = {}) oauth_client_id = [:options][:oauth_client_id] oauth_client_secret = [:options][:oauth_client_secret] jwt_response = kinetic_core_sdk().jwt_token(oauth_client_id, oauth_client_secret) jwt_response.content["access_token"] end |
#health(headers = header_accept_json) ⇒ KineticSdk::Utils::KineticHttpResponse
Check Integrator health
17 18 19 20 |
# File 'lib/kinetic_sdk/integrator/lib/metadata.rb', line 17 def health(headers=header_accept_json) @logger.info("Retrieving Integrator health.") get("#{@api_url}/healthz", {}, headers) end |
#inspect_operation(operation_id, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Inspect an Operation
93 94 95 96 97 98 99 100 |
# File 'lib/kinetic_sdk/integrator/lib/operations.rb', line 93 def inspect_operation(operation_id, headers=default_jwt_headers) @logger.info("Inspecting operation #{operation_id}") payload = { "operationId" => operation_id } url = "#{@api_url}/inspect" post(url, payload, headers) end |
#kinetic_core_sdk(options) ⇒ Object
Creates a reference to the Kinetic Request CE SDK
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/kinetic_sdk/integrator/integrator-sdk.rb', line 125 def kinetic_core_sdk() = { space_slug: [:space_slug], username: [:username], password: [:password], options: [:options] || {}, } if [:app_server_url] [:app_server_url] = [:app_server_url] else [:space_server_url] = [:space_server_url] end KineticSdk::Core.new() end |
#oas(headers = header_accept_json) ⇒ KineticSdk::Utils::KineticHttpResponse
OpenApi Specification
26 27 28 29 |
# File 'lib/kinetic_sdk/integrator/lib/metadata.rb', line 26 def oas(headers=header_accept_json) @logger.info("Retrieving OpenAPI Specification.") get("#{@api_url}/oas", {}, headers) end |
#test_saved_connection(connection_id, properties = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Test a saved Connection
77 78 79 80 |
# File 'lib/kinetic_sdk/integrator/lib/connections.rb', line 77 def test_saved_connection(connection_id, properties={}, headers=default_jwt_headers) @logger.info("Testing saved connection: #{connection_id}") post("#{@api_url}/connections/#{connection_id}/test", properties, headers) end |
#test_unsaved_connection(properties = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Test an unsaved Connection
66 67 68 69 |
# File 'lib/kinetic_sdk/integrator/lib/connections.rb', line 66 def test_unsaved_connection(properties={}, headers=default_jwt_headers) @logger.info("Testing unsaved connection") post("#{@api_url}/test", properties, headers) end |
#update_connection(connection_id, properties = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Update a Connection
56 57 58 59 |
# File 'lib/kinetic_sdk/integrator/lib/connections.rb', line 56 def update_connection(connection_id, properties={}, headers=default_jwt_headers) @logger.info("Updating Connection \"#{connection_id}\"") put("#{@api_url}/connections/#{connection_id}", properties, headers) end |
#update_operation(connection_id, operation_id, properties = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse
Update an Operation
63 64 65 66 |
# File 'lib/kinetic_sdk/integrator/lib/operations.rb', line 63 def update_operation(connection_id, operation_id, properties={}, headers=default_jwt_headers) @logger.info("Updating Operation \"#{operation_id}\"") put("#{@api_url}/connections/#{connection_id}/operations/#{operation_id}", properties, headers) end |