class Holistics::ApiClient
Public Instance Methods
build_submit_params(options)
click to toggle source
# File lib/holistics/api_client.rb, line 146 def build_submit_params(options) params = options.except(:config_path) if options[:config_path] params[:configs] = parse_transport_config(options[:config_path]).to_json end params end
dbt_upload(filepath, ds_name)
click to toggle source
# File lib/holistics/api_client.rb, line 168 def dbt_upload(filepath, ds_name); end
ds_list()
click to toggle source
# File lib/holistics/api_client.rb, line 44 def ds_list result = http_request.get 'data_sources.json', 'Error retrieving list of data sources' table = [%w[ID Type Name]] rows = result.map { |record| [record['id'], record['dbtype'], record['name']] } table.concat(rows) puts TabularFormatter.new(table).to_pretty_table end
generate_configs(options)
click to toggle source
# File lib/holistics/api_client.rb, line 127 def generate_configs(options) raise 'Output location is invalid.' unless Dir.exist?(options['output']) puts "Generating transport JSON config files to #{options['output']} directory..." result = http_request.post_json 'transports/generate_configs.json', options, 'Error generating transport configs' result.each do |table_data| File.open("#{options['output']}/#{table_data['filename']}", 'w') do |f| f.write(JSON.pretty_generate(table_data['json_content'])) end puts "Generated #{table_data['filename']}" end puts puts "Configs generation succeeded with #{result.length} files in total." end
import_csv(options)
click to toggle source
# File lib/holistics/api_client.rb, line 15 def import_csv(options) local_filepath = options[:filepath] dest_ds_id = options[:dest_ds_id] dest_fqname = options[:dest_table_name] begin file = File.open local_filepath rescue StandardError warn "Could not open file at '#{local_filepath}'." puts 'Invalid file path. Please check your file path.' return end puts "Read csv file '#{local_filepath}'." params = { dest_fqname: dest_fqname, dest_ds_id: dest_ds_id } json = http_request.post_file 'data_imports/import_csv.json', params, file, 'text/csv', 'Error uploading CSV file' job_id = json['message']['job_id'] puts "Job submitted. Job ID: #{job_id}." job_manager.tail_logs job_id.to_i end
import_list()
click to toggle source
# File lib/holistics/api_client.rb, line 54 def import_list result = http_request.get 'data_imports.json', 'Error retrieving list of data imports' table = [%w[ID Name]] rows = result.map { |record| [record['id'], record['title']] } table.concat(rows) puts TabularFormatter.new(table).to_pretty_table end
invoke_email_schedule(es_id, options)
click to toggle source
# File lib/holistics/api_client.rb, line 85 def invoke_email_schedule(es_id, options) puts "Invoking email schedule ID #{es_id}" result = http_request.post_json "email_schedules/#{es_id}/execute.json", options, 'Error submitting email schedule job' job_id = result['job_id'] puts "Job submitted. Job ID: #{job_id}." job_manager.tail_logs job_id end
job_show(options)
click to toggle source
# File lib/holistics/api_client.rb, line 122 def job_show(options) puts 'Getting job log...' job_manager.tail_logs options[:job_id] end
parse_transport_config(filepath)
click to toggle source
# File lib/holistics/api_client.rb, line 154 def parse_transport_config(filepath) file_ext = File.extname(filepath).downcase if file_ext == '.json' JSON.parse(File.read(filepath)) elsif file_ext == '.yml' YAML.safe_load(File.read(filepath)) else raise StandardError, 'Invalid config file extension. Please use either JSON or YML' end rescue StandardError => e warn "Error parsing transport config file: #{e.message}" exit 1 end
send_import(options)
click to toggle source
# File lib/holistics/api_client.rb, line 107 def send_import(options) puts 'Invoking import job...' result = http_request.post_json "data_imports/#{options[:import_id]}/execute.json", options, 'Error submitting import job' job_id = result['job_id'] puts "Job submitted. Job ID: #{job_id}." job_manager.tail_logs job_id res = job_manager.fetch_job_results job_id unless res['status'] == 'success' raise ImportError, "Failed Import Job #{job_id}: #{res['error']}" end end
send_transform(options)
click to toggle source
# File lib/holistics/api_client.rb, line 96 def send_transform(options) puts 'Invoking transform job...' result = http_request.post_json "data_transforms/#{options[:transform_id]}/execute.json", options, 'Error submitting transform job' job_id = result['job_id'] puts "Job submitted. Job ID: #{job_id}." job_manager.tail_logs job_id end
send_transport(options)
click to toggle source
# File lib/holistics/api_client.rb, line 74 def send_transport(options) puts 'Submitting transport job ...' params = build_submit_params(options) result = http_request.post_json('transports/submit.json', params, 'Error submitting transport job') job_id = result['job_id'] puts "Job submitted. Job ID: #{job_id}." job_manager.tail_logs job_id end
transform_list()
click to toggle source
# File lib/holistics/api_client.rb, line 64 def transform_list result = http_request.get 'data_transforms.json', 'Error retrieving list of data transports' table = [%w[ID Name]] rows = result.map { |record| [record['id'], record['title']] } table.concat(rows) puts TabularFormatter.new(table).to_pretty_table end
Private Instance Methods
auth_info()
click to toggle source
# File lib/holistics/api_client.rb, line 184 def auth_info @auth_info ||= Helpers::AuthInfo.new end
file_manager()
click to toggle source
# File lib/holistics/api_client.rb, line 172 def file_manager @file_manager ||= Helpers::FileManager.new end
http_request()
click to toggle source
# File lib/holistics/api_client.rb, line 180 def http_request @http_helper ||= Helpers::HttpRequest.new end
job_manager()
click to toggle source
# File lib/holistics/api_client.rb, line 176 def job_manager @job_helper ||= Helpers::JobManager.new end