Class: EmailFuse::PaginationHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/email_fuse/pagination_helper.rb

Overview

Helper class for building paginated query strings

Class Method Summary collapse

Class Method Details

.build_paginated_path(base_path, query_params = nil) ⇒ String

Builds a paginated path with query parameters

Parameters:

  • base_path (String)

    the base API path

  • query_params (Hash) (defaults to: nil)

    optional pagination parameters

Options Hash (query_params):

  • :limit (Integer)

    Number of items to retrieve (max 100)

  • :after (String)

    ID after which to retrieve more items

  • :before (String)

    ID before which to retrieve more items

Returns:

  • (String)

    the path with query parameters



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/email_fuse/pagination_helper.rb', line 15

def build_paginated_path(base_path, query_params = nil)
  return base_path if query_params.nil? || query_params.empty?

  # Filter out nil values and convert to string keys
  filtered_params = query_params.compact.transform_keys(&:to_s)

  # Build query string
  query_string = filtered_params.map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join("&")

  return base_path if query_string.empty?

  "#{base_path}?#{query_string}"
end