Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@chapados
Forked from mattetti/gist:96954a4e59f1293977c0
Created January 5, 2010 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chapados/d5d8f8a5208fa4a4d94c to your computer and use it in GitHub Desktop.
Save chapados/d5d8f8a5208fa4a4d94c to your computer and use it in GitHub Desktop.
framework 'Cocoa'
url_string = 'http://macruby.icoretech.org/latest'
url = NSURL.URLWithString(url_string)
req = NSURLRequest.requestWithURL(url)
class Test
def downloadDidBegin(dl_process)
puts "downloading..."
end
def download(dl_process, decideDestinationWithSuggestedFilename:filename)
home = NSHomeDirectory()
path = home.stringByAppendingPathComponent('Desktop').stringByAppendingPathComponent(filename)
dl_process.setDestination(path, allowOverwrite:true)
end
def download(dl_process, didFailWithError:error)
error_description = error.localizedDescription
more_details = error.userInfo[NSErrorFailingURLStringKey]
puts "Download failed. #{error_description} - #{more_details}"
end
def downloadDidFinish(dl_process)
puts "Download finished!"
exit
end
end
file_download = NSURLDownload.alloc.initWithRequest(req, delegate: Test.new)
# keep the run loop running
NSRunLoop.currentRunLoop.runUntilDate(NSDate.distantFuture)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment