Class: Holistics::ApiClient
- Inherits:
-
Object
- Object
- Holistics::ApiClient
- Defined in:
- lib/holistics/api_client.rb
Defined Under Namespace
Classes: ImportError
Instance Method Summary collapse
- #build_submit_params(options) ⇒ Object
- #ds_list ⇒ Object
- #generate_configs(options) ⇒ Object
- #import_csv(options) ⇒ Object
- #import_list ⇒ Object
- #invoke_email_schedule(es_id, options) ⇒ Object
- #job_show(options) ⇒ Object
- #parse_transport_config(filepath) ⇒ Object
- #send_import(options) ⇒ Object
- #send_transform(options) ⇒ Object
- #send_transport(options) ⇒ Object
- #transform_list ⇒ Object
Instance Method Details
#build_submit_params(options) ⇒ Object
146 147 148 149 150 |
# File 'lib/holistics/api_client.rb', line 146 def build_submit_params() params = .except(:config_path) params[:configs] = parse_transport_config([:config_path]).to_json if [:config_path] params end |
#ds_list ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/holistics/api_client.rb', line 42 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) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/holistics/api_client.rb', line 125 def generate_configs() unless Dir.exist?(['output']) raise 'Output location is invalid.' end puts "Generating transport JSON config files to #{['output']} directory..." result = http_request.post_json 'transports/generate_configs.json', , 'Error generating transport configs' result.each do |table_data| File.open("#{['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) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/holistics/api_client.rb', line 13 def import_csv local_filepath = [:filepath] dest_ds_id = [:dest_ds_id] dest_fqname = [:dest_table_name] begin file = File.open local_filepath rescue STDERR.puts "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_csv 'data_imports/import_csv.json', params, file, '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 ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/holistics/api_client.rb', line 52 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) ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/holistics/api_client.rb', line 83 def invoke_email_schedule(es_id, ) puts "Invoking email schedule ID #{es_id}" result = http_request.post_json "email_schedules/#{es_id}/execute.json", , '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) ⇒ Object
120 121 122 123 |
# File 'lib/holistics/api_client.rb', line 120 def job_show() puts 'Getting job log...' job_manager.tail_logs [:job_id] end |
#parse_transport_config(filepath) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/holistics/api_client.rb', line 152 def parse_transport_config(filepath) file_ext = File.extname(filepath).downcase if file_ext == '.json' return JSON.parse(File.read(filepath)) elsif file_ext == '.yml' return YAML.load(File.read(filepath)) else raise StandardError.new 'Invalid config file extension. Please use either JSON or YML' end rescue StandardError => e STDERR.puts "Error parsing transport config file: #{e.}" exit 1 end |
#send_import(options) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/holistics/api_client.rb', line 105 def send_import() puts 'Invoking import job...' result = http_request.post_json "data_imports/#{[:import_id]}/execute.json", , '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.new("Failed Import Job #{job_id}: #{res['error']}") end end |
#send_transform(options) ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/holistics/api_client.rb', line 94 def send_transform() puts 'Invoking transform job...' result = http_request.post_json "data_transforms/#{[:transform_id]}/execute.json", , '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) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/holistics/api_client.rb', line 72 def send_transport() puts 'Submitting transport job ...' params = build_submit_params() 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 ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/holistics/api_client.rb', line 62 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 |