<commit_before># SpaceX API for searching company info,
# vehicle info, launch sites, and
# launch data.


require 'sinatra'
require 'sinatra/subdomain'
require 'json'
require 'date'
require 'mysql2'
require './data/company_info.rb'
require './data/falcon9.rb'
require './data/home_info.rb'
require './data/falcon_heavy.rb'
require './data/launchpads.rb'
require './data/dragon.rb'


# DB connection to MariaDB
DB = Mysql2::Client.new(
  :host => ENV["MARIA_HOST"],
  :username => ENV["MARIA_USER"],
  :password => ENV["<PASSWORD>"],
  :database => ENV["MARIA_DB"],
  :reconnect => true)


# Disables rack protection because of false positives
# that were blocking connections to home page
disable :protection


# No longer necessary
# Forces the use of HTTPS for the API
#before do
#  redirect request.url.sub('http', 'https') unless request.secure?
#end


# Method for merging hashes of static data
def hash_merge *hashes
  hashes.inject :merge
end


# Uses subdomain api.example.com to route traffic
subdomain :api do


get '/' do
  content_type :json
  JSON.pretty_generate($home_info)
end

get '/info' do
  content_type :json
  JSON.pretty_generate($company_info)
end

get '/vehicles' do
  content_type :json
  merge = hash_merge($falcon9, $falcon_heavy, $dragon)
  JSON.pretty_generate(merge)
end

get '/vehicles/falcon9' do
  content_type :json
  JSON.pretty_generate($falcon9)
end

get '/vehicles/falconheavy' do
  content_type :json
  JSON.pretty_generate($falcon_heavy)
end

get '/vehicles/dragon' do
  content_type :json
  JSON.pretty_generate($dragon)
end

get '/launchpads' do
  content_type :json
  JSON.pretty_generate($launchpads)
end

# Returns all launches
get '/launches' do
  content_type :json
  results = DB.query("SELECT * FROM launch", :cast_booleans => true)
    hash = results.each do |row|
    end
  JSON.pretty_generate(hash)
end

# Gets upcoming launches
get '/launches/upcoming' do
  content_type :json
  year = "upcoming"
  statement = DB.prepare("SELECT * FROM launch WHERE launch_year = ?")
  results = statement.execute(year)
    hash = results.each do |row|
    end
    if hash.empty?
      error = {error: 'No Matches Found'}
      JSON.pretty_generate(error)
    else<commit_msg>added hash compacting to remove nil values from results<commit_after># SpaceX API for searching company info,
# vehicle info, launch sites, and
# launch data.


require 'sinatra'
require 'sinatra/subdomain'
require 'json'
require 'date'
require 'mysql2'
require './data/company_info.rb'
require './data/falcon9.rb'
require './data/home_info.rb'
require './data/falcon_heavy.rb'
require './data/launchpads.rb'
require './data/dragon.rb'


# DB connection to MariaDB
DB = Mysql2::Client.new(
  :host => ENV["MARIA_HOST"],
  :username => ENV["MARIA_USER"],
  :password => ENV["<PASSWORD>"],
  :database => ENV["MARIA_DB"],
  :reconnect => true)


# Disables rack protection because of false positives
# that were blocking connections to home page
disable :protection


# No longer necessary
# Forces the use of HTTPS for the API
#before do
#  redirect request.url.sub('http', 'https') unless request.secure?
#end


# Method for merging hashes of static data
def hash_merge *hashes
  hashes.inject :merge
end


# Uses subdomain api.example.com to route traffic
subdomain :api do


get '/' do
  content_type :json
  JSON.pretty_generate($home_info)
end

get '/info' do
  content_type :json
  JSON.pretty_generate($company_info)
end

get '/vehicles' do
  content_type :json
  merge = hash_merge($falcon9, $falcon_heavy, $dragon)
  JSON.pretty_generate(merge)
end

get '/vehicles/falcon9' do
  content_type :json
  JSON.pretty_generate($falcon9)
end

get '/vehicles/falconheavy' do
  content_type :json
  JSON.pretty_generate($falcon_heavy)
end

get '/vehicles/dragon' do
  content_type :json
  JSON.pretty_generate($dragon)
end

get '/launchpads' do
  content_type :json
  JSON.pretty_generate($launchpads)
end

# Returns all launches
get '/launches' do
  content_type :json
  results = DB.query("SELECT * FROM launch", :cast_booleans => true)
    hash = results.each do |row|
    end
  JSON.pretty_generate(hash.compact)
end

# Gets upcoming launches
get '/launches/upcoming' do
  content_type :json
  year = "upcoming"
  statement = DB.prepare("SELECT * FROM launch WHERE launch_year = ?")
  results = statement.execute(year)
    hash = results.each do |row|
    end
    if hash.empty?
      error = {error: 'No Matches Found'}
      JSON.pretty_generate(error)
    else
{'fraction_non_alphanumeric': 0.11356537260151718, 'fraction_numerical': 0.002677376171352075, 'mean_word_length': 4.261737089201878, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '686950', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1481, 'n_words': 435}