diff --git a/exe/outliner-export b/exe/outliner-export index 20e261b..fa47e67 100755 --- a/exe/outliner-export +++ b/exe/outliner-export @@ -36,14 +36,14 @@ loop do break if fop_info_response['data']['state'] == 'complete' end -fop_redirect_response = CLIENT.fileOperations__redirect(id: file_operation_id) +begin + fop_redirect_response = CLIENT.fileOperations__redirect({id: file_operation_id}, {no_follow: true}) +rescue HTTParty::RedirectionTooDeep => e + response = HTTParty.get e.response.header['location'] + file = Tempfile.new('download.zip') + File.open(file.path, 'w') { |f| f.write(response.body) } + `unzip -o "#{file.path}" -d "#{local_directory}"` + file.unlink +end -# Extract it to a tempfle -file = Tempfile.new('download.zip') -File.open(file.path, 'w') { |f| f.write(fop_redirect_response) } - -`unzip -o "#{file.path}" -d "#{local_directory}"` - -# Delete tempfile -file.unlink diff --git a/lib/outliner/client.rb b/lib/outliner/client.rb index 0882855..76801d2 100644 --- a/lib/outliner/client.rb +++ b/lib/outliner/client.rb @@ -20,19 +20,19 @@ module Outliner end end - def method_missing(method_name, params = {}) - method_name = '/' + method_name.to_s.sub('__', '.') - puts method_name - body = {token: @token}.merge(params).to_json + def method_missing(method_name, params = {}, options = {}) + method_name = "/#{method_name.to_s.sub('__', '.')}" + options = { - body: body, + body: params.to_json, headers: { - 'Accept'=>'application/json', - 'Content-Type': 'application/json', - 'User-Agent': "Outliner/#{Outliner::VERSION}" + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + 'User-Agent' => "Outliner/#{Outliner::VERSION}", + 'Authorization' => "Bearer #{@token}" }, - format: :json - } + format: :json, + }.merge!(options) self.class.post(method_name, options) end