From 831e1731707d216d7e29fbf308f2f0e4165ce1d9 Mon Sep 17 00:00:00 2001 From: dhx Date: Thu, 22 Feb 2024 18:20:20 +0100 Subject: [PATCH] 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. --- exe/outliner-export | 21 +++++++++++++++++++-- exe/outliner-import | 6 +++--- lib/outliner/client.rb | 7 ++++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/exe/outliner-export b/exe/outliner-export index f12f103..20e261b 100755 --- a/exe/outliner-export +++ b/exe/outliner-export @@ -20,11 +20,28 @@ local_directory = ARGV[0] CLIENT = Outliner::Client.new ENV['OUTLINE_BASE_URI'] # 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 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}"` diff --git a/exe/outliner-import b/exe/outliner-import index b2941a7..85a1b87 100755 --- a/exe/outliner-import +++ b/exe/outliner-import @@ -28,7 +28,7 @@ def create_documents_recursively(directory, collection_id, parent_document_id = } params[:parentDocumentId] = parent_document_id if parent_document_id - CLIENT.documents_create(params) + CLIENT.documents__create(params) puts "[-] #{file}" end @@ -42,7 +42,7 @@ def create_documents_recursively(directory, collection_id, parent_document_id = publish: true, parentDocumentId: parent_document_id } - response = CLIENT.documents_create(params) + response = CLIENT.documents__create(params) create_documents_recursively(dir, collection_id, response['data']['id']) end Dir.chdir cwd @@ -65,7 +65,7 @@ begin rescue StandardError? => e # If we fail, print an error, and delete the collection 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' exit 1 end diff --git a/lib/outliner/client.rb b/lib/outliner/client.rb index ea55969..0882855 100644 --- a/lib/outliner/client.rb +++ b/lib/outliner/client.rb @@ -11,17 +11,18 @@ module Outliner end 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} if collections.size >= 1 collections[0]['id'] else - self.collections_create(name: name, description: 'Imported Collection')['data']['id'] + self.collections__create(name: name, description: 'Imported Collection')['data']['id'] end end 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 options = { body: body,