<commit_before># encoding=UTF-8
# GoodData Ruby SDK Environment Builder
require 'io/console'

puts "##########################################"
puts "# GOODDATA RUBY SDK: ENVIRONMENT BUILDER #"
puts "##########################################"
puts "Learn more at https://sdk.gooddata.com/gooddata-ruby/"

# User Credentials for GoodData Platform
time = "(#{Time.now.month}/#{Time.now.day}/#{Time.now.year})"
title = "My Ruby SDK Project #{time}"
model = './my_test_project/model/model.rb'
if ARGV[0] && ARGV[1] && ARGV[2]
  user = ARGV[0]
  password = ARGV[1]
  token = ARGV[2]
else
  puts '[GoodData] Let\'s start by logging you in and setting up a demo project.'
  puts '[GoodData] (1/3) Enter Developer TOKEN ("https://developer.gooddata.com/trial/"):'
  token = $stdin.gets.chomp!
  puts '[GoodData] (2/3) GoodData Username (ex. "<EMAIL>"):'
  user = $stdin.gets.chomp!
  puts "[GoodData] (3/3) GoodData Password for #{user}: (hidden)"
  password = STDIN.noecho(&:gets).strip!
end

# Check GoodData SDK Installation
begin
  gem "gooddata"
rescue LoadError
  puts "[GoodData] GoodData Ruby SDK has not been installed on this machine, would you like to install it? (y/n)"

  # Confirm the use would like to install GoodData
  c = $stdin.gets.chomp
  if c == "y" || c == "yes" || c == ""
    puts "[GoodData] Installing GoodData Ruby SDK..."
  	system("gem install nokogiri -- --use-system-libraries && gem install gooddata && git clone https://github.com/gooddata/gooddata-ruby-examples")
  	Gem.clear_paths
  else
    puts '[GoodData] Cancelled install of GoodData.'
    exit
  end
end

require 'gooddata'
require 'pp'

# Set up demo project, upload to user's GoodData, update GoodFile
puts '[GoodData] Installed GoodData SDK!'
puts "[GoodData] Downloading demo project..."
system("gooddata scaffold project my_test_project") unless File.directory?('./my_test_project')
updated_model = IO.readlines(model)
updated_model[0] = "GoodData::Model::ProjectBuilder.create(\"#{title}\") do |p|\n"
File.open(model, 'w') { |f|
  updated_model.each { |line| f.puts line }
}

GoodData.connect user, password
puts "[GoodData] Deploying demo project \"#{title}\" for #{user}. This can take up to 2 minutes..."
blueprint = eval(File.read('./my_test_project/model/model.rb')).to_blueprint
project = GoodData::Model::ProjectCreator.migrate(:token => token, :spec => blueprint)
puts "[GoodData] Updating Goodfile..."
File.open('./my_test_project/Goodfile', 'w') do |file|
  file.puts "{\n\"model\" : \"./model/model.rb\",\n\"project_id\" : \"#{project.pid}\"\n}"
end

puts "[GoodData] Success! These the details about your new demo project:"
puts "             User: #{user}"
puts "             Project Title: #{title}"
puts "             Project Identifier: #{project.pid}"<commit_msg> Prompt for Auth Store<commit_after># encoding=UTF-8
# GoodData Ruby SDK Environment Builder
require 'io/console'

puts "======================================="
puts "GOODDATA RUBY SDK: ENVIRONMENT BUILDER"
puts "======================================="
puts "Learn more at https://sdk.gooddata.com/gooddata-ruby/"

# User Credentials for GoodData Platform
time = "(#{Time.now.month}/#{Time.now.day}/#{Time.now.year})"
title = "My Ruby SDK Project #{time}"
model = './my_test_project/model/model.rb'
if ARGV[0] && ARGV[1] && ARGV[2]
  user = ARGV[0]
  password = ARGV[1]
  token = ARGV[2]
else
  puts '[GoodData] Let\'s start by logging you in and setting up a demo project.'
  puts '[GoodData] (1/3) Enter Developer TOKEN ("https://developer.gooddata.com/trial/"):'
  token = $stdin.gets.chomp!
  puts '[GoodData] (2/3) GoodData Username (ex. "<EMAIL>"):'
  user = $stdin.gets.chomp!
  puts "[GoodData] (3/3) GoodData Password for #{user}: (hidden)"
  password = STDIN.noecho(&:gets).strip!
end

# Check GoodData SDK Installation
begin
  gem "gooddata"
rescue LoadError
  puts "[GoodData] GoodData Ruby SDK has not been installed on this machine, would you like to install it? (y/n)"

  # Confirm the use would like to install GoodData
  c = $stdin.gets.chomp
  if c == "y" || c == "yes" || c == ""
    puts "[GoodData] Installing GoodData Ruby SDK..."
  	system("gem install nokogiri -- --use-system-libraries && gem install gooddata && git clone https://github.com/gooddata/gooddata-ruby-examples")
  	Gem.clear_paths
  else
    puts '[GoodData] Cancelled install of GoodData.'
    exit
  end
end

require 'gooddata'
require 'pp'

# Set up demo project, upload to user's GoodData, update GoodFile
puts '[GoodData] Installed GoodData SDK!'
puts "[GoodData] Downloading demo project..."
system("gooddata scaffold project my_test_project") unless File.directory?('./my_test_project')
updated_model = IO.readlines(model)
updated_model[0] = "GoodData::Model::ProjectBuilder.create(\"#{title}\") do |p|\n"
File.open(model, 'w') { |f|
  updated_model.each { |line| f.puts line }
}

GoodData.connect user, password
puts "[GoodData] Deploying demo project \"#{title}\" for #{user}. This can take up to 2 minutes..."
blueprint = eval(File.read('./my_test_project/model/model.rb')).to_blueprint
project = GoodData::Model::ProjectCreator.migrate(:token => token, :spec => blueprint)
puts "[GoodData] Updating Goodfile..."
File.open('./my_test_project/Goodfile', 'w') do |file|
  file.puts "{\n\"model\" : \"./model/model.rb\",\n\"project_id\" : \"#{project.pid}\"\n}"
end
puts '[GoodData] Would you like your computer to remember your login credentials?'

q = $stdin.gets.chomp
if q == "y" || q == "yes" || q == ""
  system("gooddata auth store")
end

puts "[GoodData] Success! These the details about your new demo project:"
puts "             User: #{user}"
puts "             Project Title: #{title}"
puts "             Project Identifier: #{project.pid}"
{'fraction_non_alphanumeric': 0.182628451590353, 'fraction_numerical': 0.005242922055225445, 'mean_word_length': 4.264949402023919, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1290301', 'n_tokens_mistral': 1930, 'n_tokens_neox': 1893, 'n_words': 557}