Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Include first and last page hrefs in paging meta data
  • Loading branch information
cover committed Aug 16, 2014
commit 744b4fc89cda5dd9ed00148014eecf87231c0c79
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ http://restpack-serializer-sample.herokuapp.com/api/v1/songs.json?page=2&page_si
"page_count": 14,
"previous_page": 1,
"next_page": 3,
"previous_href": "/api/v1/songs?page_size=3",
"next_href": "/api/v1/songs?page=3&page_size=3"
"first_href": "/songs?page_size=3",
"previous_href": "/songs?page_size=3",
"next_href": "/songs?page=3&page_size=3",
"last_href": "/songs?page=14&page_size=3"
}
},
"links": {
Expand Down Expand Up @@ -266,8 +268,10 @@ which yields:
"page_count": 1,
"previous_page": null,
"next_page": null,
"first_href": '/albums',
"previous_href": null,
"next_href": null
"next_href": null,
"last_href": '/albums'
}
},
"links": {
Expand Down
2 changes: 2 additions & 0 deletions lib/restpack_serializer/serializable/paging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ def serialize_meta(page, options)
next_page: page.next_page
}

meta[:first_href] = page_href(1, options)
meta[:previous_href] = page_href(meta[:previous_page], options)
meta[:next_href] = page_href(meta[:next_page], options)
meta[:last_href] = page_href(meta[:page_count], options)
meta
end

Expand Down
3 changes: 3 additions & 0 deletions spec/serializable/paging_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
it "includes valid paging meta data" do
page[:meta][:songs][:count].should == 18
page[:meta][:songs][:page_count].should == 2
page[:meta][:songs][:first_href].should == '/songs'
page[:meta][:songs][:previous_page].should == nil
page[:meta][:songs][:previous_href].should == nil
page[:meta][:songs][:next_page].should == 2
page[:meta][:songs][:next_href].should == '/songs?page=2'
page[:meta][:songs][:last_href].should == '/songs?page=2'
end
it "includes links" do
page[:links].should == {
Expand All @@ -44,6 +46,7 @@
it "includes the custom page size in the page hrefs" do
page[:meta][:songs][:next_page].should == 2
page[:meta][:songs][:next_href].should == '/songs?page=2&page_size=3'
page[:meta][:songs][:last_href].should == '/songs?page=6&page_size=3'
end
end

Expand Down