nov / fb_graph

This gem doesn't support FB Graph API v2.0+. Please use fb_graph2 gem instead.
MIT License
1.04k stars 191 forks source link

Batch mode #243

Closed kellym closed 11 years ago

kellym commented 12 years ago

:warning: This code needs clean-up duty. It's the idea that counts.

This should help continue the development on batch requests. I did preliminary tests with og_action! and found it working decently well, and running a test on the friends method seemed to perform too.

The main problem is when an action needs to be run inside a batch request, before that request is performed (i.e. fetch.namespace). That action can't run since we're already set up to queue these actions.

This adds the ability to handle the response in a block after each individual action, but it also returns all the data at the end as well. For instance:

FbGraph.batch do
  facebook_user.og_action! 'my_app.host', :party => 'http://myhouse.com' do |response, success|
    Action.create(:cancellation_id => response.identifier) if success
  end
end

FbGraph.batch also returns all the responses in an array in case you need to perform another set of batch requests with them. For instance, I perform a batch of open graph actions, then use the returned ID of each to perform another batch job to get the details of those actions.

It would be nice if there were a way to perform non-batch requests inside the batch block, especially requests that are performed inside FbGraph's code (like retrieving the namespace for open graph tags). Might just be a matter of creating another flag like :batch => false.

buildhive commented 12 years ago

Nov Matake » fb_graph #9 FAILURE Looks like there's a problem with this pull request (what's this?)

buildhive commented 12 years ago

Nov Matake » fb_graph #10 SUCCESS This pull request looks good (what's this?)

buildhive commented 12 years ago

Nov Matake » fb_graph #11 SUCCESS This pull request looks good (what's this?)

buildhive commented 12 years ago

Nov Matake » fb_graph #12 SUCCESS This pull request looks good (what's this?)

nov commented 12 years ago

Hi,

First of all, thanks for your pull request! I've made a branch kellym-batch-mode, and merged your changes to that branch.

Could you tell me what's working and what's not? (working & not-working sample codes are very helpful)

res = FbGraph.batch(access_token: ACCESS_TOKEN) do
  me = FbGraph::User.me(ACCESS_TOKEN)
  me.fetch
  me.friends
  me.feed
end

I definitely move this forward!

buildhive commented 12 years ago

Nov Matake » fb_graph #14 FAILURE Looks like there's a problem with this pull request (what's this?)