Class: Footrest::Pagination
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Footrest::Pagination
- Defined in:
- lib/footrest/pagination.rb
Overview
Faraday 2.x removed Faraday::Response::Middleware; the on_complete hook now lives on the unified Faraday::Middleware base (also present in 1.x).
Defined Under Namespace
Classes: Links
Instance Method Summary collapse
Instance Method Details
#find_link(header, rel) ⇒ Object
32 33 34 35 |
# File 'lib/footrest/pagination.rb', line 32 def find_link(header, rel) link = ::LinkHeader.parse(header).links.find{ |link| link['rel'] == rel } link.to_a.first if link end |
#on_complete(response) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/footrest/pagination.rb', line 18 def on_complete(response) if response[:response_headers] if link_header = response[:response_headers][:link] links = Links.new %w(prev next first last current).each do |page| link = find_link(link_header, page) response["#{page}_page".to_sym] = link links.public_send("#{ page }=", link) end response[:pagination_links] = links end end end |