twittermotion
twittermotion copied to clipboard
Handling Cursors
I started thinking about adding a few methods to the gem but got stuck when I came upon Cursors. The twitter gem handles this using send and recursion https://github.com/sferik/twitter/blob/master/lib/twitter/cursor.rb#L51
How would you begin implementing the fetching all pages (cursors) with RubyMotion? I'm not sure how one would work blocks into this pattern.
Ah yeah. Personally, I think ditching blocks and mimicking that library's API is a good idea, with documentation that says those methods will block the running thread:
Dispatch::Queue.concurrent.async {
followers = Twitter.followers("user")
Dispatch::Queue.main.sync { update_followers(followers) }
}
As for how to make Twitter.followers lock the thread, if you're sticking with TWRequest I think you could do:
tw_request = TWRequest.alloc.initWithURL(...)
ns_url_request = tw_request.signedURLRequest
ns_url_response_ptr = Pointer.new(:object)
error_ptr = Pointer.new(:object)
ns_data = NSURLConnection.sendSynchronousRequest(ns_url_request,
returningResponse:ns_url_response, error: error_ptr)
# parse the ns_data into a Hash etc
@clayallsopp sorry for the slow response was shipping some stuff :)
Thanks for the example of how you would do something like that, very useful to see that.
Would you consider replacing TWRequest with something? Maybe use AFMotion or AFNetworking directly?
Yup! As long as it had tests :)