Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
resend (1.22.0)
resend (1.23.0)
base64
httparty (>= 0.22.0)

Expand Down
17 changes: 12 additions & 5 deletions examples/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,18 @@
})
puts "sent event with email: #{sent_with_email[:event]}"

# 9. List events
# 9. Send event with an idempotency key
Comment thread
NicolasLopes7 marked this conversation as resolved.
Resolved
sent_idempotent = Resend::Events.send(
{ event: "user.signed_up", email: "test.events@example.com" },
options: { idempotency_key: "user.signed_up:test.events@example.com" }
)
puts "sent event with idempotency key: #{sent_idempotent[:event]}"

# 10. List events
events = Resend::Events.list
puts "total events: #{events[:data].length}, has_more: #{events[:has_more]}"

# 10. List events with pagination params
# 11. List events with pagination params
paginated = Resend::Events.list({ limit: 5 })
puts "paginated events (limit 5): #{paginated[:data].length}"

Expand All @@ -78,14 +85,14 @@
puts "next page: #{more_events[:data].length}"
end

# 11. Delete event by ID
# 12. Delete event by ID
deleted_by_id = Resend::Events.remove(event_id)
puts "deleted event by ID: #{deleted_by_id[:id]}, deleted: #{deleted_by_id[:deleted]}"

# 12. Delete event by name
# 13. Delete event by name
deleted_by_name = Resend::Events.remove("user.signed_up")
puts "deleted event by name: #{deleted_by_name[:deleted]}"

# 13. Cleanup: delete contact
# 14. Cleanup: delete contact
Resend::Contacts.remove({ id: contact_id })
puts "removed contact: #{contact_id}"
8 changes: 6 additions & 2 deletions lib/resend/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ def remove(identifier = "")
end

# https://resend.com/docs/api-reference/events/send-event
def send(params = {})
Resend::Request.new("events/send", params, "post").perform
#
# @param params [Hash] the event to send
# @param options [Hash] additional options for the request
# @option options [String] :idempotency_key Optional idempotency key
def send(params = {}, options: {})
Resend::Request.new("events/send", params, "post", options: options).perform
end

# https://resend.com/docs/api-reference/events/list-events
Expand Down
2 changes: 1 addition & 1 deletion lib/resend/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Resend
VERSION = "1.22.0"
VERSION = "1.23.0"
end
16 changes: 16 additions & 0 deletions spec/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,22 @@
end
Resend::Events.send(params)
end

it "sends the Idempotency-Key header" do
resp = { object: "event", event: event_name }
allow(resp).to receive(:body).and_return(resp)
allow(HTTParty).to receive(:send).and_return(resp)

Resend::Events.send({ event: event_name, email: "user@example.com" }, options: { idempotency_key: "evt-1" })

expect(HTTParty).to have_received(:send).with(
:post,
"#{Resend::Request::BASE_URL}events/send",
hash_including(
headers: hash_including("Idempotency-Key" => "evt-1")
)
)
end
end

describe "list" do
Expand Down