Skip to content

Commit

Permalink
added 2 more fields to help with pagination as well as normalized key…
Browse files Browse the repository at this point in the history
…s to be the same as the main mix (#4)
  • Loading branch information
jbhatab authored and doomspork committed Sep 20, 2016
1 parent a76ce3d commit 4997744
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/scrivener/headers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ defmodule Scrivener.Headers do
|> put_resp_header("link", build_link_header(uri, page))
|> put_resp_header("total", Integer.to_string(page.total_entries))
|> put_resp_header("per-page", Integer.to_string(page.page_size))
|> put_resp_header("total-pages", Integer.to_string(page.total_pages))
|> put_resp_header("page-number", Integer.to_string(page.page_number))
end

@spec build_link_header(URI.t, Scrivener.Page.t) :: String.t
Expand Down
2 changes: 2 additions & 0 deletions test/scrivener/headers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ defmodule Scrivener.HeadersTests do

assert headers["total"] == "50"
assert headers["per-page"] == "10"
assert headers["total-pages"] == "5"
assert headers["page-number"] == "3"
links = String.split(headers["link"], ", ")
assert ~s(<http://www.example.com/test?foo=bar&page=1>; rel="first") in links
assert ~s(<http://www.example.com/test?foo=bar&page=5>; rel="last") in links
Expand Down

0 comments on commit 4997744

Please sign in to comment.