-
Notifications
You must be signed in to change notification settings - Fork 9
feat: Pagination support for list methods #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
drish
wants to merge
6
commits into
main
Choose a base branch
from
feat/optional-list-with-pagination
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+361
−11
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
70d0918
feat: impl pagination support for list methods
drish 6161e37
chore: rename file
drish ea5cb68
Merge branch 'main' of https://github.com/resendlabs/resend-ruby into…
drish 257332e
fix: rm not needed validation
drish 977bcbf
spec: fix
drish ea0f89c
Merge branch 'main' of https://github.com/resendlabs/resend-ruby into…
drish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../lib/resend" | ||
|
||
raise if ENV["RESEND_API_KEY"].nil? | ||
|
||
Resend.api_key = ENV["RESEND_API_KEY"] | ||
|
||
puts "=== Resend Ruby SDK Pagination Examples ===" | ||
puts | ||
|
||
# API Keys pagination | ||
puts "1. API Keys Pagination:" | ||
puts "List first 5 API keys:" | ||
api_keys = Resend::ApiKeys.list({ limit: 5 }) | ||
puts api_keys | ||
puts "Has more: #{api_keys[:has_more]}" if api_keys.key?(:has_more) | ||
puts | ||
|
||
# Audiences pagination | ||
puts "2. Audiences Pagination:" | ||
puts "List first 10 audiences:" | ||
audiences = Resend::Audiences.list({ limit: 10 }) | ||
puts audiences | ||
puts "Has more: #{audiences[:has_more]}" if audiences.key?(:has_more) | ||
puts | ||
|
||
# If we have audiences, demonstrate pagination with 'after' | ||
if audiences[:data] && !audiences[:data].empty? | ||
first_audience_id = audiences[:data].first[:id] | ||
puts "List audiences after '#{first_audience_id}':" | ||
next_audiences = Resend::Audiences.list({ limit: 5, after: first_audience_id }) | ||
puts next_audiences | ||
puts | ||
end | ||
|
||
# Domains pagination | ||
puts "3. Domains Pagination:" | ||
puts "List first 3 domains:" | ||
domains = Resend::Domains.list({ limit: 3 }) | ||
puts domains | ||
puts "Has more: #{domains[:has_more]}" if domains.key?(:has_more) | ||
puts | ||
|
||
# Broadcasts pagination | ||
puts "4. Broadcasts Pagination:" | ||
puts "List first 2 broadcasts:" | ||
broadcasts = Resend::Broadcasts.list({ limit: 2 }) | ||
puts broadcasts | ||
puts "Has more: #{broadcasts[:has_more]}" if broadcasts.key?(:has_more) | ||
puts | ||
|
||
# Contacts pagination (requires an audience ID) | ||
puts "5. Contacts Pagination:" | ||
if audiences[:data] && !audiences[:data].empty? | ||
audience_id = audiences[:data].first[:id] | ||
if audience_id && !audience_id.empty? | ||
puts "List first 5 contacts from audience '#{audience_id}':" | ||
begin | ||
contacts = Resend::Contacts.list(audience_id, { limit: 5 }) | ||
puts contacts | ||
puts "Has more: #{contacts[:has_more]}" if contacts.key?(:has_more) | ||
rescue Resend::Error => e | ||
puts "Error listing contacts: #{e.message}" | ||
puts "(This might happen if the audience has no contacts or access is restricted)" | ||
end | ||
else | ||
puts "Audience ID is empty, skipping contacts pagination example" | ||
end | ||
else | ||
puts "No audiences available for contacts pagination example" | ||
end | ||
puts | ||
|
||
puts "=== Pagination Parameters ===" | ||
puts "• limit: Number of items to retrieve (1-100)" | ||
puts "• after: ID after which to retrieve more items" | ||
puts "• before: ID before which to retrieve more items" | ||
puts | ||
puts "Example usage:" | ||
puts "Resend::ApiKeys.list({ limit: 25, after: 'key_123' })" | ||
puts "Resend::Domains.list({ limit: 10, before: 'domain_456' })" | ||
puts "Resend::Contacts.list('audience_id', { limit: 50 })" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Resend | ||
# Helper class for building paginated query strings | ||
class PaginationHelper | ||
class << self | ||
# Builds a paginated path with query parameters | ||
# | ||
# @param base_path [String] the base API path | ||
# @param query_params [Hash] optional pagination parameters | ||
# @option query_params [Integer] :limit Number of items to retrieve (max 100) | ||
# @option query_params [String] :after ID after which to retrieve more items | ||
# @option query_params [String] :before ID before which to retrieve more items | ||
# @return [String] the path with query parameters | ||
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("&") | ||
drish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return base_path if query_string.empty? | ||
|
||
"#{base_path}?#{query_string}" | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.