mirror of https://github.com/captn3m0/outliner.git
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
This commit is contained in:
parent
831e173170
commit
787e838a59
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue