Module: AtomicLti::PagingHelper
- Defined in:
- app/lib/atomic_lti/paging_helper.rb
Constant Summary collapse
- MAX_PAGES =
200
Class Method Summary collapse
- .link_url(links, rel) ⇒ Object
- .paginate_request ⇒ Object
- .response_link_urls(response, *rels) ⇒ Object
Class Method Details
.link_url(links, rel) ⇒ Object
14 15 16 17 18 19 20 |
# File 'app/lib/atomic_lti/paging_helper.rb', line 14 def self.link_url(links, rel) matching_link = links.detect { |link| link.include?("rel=\"#{rel}\"") } return unless matching_link matching_link.split(";")[0].gsub(/[<>\s]/, "") end |
.paginate_request ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/lib/atomic_lti/paging_helper.rb', line 22 def self.paginate_request all = [] next_link = nil loop do result, next_link = yield(next_link) all << result break if next_link.blank? || result.blank? raise AtomicLti::Exceptions::PaginationLimitExceeded if all.count > MAX_PAGES end all.compact.flatten end |
.response_link_urls(response, *rels) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'app/lib/atomic_lti/paging_helper.rb', line 5 def self.response_link_urls(response, *rels) links = response.headers["link"]&.split(",") || [] urls = {} rels.each do |rel| urls[rel] = link_url(links, rel) end urls.values_at(*rels) end |