mirror of https://github.com/captn3m0/outliner.git
34 lines
852 B
Ruby
Executable File
34 lines
852 B
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
require "bundler/setup"
|
|
require "outliner"
|
|
require 'tempfile'
|
|
|
|
def validate
|
|
unless (ARGV.size == 1) and Dir.exists?(ARGV[0]) and ENV.key?('OUTLINE_BASE_URI') and ENV.key?('OUTLINE_TOKEN')
|
|
puts "[E] Please call as `outliner-export directory`"
|
|
puts "[E] Please export OUTLINE_BASE_URI and OUTLINE_TOKEN environment variables"
|
|
puts "[E] OUTLINE_BASE_URI should not include /api"
|
|
exit 1
|
|
end
|
|
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') { |file| file.write(response.body) }
|
|
|
|
`unzip -o "#{file.path}" -d "#{local_directory}"`
|
|
|
|
# Delete tempfile
|
|
file.unlink
|