Skip to content

Instantly share code, notes, and snippets.

@ericdke
Created December 16, 2013 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericdke/7993978 to your computer and use it in GitHub Desktop.
Save ericdke/7993978 to your computer and use it in GitHub Desktop.
Download with HTTP + progress indicator
uri = URI.parse(THE_URL)
https = Net::HTTP.new(uri.host,uri.port)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
request["Authorization"] = "Bearer THE_AUTH_TOKEN"
request["Content-Type"] = "THE_TYPE"
body = ''
https.request(request) do |response|
fileSize = response['Content-Length'].to_i
bytesTransferred = 0
response.read_body do |part|
bytesTransferred += part.length
rounded = bytesTransferred.percent_of(fileSize).round
print "\rFetching data: #{rounded.to_s}%"
body << part
end
end
return body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment