Class: Xapixctl::PhoenixClient::ProjectConnection
- Inherits:
-
OrganizationConnection
- Object
- OrganizationConnection
- Xapixctl::PhoenixClient::ProjectConnection
- Defined in:
- lib/xapixctl/phoenix_client/project_connection.rb
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Attributes inherited from OrganizationConnection
Instance Method Summary collapse
-
#accept_data_source_preview(data_source_id, &block) ⇒ Object
This returns a hashified preview like the following:.
-
#add_rest_data_source(http_method:, url:, path_params: {}, headers: {}, cookies: {}, body: nil, auth_schemes: [], &block) ⇒ Object
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.
- #add_schema_import(spec_filename, &block) ⇒ Object
-
#data_source_preview(data_source_id, authentications: {}, &block) ⇒ Object
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.
- #endpoint_preview(endpoint_id, format: :hash, &block) ⇒ Object
-
#initialize(connection, org, project) ⇒ ProjectConnection
constructor
A new instance of ProjectConnection.
- #logs(correlation_id, &block) ⇒ Object
- #organization ⇒ Object
- #pipeline_preview(pipeline_id, format: :hash, &block) ⇒ Object
- #project_resource(format: :hash, &block) ⇒ Object
- #public_project_url ⇒ Object
- #publish(&block) ⇒ Object
- #resource_types_for_export ⇒ Object
- #stream_processor_preview(stream_processor_id, format: :hash, &block) ⇒ Object
- #update_schema_import(schema_import, spec_filename, &block) ⇒ Object
Methods inherited from OrganizationConnection
#apply, #delete, #resource, #resource_ids
Constructor Details
#initialize(connection, org, project) ⇒ ProjectConnection
Returns a new instance of ProjectConnection.
8 9 10 11 |
# File 'lib/xapixctl/phoenix_client/project_connection.rb', line 8 def initialize(connection, org, project) super(connection, org) @project = project end |
Instance Attribute Details
#project ⇒ Object (readonly)
Returns the value of attribute project.
6 7 8 |
# File 'lib/xapixctl/phoenix_client/project_connection.rb', line 6 def project @project end |
Instance Method Details
#accept_data_source_preview(data_source_id, &block) ⇒ Object
This returns a hashified preview like the following:
124 125 126 127 |
# 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 |
#add_rest_data_source(http_method:, url:, path_params: {}, headers: {}, cookies: {}, body: nil, auth_schemes: [], &block) ⇒ Object
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
48 49 50 51 52 53 54 55 56 57 58 |
# 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: .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 |
#add_schema_import(spec_filename, &block) ⇒ Object
79 80 81 82 83 |
# 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 |
#data_source_preview(data_source_id, authentications: {}, &block) ⇒ Object
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 } }
71 72 73 74 75 76 77 |
# 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 |
#endpoint_preview(endpoint_id, format: :hash, &block) ⇒ Object
98 99 100 101 102 103 |
# 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 |
#logs(correlation_id, &block) ⇒ Object
117 118 119 120 |
# 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 |
#organization ⇒ Object
17 18 19 |
# File 'lib/xapixctl/phoenix_client/project_connection.rb', line 17 def organization OrganizationConnection.new(@connection, @org) end |
#pipeline_preview(pipeline_id, format: :hash, &block) ⇒ Object
91 92 93 94 95 96 |
# 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 |
#project_resource(format: :hash, &block) ⇒ Object
13 14 15 |
# File 'lib/xapixctl/phoenix_client/project_connection.rb', line 13 def project_resource(format: :hash, &block) organization.resource('Project', @project, format: format, &block) end |
#public_project_url ⇒ Object
129 130 131 |
# File 'lib/xapixctl/phoenix_client/project_connection.rb', line 129 def public_project_url File.join(@connection.xapix_url, @org, @project) end |
#publish(&block) ⇒ Object
112 113 114 115 |
# File 'lib/xapixctl/phoenix_client/project_connection.rb', line 112 def publish(&block) result_handler(block). run { @client[project_publications_path].post('') } end |
#resource_types_for_export ⇒ Object
21 22 23 24 25 26 27 28 29 |
# 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 |
#stream_processor_preview(stream_processor_id, format: :hash, &block) ⇒ Object
105 106 107 108 109 110 |
# 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 |
#update_schema_import(schema_import, spec_filename, &block) ⇒ Object
85 86 87 88 89 |
# 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 |