diff --git a/lib/koala/api/graph_collection.rb b/lib/koala/api/graph_collection.rb index 86ba0ab1..6dced349 100644 --- a/lib/koala/api/graph_collection.rb +++ b/lib/koala/api/graph_collection.rb @@ -41,18 +41,26 @@ def self.evaluate(response, api) # Retrieve the next page of results. # + # @param [Hash] extra_params Some optional extra parameters for paging. For supported parameters see https://developers.facebook.com/docs/reference/api/pagination/ + # + # @example With optional extra params + # wall = api.get_connections("me", "feed", since: 1379593891) + # wall.next_page(since: 1379593891) + # # @return a GraphCollection array of additional results (an empty array if there are no more results) - def next_page + def next_page extra_params = {} base, args = next_page_params - base ? @api.get_page([base, args]) : nil + base ? @api.get_page([base, args.merge(extra_params)]) : nil end # Retrieve the previous page of results. # + # @param [Hash] extra_params Some optional extra parameters for paging. For supported parameters see https://developers.facebook.com/docs/reference/api/pagination/ + # # @return a GraphCollection array of additional results (an empty array if there are no earlier results) - def previous_page + def previous_page extra_params = {} base, args = previous_page_params - base ? @api.get_page([base, args]) : nil + base ? @api.get_page([base, args.merge(extra_params)]) : nil end # Arguments that can be sent to {Koala::Facebook::API#graph_call} to retrieve the next page of results. diff --git a/spec/cases/graph_collection_spec.rb b/spec/cases/graph_collection_spec.rb index 88b10446..9d9c064e 100644 --- a/spec/cases/graph_collection_spec.rb +++ b/spec/cases/graph_collection_spec.rb @@ -1,10 +1,12 @@ require 'spec_helper' describe Koala::Facebook::GraphCollection do + let(:paging){ {:paging => true} } + before(:each) do @result = { "data" => [1, 2, :three], - "paging" => {:paging => true} + "paging" => paging } @api = Koala::Facebook::API.new("123") @collection = Koala::Facebook::GraphCollection.new(@result, @api) @@ -46,7 +48,7 @@ "paging" => {} } @base = double("base") - @args = double("args") + @args = {"a" => 1} @page_of_results = double("page of results") end @@ -141,4 +143,32 @@ Koala::Facebook::GraphCollection.evaluate(result, @api).should == expected end end + + describe "#next_page" do + let(:paging){ {"next" => "http://example.com/?a=2&b=3"} } + + it "should get next page" do + @api.should_receive(:get_page).with(["", {"a" => "2", "b" => "3"}]) + @collection.next_page + end + + it "should get next page with extra parameters" do + @api.should_receive(:get_page).with(["", {"a" => "2", "b" => "3", "c" => "4"}]) + @collection.next_page("c" => "4") + end + end + + describe "#previous_page" do + let(:paging){ {"previous" => "http://example.com/?a=2&b=3"} } + + it "should get previous page" do + @api.should_receive(:get_page).with(["", {"a" => "2", "b" => "3"}]) + @collection.previous_page + end + + it "should get previous page with extra parameters" do + @api.should_receive(:get_page).with(["", {"a" => "2", "b" => "3", "c" => "4"}]) + @collection.previous_page("c" => "4") + end + end end \ No newline at end of file