views:

193

answers:

2

I'm still trying to get a handle on Cocoa (both in Obj-C and MacRuby), and I'd really appreciate seeing how to download a file with ASIHTTPRequest (or without it) and MacRuby. Ideally, I'd like to be able show the progress inside a progress bar too.

Must use a cocoa method for downloading, since open-uri in MacRuby is borken.

Thanks for your help.

+2  A: 

Here is an example app doing exactly that using HotCocoa: http://github.com/richkilmer/hotcocoa/tree/master/examples/download_and_progress_indicator

You would have to convert it to normal Cocoa but if you look at http://github.com/richkilmer/hotcocoa/blob/master/examples/download_and_progress_indicator/lib/application.rb you will see the main callbacks defined.

You might want to ask your questions in the MacRuby mailing so people involved with the project can help.

  • Matt

p.s: The cocoa IO methods are way more stable and efficient than Ruby's. Also keep in mind that you want to do async calls, something net/http won't help you with.

Matt Aimonetti
Thanks Matt. The links are helpful but the "delegate" pattern is very confusing to me: it doesn't seem to resemble callback functions or passing blocks (which I'm familiar with from js and ruby). I guess I have trouble visualizing the connections between the various methods passed with self as delegates — how does "connectionDidFinishLoading" get called for example?I didn't know MacRuby had an active mailing less, or one that would be tolerant of beginners. Now that I know this, I'll try posting my MacRuby-related questions there!
arbales
+1  A: 

Here are more explanations and an example from the book I'm writting: http://macruby.labs.oreilly.com/ch03.html#_urls_requests_connections Hopefully that will help.

Matt Aimonetti
@Matt, Niiiice book.
arbales