diff --git a/exe/outliner-import b/exe/outliner-import index 6f1c7c1..6a1222f 100755 --- a/exe/outliner-import +++ b/exe/outliner-import @@ -54,7 +54,7 @@ remote_collection_name = ARGV[1] # Create a root collection CLIENT = Outliner::Client.new ENV['OUTLINE_BASE_URI'] -root_collection_id = find_or_create_collection(CLIENT, remote_collection_name) +root_collection_id = CLIENT.find_or_create_collection(remote_collection_name) begin create_documents_recursively(local_directory, root_collection_id) diff --git a/lib/outliner/client.rb b/lib/outliner/client.rb index b6c2d2a..ea55969 100644 --- a/lib/outliner/client.rb +++ b/lib/outliner/client.rb @@ -10,10 +10,20 @@ module Outliner @token = ENV['OUTLINE_TOKEN'] end + def find_or_create_collection(name) + 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'] + end + end + def method_missing(method_name, params = {}) method_name = '/' + method_name.to_s.sub('_', '.') body = {token: @token}.merge(params).to_json - options = { + options = { body: body, headers: { 'Accept'=>'application/json', diff --git a/lib/outliner/version.rb b/lib/outliner/version.rb index db2a4ad..49715f1 100644 --- a/lib/outliner/version.rb +++ b/lib/outliner/version.rb @@ -1,3 +1,3 @@ module Outliner - VERSION = "0.2.0" + VERSION = "0.2.1" end