Created
December 16, 2013 20:40
-
-
Save ericdke/7993978 to your computer and use it in GitHub Desktop.
Download with HTTP + progress indicator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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