🏡 index : github.com/captn3m0/outliner.git

author Nemo <commits@captnemo.in> 2024-03-07 12:01:25.0 +05:30:00
committer Nemo <me@captnemo.in> 2024-03-07 6:38:05.0 +00:00:00
commit
787e838a5977fc4f1f2de479e09a818224020bde [patch]
tree
32553f8223c0fad4ca6e66498ef08af533459c53
parent
831e1731707d216d7e29fbf308f2f0e4165ce1d9
download
787e838a5977fc4f1f2de479e09a818224020bde.tar.gz

Handle redirects properly.

Fixes redirect issues.

httparty sends request body at 302 redirects, so we
disable redirect follows for our fileoperations.redirect
call.

minor changes in client as well:

1. drops the token from the body, and sends it in header instead
   as per the new api
2. support additional options

Diff

 exe/outliner-export    | 18 +++++++++++++-----
 lib/outliner/client.rb | 20 +++++++++++++++-----
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/exe/outliner-export b/exe/outliner-export
index 20e261b..fa47e67 100755
--- a/exe/outliner-export
+++ a/exe/outliner-export
@@ -36,14 +36,14 @@
  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
+++ a/lib/outliner/client.rb
@@ -20,19 +20,19 @@
      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