mirror of https://github.com/captn3m0/outliner.git
Fixes the exportAll -> export_all outline API change
As until now the client implementation replaced single underscores with a dot this was not compatible with underscores in the API URIs. For this reason now double underscores in the method name are replaced with a dot instead.
This commit is contained in:
parent
969f704f31
commit
831e173170
|
@ -20,11 +20,28 @@ local_directory = ARGV[0]
|
||||||
CLIENT = Outliner::Client.new ENV['OUTLINE_BASE_URI']
|
CLIENT = Outliner::Client.new ENV['OUTLINE_BASE_URI']
|
||||||
|
|
||||||
# Download the complete zip
|
# Download the complete zip
|
||||||
response = CLIENT.collections_exportAll(download: true)
|
response = CLIENT.collections__export_all(format: "outline-markdown")
|
||||||
|
|
||||||
|
raise 'Failed to trigger export_all action' if not response['success']
|
||||||
|
|
||||||
|
file_operation_id = response['data']['fileOperation']['id']
|
||||||
|
fop_info_response = nil
|
||||||
|
i = 0
|
||||||
|
loop do
|
||||||
|
i += 1
|
||||||
|
raise 'Timed out waiting for the file export operation to complete' if i > 20
|
||||||
|
sleep(2*i)
|
||||||
|
fop_info_response = CLIENT.fileOperations__info(id: file_operation_id)
|
||||||
|
raise 'Failed to query export file operation info' if not fop_info_response['ok']
|
||||||
|
break if fop_info_response['data']['state'] == 'complete'
|
||||||
|
end
|
||||||
|
|
||||||
|
fop_redirect_response = CLIENT.fileOperations__redirect(id: file_operation_id)
|
||||||
|
|
||||||
|
|
||||||
# Extract it to a tempfle
|
# Extract it to a tempfle
|
||||||
file = Tempfile.new('download.zip')
|
file = Tempfile.new('download.zip')
|
||||||
File.open(file.path, 'w') { |f| f.write(response.body) }
|
File.open(file.path, 'w') { |f| f.write(fop_redirect_response) }
|
||||||
|
|
||||||
`unzip -o "#{file.path}" -d "#{local_directory}"`
|
`unzip -o "#{file.path}" -d "#{local_directory}"`
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ def create_documents_recursively(directory, collection_id, parent_document_id =
|
||||||
}
|
}
|
||||||
|
|
||||||
params[:parentDocumentId] = parent_document_id if parent_document_id
|
params[:parentDocumentId] = parent_document_id if parent_document_id
|
||||||
CLIENT.documents_create(params)
|
CLIENT.documents__create(params)
|
||||||
puts "[-] #{file}"
|
puts "[-] #{file}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ def create_documents_recursively(directory, collection_id, parent_document_id =
|
||||||
publish: true,
|
publish: true,
|
||||||
parentDocumentId: parent_document_id
|
parentDocumentId: parent_document_id
|
||||||
}
|
}
|
||||||
response = CLIENT.documents_create(params)
|
response = CLIENT.documents__create(params)
|
||||||
create_documents_recursively(dir, collection_id, response['data']['id'])
|
create_documents_recursively(dir, collection_id, response['data']['id'])
|
||||||
end
|
end
|
||||||
Dir.chdir cwd
|
Dir.chdir cwd
|
||||||
|
@ -65,7 +65,7 @@ begin
|
||||||
rescue StandardError? => e
|
rescue StandardError? => e
|
||||||
# If we fail, print an error, and delete the collection
|
# If we fail, print an error, and delete the collection
|
||||||
puts "[E] Import failed with error: #{e.message}"
|
puts "[E] Import failed with error: #{e.message}"
|
||||||
CLIENT.collections_delete(id: root_collection_id)
|
CLIENT.collections__delete(id: root_collection_id)
|
||||||
puts '[E] Deleted collection, please report the issue or retry'
|
puts '[E] Deleted collection, please report the issue or retry'
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,17 +11,18 @@ module Outliner
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_or_create_collection(name)
|
def find_or_create_collection(name)
|
||||||
collections = self.collections_list(limit: 100)['data']
|
collections = self.collections__list(limit: 100)['data']
|
||||||
collections.filter!{|c|c['name'] == name}
|
collections.filter!{|c|c['name'] == name}
|
||||||
if collections.size >= 1
|
if collections.size >= 1
|
||||||
collections[0]['id']
|
collections[0]['id']
|
||||||
else
|
else
|
||||||
self.collections_create(name: name, description: 'Imported Collection')['data']['id']
|
self.collections__create(name: name, description: 'Imported Collection')['data']['id']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_missing(method_name, params = {})
|
def method_missing(method_name, params = {})
|
||||||
method_name = '/' + method_name.to_s.sub('_', '.')
|
method_name = '/' + method_name.to_s.sub('__', '.')
|
||||||
|
puts method_name
|
||||||
body = {token: @token}.merge(params).to_json
|
body = {token: @token}.merge(params).to_json
|
||||||
options = {
|
options = {
|
||||||
body: body,
|
body: body,
|
||||||
|
|
Loading…
Reference in New Issue