module Projectionist::Projects

Constants

DOWNLOAD_DIRECTORY
INDEX_ROOT
VERSION

Public Class Methods

download(project:, confirm: true, stdin: -> { gets } click to toggle source
# File lib/projectionist/projects.rb, line 23
def self.download(project:, confirm: true, stdin: -> { gets })
  normalized_project = "#{project}.projections.json"
  destination_file   = File.join(DOWNLOAD_DIRECTORY, normalized_project)

  if confirm && File.exist?(destination_file)
    print "Overwrite existing file? (y/N) "
    return unless stdin.call.strip.downcase == "y"
  end
  
  json_contents = Net::HTTP.get INDEX_ROOT, "/projectionist-projects-files/downloads/#{normalized_project}"
  File.open(destination_file, "w") do |file|
    file.write json_contents
  end
rescue SocketError
  throw :server_unavailable
end
fetch() click to toggle source
# File lib/projectionist/projects.rb, line 15
def self.fetch
  csv_contents = Net::HTTP.get INDEX_ROOT, "/projectionist-projects-files/downloads/index.csv"
  CSV.new(csv_contents, headers: true, header_converters: :symbol)
    .map(&:to_hash)
rescue SocketError
  throw :server_unavailable
end