Sha256: a4eb155a295de4a7a40bc6776a586fee917deceba5f3a64d648126bfe42a3bb0
Contents?: true
Size: 1.03 KB
Versions: 27
Compression:
Stored size: 1.03 KB
Contents
module SlackRubyBotServer module Api module Presenters module PaginatedPresenter include Roar::JSON::HAL include Roar::Hypermedia include Grape::Roar::Representer property :total_count link :self do |opts| "#{request_url(opts)}#{query_string_for_cursor(nil, opts)}" end link :next do |opts| "#{request_url(opts)}#{query_string_for_cursor(represented.next, opts)}" if represented.next end private def request_url(opts) request = Grape::Request.new(opts[:env]) "#{request.base_url}#{opts[:env]['PATH_INFO']}" end # replace the page and offset parameters in the query string def query_string_for_cursor(cursor, opts) qs = Hashie::Mash.new(Rack::Utils.parse_nested_query(opts[:env]['QUERY_STRING'])) if cursor qs[:cursor] = cursor qs.delete(:offset) end "?#{qs.to_query}" unless qs.empty? end end end end end
Version data entries
27 entries across 27 versions & 1 rubygems