#!/usr/bin/env ruby # frozen_string_literal: true require 'bundler/setup' require 'outliner' require 'tempfile' def validate raise 'Missing arguments' if ARGV.size != 1 raise 'Invalid directory' unless Dir.exist?(ARGV[0]) raise 'OUTLINE_BASE_URI not set' unless ENV.key?('OUTLINE_BASE_URI') raise 'OUTLINE_TOKEN not set' unless ENV.key?('OUTLINE_TOKEN') end # Run validations validate # Setup variables local_directory = ARGV[0] CLIENT = Outliner::Client.new ENV['OUTLINE_BASE_URI'] # Download the complete zip response = CLIENT.collections_exportAll(download: true) # Extract it to a tempfle file = Tempfile.new('download.zip') File.open(file.path, 'w') { |f| f.write(response.body) } `unzip -o "#{file.path}" -d "#{local_directory}"` # Delete tempfile file.unlink