lib/koala/graph_batch_api.rb in koala-1.2.0beta3 vs lib/koala/graph_batch_api.rb in koala-1.2.0beta4

- old
+ new

@@ -2,10 +2,17 @@ module Facebook module GraphBatchAPIMethods def self.included(base) base.class_eval do + attr_reader :original_api + + def initialize(access_token, api) + super(access_token) + @original_api = api + end + alias_method :graph_call_outside_batch, :graph_call alias_method :graph_call, :graph_call_in_batch alias_method :check_graph_api_response, :check_response alias_method :check_response, :check_graph_batch_api_response @@ -44,11 +51,11 @@ args["batch"] = MultiJson.encode(batch_calls.map { |batch_op| args.merge!(batch_op.files) if batch_op.files batch_op.to_batch_params(access_token) }) - graph_call_outside_batch('/', args, 'post', http_options) do |response| + batch_result = graph_call_outside_batch('/', args, 'post', http_options) do |response| # map the results with post-processing included index = 0 # keep compat with ruby 1.8 - no with_index for map response.map do |call_result| # Get the options hash batch_op = batch_calls[index] @@ -78,9 +85,12 @@ else nil end end end + + # turn any results that are pageable into GraphCollections + batch_result.inject([]) {|processed_results, raw| processed_results << GraphCollection.evaluate(raw, @original_api)} end end end end