Skip to content

Commit 5468b88

Browse files
committed
Make pagination great again
1 parent a7cc0e2 commit 5468b88

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/cortex/result.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
require 'hashie'
22
module Cortex
33
class Result
4-
attr_reader :raw_headers, :contents, :total_items, :page, :per_page, :errors, :range_start, :range_end, :range, :status
4+
attr_reader :raw_headers, :contents, :total_items, :page, :per_page, :errors, :range_start, :range_end, :range, :status, :total_pages, :next_page, :prev_page
55

66
def initialize(body, headers, status)
77
@contents = parse(body)
88
@raw_headers = headers
99
@status = status
10-
@total_items = headers['x-total-items'] unless headers['x-total-items'].nil?
1110
parse_headers(headers)
1211
@errors = find_errors
1312
end
@@ -20,15 +19,16 @@ def is_error?
2019

2120
def parse_headers(headers)
2221
if headers['X-Total']
22+
@total_items = headers['X-Total']
2323
@count = headers['X-Total'].to_i
24-
end
25-
if headers['X-Total']
2624
@page = headers['X-Page'].to_i
2725
@per_page = headers['X-Per-Page'].to_i
2826
@range_start = (@page-1) * @per_page
2927
@range_end = @per_page * @page - 1
3028
@range = "#{@range_start}-#{@range_end}"
31-
29+
@total_pages = headers['X-Total-Pages']
30+
@next_page = headers['X-Next-Page']
31+
@prev_page = headers['X-Prev-Page']
3232
end
3333
end
3434

0 commit comments

Comments
 (0)