forked from OpenSourcePolitics/metabase_automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rb
executable file
·48 lines (40 loc) · 1.47 KB
/
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
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
41
42
43
44
45
46
47
48
#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative "lib/decidim_metabase"
require "securerandom"
require "faraday"
require "faraday/net_http"
require "dotenv/load"
require "yaml"
require "colorize"
Faraday.default_adapter = :net_http
main = DecidimMetabase::Main.new(true)
## Interesting things below...
begin
main.tap do |obj|
puts "Enter name of YML file without extension containing informations (ex:config-berlin): "
obj.configs = DecidimMetabase::Config.new("#{gets.chomp}.yml")
obj.define_connexion!
obj.define_api_session!
obj.define_http_request!
obj.define_api_database!
obj.set_databases!
obj.set_api_cards!
obj.set_collections!
end
puts "Cards prepared to be saved in Metabase '#{main.filesystem_collection.cards.map(&:name).join(", ")}'"
.colorize(:yellow)
if main.create_new_cards?
puts "Creating new cards #{main.filesystem_collection.cards.map(&:name) - main.metabase_collection.cards.map(&:name)}"
.colorize(:light_green)
end
main.store_and_update_cards!
puts "Program successfully terminated (Exit code: 0)".colorize(:light_green)
exit 0
rescue StandardError => e
puts "[#{e.class}] #{e.message} (Exit code: 2)".colorize(:light_red)
puts e.backtrace.join("\n").colorize(:light_red) if ARGV.include?("-v")
puts "You can enable verbose mode using '-v' to have the backtrace".colorize(:light_yellow) unless ARGV.include?("-v")
puts "Operation terminated".colorize(:light_red)
exit 2
end