class Xapixctl::PhoenixClient::ProjectConnection
Attributes
Public Class Methods
Xapixctl::PhoenixClient::OrganizationConnection::new
# File lib/xapixctl/phoenix_client/project_connection.rb, line 8 def initialize(connection, org, project) super(connection, org) @project = project end
Public Instance Methods
This returns a hashified preview like the following:
# File lib/xapixctl/phoenix_client/project_connection.rb, line 124 def accept_data_source_preview(data_source_id, &block) result_handler(block). run { @client[data_source_preview_path(data_source_id)].patch('') } end
Notes on parameters:
-
Query parameters should be part of the URL
-
Path parameters should be marked with `{name}` in the URL, and values should be given in path_params hash
-
Headers should be given in headers hash
-
Cookies should be given in cookies hash
-
The body has to be given as a string
-
The required authentication schemes should be listed, referring to previously created schemes
This returns a hash like the following:
"data_source" => { "id" => id, "resource_description" => resource_description }
To successfully onboard a DB using the API, the following steps are needed:
1. setup the data source using add_rest_data_source. 2. retrieve a preview using preview_data_source using the id returned by previous step 3. confirm preview 4. call accept_data_source_preview to complete onboarding
# File lib/xapixctl/phoenix_client/project_connection.rb, line 48 def add_rest_data_source(http_method:, url:, path_params: {}, headers: {}, cookies: {}, body: nil, auth_schemes: [], &block) data_source_details = { data_source: { http_method: http_method, url: url, parameters: { path: path_params.to_query, header: headers.to_query, cookies: cookies.to_query, body: body }, auth_schemes: auth_schemes } } result_handler(block). run { @client[rest_data_source_path].post(data_source_details.to_json, content_type: :json) } end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 79 def add_schema_import(spec_filename, &block) spec_data = { schema_import: { file: File.new(spec_filename, 'r') } } result_handler(block). run { @client[schema_imports_path].post(spec_data) } end
Notes on parameters:
-
To call a data source which requires authentication, provide a hash with each required auth scheme as key and as the value a reference to a previously created credential. Example: { scheme_ref1 => credential_ref1, scheme_ref2 => credential_ref2 }
This returns a hashified preview like the following:
{ "preview" => { "sample" => { "status" => integer, "body" => { ... }, "headers" => { ... }, "cookies" => { ... } }, "fetched_at" => Timestamp }, "data_source" => { "id" => id, "resource_description" => resource_description } }
# File lib/xapixctl/phoenix_client/project_connection.rb, line 71 def data_source_preview(data_source_id, authentications: {}, &block) preview_data = { authentications: authentications.map { |scheme, cred| { auth_scheme_id: scheme, auth_credential_id: cred } } } result_handler(block). run { @client[data_source_preview_path(data_source_id)].post(preview_data.to_json, content_type: :json) } end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 98 def endpoint_preview(endpoint_id, format: :hash, &block) result_handler(block). prepare_data(->(data) { data['endpoint_preview'] }). formatter(PREVIEW_FORMATTERS[format]). run { @client[endpoint_preview_path(endpoint_id)].get } end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 117 def logs(correlation_id, &block) result_handler(block). run { @client[project_logss_path(correlation_id)].get } end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 17 def organization OrganizationConnection.new(@connection, @org) end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 91 def pipeline_preview(pipeline_id, format: :hash, &block) result_handler(block). prepare_data(->(data) { data['pipeline_preview'] }). formatter(PREVIEW_FORMATTERS[format]). run { @client[pipeline_preview_path(pipeline_id)].get } end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 13 def project_resource(format: :hash, &block) organization.resource('Project', @project, format: format, &block) end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 129 def public_project_url File.join(@connection.xapix_url, @org, @project) end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 112 def publish(&block) result_handler(block). run { @client[project_publications_path].post('') } end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 21 def resource_types_for_export @resource_types_for_export ||= @connection.available_resource_types do |res| res.on_success do |available_types| prj_types = available_types.select { |desc| desc['context'] == 'Project' } SUPPORTED_RESOURCE_TYPES & prj_types.map { |desc| desc['type'] } end end end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 105 def stream_processor_preview(stream_processor_id, format: :hash, &block) result_handler(block). prepare_data(->(data) { data['stream_processor_preview'] }). formatter(PREVIEW_FORMATTERS[format]). run { @client[stream_processor_preview_path(stream_processor_id)].get } end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 85 def update_schema_import(schema_import, spec_filename, &block) spec_data = { schema_import: { file: File.new(spec_filename, 'r') } } result_handler(block). run { @client[schema_import_path(schema_import)].patch(spec_data) } end
Private Instance Methods
# File lib/xapixctl/phoenix_client/project_connection.rb, line 139 def data_source_preview_path(id) "/projects/#{@org}/#{@project}/onboarding/data_sources/#{id}/preview" end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 167 def endpoint_preview_path(endpoint) "/projects/#{@org}/#{@project}/endpoints/#{endpoint}/preview" end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 159 def generic_resource_path "projects/#{@org}/#{@project}/resource" end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 163 def pipeline_preview_path(pipeline) "/projects/#{@org}/#{@project}/pipelines/#{pipeline}/preview" end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 179 def project_logss_path(correlation_id) "/projects/#{@org}/#{@project}/logs/#{correlation_id}" end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 175 def project_publications_path "/projects/#{@org}/#{@project}/publications" end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 151 def resource_path(type, id) "/projects/#{@org}/#{@project}/#{translate_type(type)}/#{id}" end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 155 def resources_path(type) "/projects/#{@org}/#{@project}/#{translate_type(type)}" end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 135 def rest_data_source_path "/projects/#{@org}/#{@project}/onboarding/data_sources/rest" end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 147 def schema_import_path(schema_import) "/projects/#{@org}/#{@project}/onboarding/schema_imports/#{schema_import}" end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 143 def schema_imports_path "/projects/#{@org}/#{@project}/onboarding/schema_imports" end
# File lib/xapixctl/phoenix_client/project_connection.rb, line 171 def stream_processor_preview_path(stream_processor) "/projects/#{@org}/#{@project}/stream_processors/#{stream_processor}/preview" end